start-as-root option added in service spec files.

master
Luka Vandervelden 2020-01-04 16:26:05 +01:00
parent ddeb253c1e
commit 2e66b44e58
3 changed files with 6 additions and 2 deletions

View File

@ -3,7 +3,7 @@ consumes: http?
provides: www, http
ports: http=80, https=443
reload-command: kill -HUP ${SERVICE_PID}
user: root
start-as-root: true
%configuration nginx.conf

View File

@ -347,7 +347,9 @@ class Service
LibC.dup2 stdout_file.fd, 1
LibC.dup2 stderr_file.fd, 2
System.become_user user_name
unless @reference.start_as_root
System.become_user user_name
end
Process.exec command, args,
chdir: (@reference.directory.try { |x| evaluate x } || root),

View File

@ -82,6 +82,7 @@ class ServiceDefinition
getter directory : String?
getter user : String?
getter group : String?
getter start_as_root : Bool?
getter provides : String?
getter consumes : Array(Consumes)
getter environment_variables : Array(String)
@ -103,6 +104,7 @@ class ServiceDefinition
@directory = specs["directory"]?.try &.as_s
@user = specs["user"]?.try &.as_s
@group = specs["group"]?.try &.as_s
@start_as_root = specs["start-as-root"]?.try(&.as_s).try(&.==("true")) || false
@provides = specs["provides"]?.try &.as_a_or_s.map { |x| Provides.new x } || Array(Provides).new
@consumes = specs["consumes"]?.try &.as_a_or_s.map { |x| Consumes.new x } || Array(Consumes).new
@environment_variables = specs["environment-variables"]?.try &.as_a_or_s || Array(String).new