Modification : vm_{host,hosted,remote} -> {host,local,remote}/ .
[lhc/ateliers.git] / etc / sv / nginx / local.sh
diff --git a/etc/sv/nginx/local.sh b/etc/sv/nginx/local.sh
new file mode 100644 (file)
index 0000000..dd3bd8e
--- /dev/null
@@ -0,0 +1,92 @@
+"$tool"/local/runit-sv-configure php5-fpm '*'
+"$tool"/local/runit-sv-restart   php5-fpm
+"$tool"/local/apt-get-install nginx spawn-fcgi fcgiwrap
+"$tool"/local/insserv-remove  nginx
+"$tool"/local/insserv-remove fcgiwrap
+
+"$tool"/local/www-init
+
+sudo install -d -m 770 -o www -g www \
+ /etc/nginx \
+ /etc/nginx/conf.d \
+ /etc/nginx/site.d \
+ /etc/nginx/x509.d
+sudo ln -fns \
+ /etc/nginx \
+ /home/www/etc/nginx
+sudo install -m 660 -o www -g www \
+ "$tool"/etc/nginx/nginx.conf \
+        /etc/nginx/nginx.conf
+
+for conf in $(find "$tool"/etc/nginx/conf.d \
+ -mindepth 1 -maxdepth 1 -type f \
+ -name '*.conf' \
+ -printf '%f\n')
+ do
+       sudo install -m 660 -o www -g www \
+        "$tool"/etc/nginx/conf.d/"$conf" \
+               /etc/nginx/conf.d/"$conf"
+ done
+
+for site in $(find "$tool"/etc/nginx/site.d \
+ -mindepth 1 -maxdepth 1 -type d \
+ -false ${@:+$(printf -- '-or -name %s\n' "$@")} \
+ -printf '%f\n')
+ do
+       "$tool"/local/adduser www-"$site" \
+        --disabled-login \
+        --disabled-password \
+        --group \
+        --home /home/www/pub/"$site" \
+        --shell /bin/false \
+        --system
+       "$tool"/local/adduser log-www-"$site" \
+        --disabled-login \
+        --disabled-password \
+        --group \
+        --home /home/www/log/"$site"/nginx \
+        --shell /bin/false \
+        --system
+       sudo install -d -m 771 -o log-www -g log-www \
+        /home/www/log/"$site"
+       sudo install -d -m 770 -o www -g www \
+        /etc/nginx/site.d/"$site"
+       sudo install -d -m 770 -o www -g www \
+        /etc/nginx/x509.d/"$site"
+       sudo test -L /home/www/pub/"$site" ||
+       sudo install -d -m 2770 -o www-"$site" -g www-"$site" \
+        /home/www/pub/"$site"
+       sudo adduser www-data www-"$site"
+       sudo adduser www-data log-www-"$site"
+       sudo install -m 660 -o www -g www \
+        "$tool"/etc/nginx/site.d/"$site"/local.conf \
+               /etc/nginx/site.d/"$site"/local.conf
+       test ! -e "$tool"/etc/nginx/site.d/"$site"/http.conf ||
+       sudo install -m 660 -o www -g www \
+        "$tool"/etc/nginx/site.d/"$site"/http.conf \
+               /etc/nginx/site.d/"$site"/http.conf
+       if test -L "$tool"/etc/nginx/site.d/"$site"/site.conf
+        then
+               sudo cp --force --preserve=links --no-dereference \
+                "$tool"/etc/nginx/site.d/"$site"/site.conf \
+                       /etc/nginx/site.d/"$site"/site.conf
+        else
+               sudo install -m 660 -o www -g www \
+                "$tool"/etc/nginx/site.d/"$site"/site.conf \
+                       /etc/nginx/site.d/"$site"/site.conf
+        fi
+       sudo install -m 660 -o www -g www /dev/stdin \
+        /etc/nginx/site.d/"$site"/server.conf <<-EOF
+               server {
+                       access_log /home/www/log/$site/nginx/access.log main;
+                       error_log  /home/www/log/$site/nginx/error.log warn;
+                       root       /home/www/pub/$site;
+                       include    /etc/nginx/site.d/$site/local.conf;
+                       include    /etc/nginx/site.d/$site/site.conf;
+                }
+               EOF
+       (
+       test ! -r "$tool"/etc/nginx/site.d/"$site"/configure.sh ||
+       .         "$tool"/etc/nginx/site.d/"$site"/configure.sh || return 1
+       )
+ done