Skip to content

Commit fa688f3

Browse files
authored
Merge pull request #413 from continuouspipe/feature/allow-things-to-be-ran-as-non-privileged-user
Add a `NON_PRIVELEGED_USER` environment variable to start services as the current user
2 parents 828d585 + 68af84d commit fa688f3

File tree

6 files changed

+17
-0
lines changed

6 files changed

+17
-0
lines changed

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 & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,13 @@ as_user() (
4242
set +x
4343
local COMMAND="$1"
4444
local WORKING_DIR="$2"
45+
46+
if [ "true" = "$NON_PRIVILEGED_USER" ]; then
47+
set -x
48+
/bin/bash -c "cd '$WORKING_DIR'; $COMMAND"
49+
return "$?"
50+
fi
51+
4552
local USER="$3"
4653
if [ -z "$COMMAND" ]; then
4754
return 1;

0 commit comments

Comments
 (0)