Skip to content

Commit 1f4fbd9

Browse files
committed
Add a NON_PRIVELEGED_USER environment variable to start services as the current user
1 parent 2618274 commit 1f4fbd9

6 files changed

Lines changed: 17 additions & 1 deletion

File tree

nginx/etc/confd/templates/nginx/nginx.conf.tmpl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1+
{{ if not (eq "true" (getenv "NON_PRIVILEGED_USER")) }}
12
user www-data;
3+
{{ end }}
24
worker_processes auto;
35
pid /run/nginx.pid;
46

php/nginx/etc/confd/templates/nginx/nginx.conf.tmpl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1+
{{ if not (eq "true" (getenv "NON_PRIVILEGED_USER")) }}
12
user www-data;
3+
{{ end }}
24
worker_processes auto;
35
pid /run/nginx.pid;
46

php/nginx/etc/confd/templates/php-fpm/pool.conf.tmpl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,10 @@ clear_env = no
77

88
listen = /run/php{{ getenv "PHP_VERSION" }}-fpm.sock
99

10+
{{ if not (eq "true" (getenv "NON_PRIVILEGED_USER")) }}
1011
listen.owner = www-data
1112
listen.group = www-data
13+
{{ end }}
1214

1315
pm = dynamic
1416

php/nginx/etc/confd/templates/supervisor/nginx.conf.tmpl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,9 @@ stdout_logfile_maxbytes=0
55
stderr_logfile=/dev/stderr
66
stderr_logfile_maxbytes=0
77
loglevel = warn
8+
{{ if not (eq "true" (getenv "NON_PRIVILEGED_USER")) }}
89
user = root
10+
{{ end }}
911
autostart = {{ getenv "START_NGINX" }}
1012
autorestart = true
1113
priority = 5

php/nginx/etc/confd/templates/supervisor/php-fpm.conf.tmpl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@ stdout_logfile=/dev/stdout
44
stdout_logfile_maxbytes=0
55
stderr_logfile=/dev/stderr
66
stderr_logfile_maxbytes=0
7+
{{ if not (eq "true" (getenv "NON_PRIVILEGED_USER")) }}
78
user = root
9+
{{ end }}
810
autostart = {{ getenv "START_PHP_FPM" }}
911
autorestart = true
1012
priority = 5

ubuntu/16.04/usr/local/share/bootstrap/common_functions.sh

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,15 @@ get_user_home_directory() {
3939
}
4040

4141
as_user() (
42-
set +x
4342
local COMMAND="$1"
4443
local WORKING_DIR="$2"
44+
45+
if [ "true" = "$NON_PRIVILEGED_USER" ];
46+
/bin/bash -c "cd '$WORKING_DIR'; $COMMAND"
47+
return "$?"
48+
fi
49+
50+
set +x
4551
local USER="$3"
4652
if [ -z "$COMMAND" ]; then
4753
return 1;

0 commit comments

Comments
 (0)