5
5
using System . Diagnostics ;
6
6
using Microsoft . Azure . WebJobs . Script . Eventing ;
7
7
using Microsoft . Extensions . Logging ;
8
+ using Mono . Unix ;
8
9
9
10
namespace Microsoft . Azure . WebJobs . Script . Workers . Http
10
11
{
@@ -17,6 +18,7 @@ internal class HttpWorkerProcess : WorkerProcess
17
18
private readonly string _scriptRootPath ;
18
19
private readonly string _workerId ;
19
20
private readonly WorkerProcessArguments _workerProcessArguments ;
21
+ private readonly IEnvironment _environment ;
20
22
21
23
internal HttpWorkerProcess ( string workerId ,
22
24
string rootScriptPath ,
@@ -25,7 +27,8 @@ internal HttpWorkerProcess(string workerId,
25
27
IWorkerProcessFactory processFactory ,
26
28
IProcessRegistry processRegistry ,
27
29
ILogger workerProcessLogger ,
28
- IWorkerConsoleLogSource consoleLogSource )
30
+ IWorkerConsoleLogSource consoleLogSource ,
31
+ IEnvironment environment )
29
32
: base ( eventManager , processRegistry , workerProcessLogger , consoleLogSource )
30
33
{
31
34
_processFactory = processFactory ;
@@ -35,6 +38,7 @@ internal HttpWorkerProcess(string workerId,
35
38
_scriptRootPath = rootScriptPath ;
36
39
_httpWorkerOptions = httpWorkerOptions ;
37
40
_workerProcessArguments = _httpWorkerOptions . Arguments ;
41
+ _environment = environment ;
38
42
}
39
43
40
44
internal override Process CreateWorkerProcess ( )
@@ -49,7 +53,31 @@ internal override Process CreateWorkerProcess()
49
53
} ;
50
54
workerContext . EnvironmentVariables . Add ( HttpWorkerConstants . PortEnvVarName , _httpWorkerOptions . Port . ToString ( ) ) ;
51
55
workerContext . EnvironmentVariables . Add ( HttpWorkerConstants . WorkerIdEnvVarName , _workerId ) ;
52
- return _processFactory . CreateWorkerProcess ( workerContext ) ;
56
+ Process workerProcess = _processFactory . CreateWorkerProcess ( workerContext ) ;
57
+ if ( _environment . IsLinuxConsumption ( ) )
58
+ {
59
+ AssignUserExecutePermissionsIfNotExists ( workerProcess . StartInfo . FileName ) ;
60
+ }
61
+ return workerProcess ;
62
+ }
63
+
64
+ private void AssignUserExecutePermissionsIfNotExists ( string filePath )
65
+ {
66
+ try
67
+ {
68
+ UnixFileInfo fileInfo = new UnixFileInfo ( filePath ) ;
69
+ if ( ! fileInfo . FileAccessPermissions . HasFlag ( FileAccessPermissions . UserExecute ) )
70
+ {
71
+ _workerProcessLogger . LogDebug ( "Assigning execute permissions to file: {filePath}" , filePath ) ;
72
+ fileInfo . FileAccessPermissions |= FileAccessPermissions . UserExecute |
73
+ FileAccessPermissions . GroupExecute |
74
+ FileAccessPermissions . OtherExecute ;
75
+ }
76
+ }
77
+ catch ( Exception ex )
78
+ {
79
+ _workerProcessLogger . LogWarning ( ex , "Error while assigning execute permission." ) ;
80
+ }
53
81
}
54
82
55
83
internal override void HandleWorkerProcessExitError ( WorkerProcessExitException httpWorkerProcessExitException )
0 commit comments