Correction : vm_hosted : etc/init.d/tmpfs -> etc/sv/*/run .
authorJulien Moutinho <julm+burette@autogeree.net>
Thu, 11 Apr 2013 18:18:51 +0000 (20:18 +0200)
committerJulien Moutinho <julm+burette@autogeree.net>
Thu, 11 Apr 2013 20:27:55 +0000 (22:27 +0200)
12 files changed:
etc/init.d/tmpfs [deleted file]
etc/nsd3/nsd.conf
etc/sv/gitweb/run
etc/sv/lhc-remorque/run
etc/sv/mysql/run
etc/sv/nginx/run
etc/sv/nsd3/run
etc/sv/php5-fpm/run
etc/sv/postgres/run
etc/sv/postgrey/run
etc/sv/sshd/run
vm_hosted

diff --git a/etc/init.d/tmpfs b/etc/init.d/tmpfs
deleted file mode 100755 (executable)
index 8e46d00..0000000
+++ /dev/null
@@ -1,90 +0,0 @@
-#! /bin/sh
-### BEGIN INIT INFO
-# Provides:          tmpfs
-# Required-Start:    $local_fs
-# Required-Stop:     $local_fs
-# X-Start-Before:    nginx
-# Default-Start:     2 3 4 5
-# Default-Stop:      0 1 6
-# Short-Description: Initialise tmpfs file systems
-### END INIT INFO
-
-PATH=/sbin:/usr/sbin:/bin:/usr/bin
-
-. /lib/init/vars.sh
-. /lib/lsb/init-functions
-
-do_start() {
-       if [ -x /etc/rc.local ]
-        then
-               [ "$VERBOSE" != no ] && log_begin_msg "Initialising tmpfs file systems"
-               
-               ! mountpoint -q /run ||
-               sudo install -d -m 770 -o www-data -g www-data \
-                /run/nginx \
-                /run/nginx/fastcgi
-               
-               if mountpoint -q /run/shm &&
-                       test -f /run/shm/.tmpfs
-                then
-                       set -x
-                       sudo install -d -m 1777 -o root -g root \
-                        /run/shm/cache \
-                        /run/shm/tmp
-                       
-                       ! getent passwd www-data >/dev/null ||
-                       sudo install -d -m 770 -o www-data -g www-data \
-                        /run/shm/cache/nginx \
-                        /run/shm/cache/nginx/fastcgi \
-                        /run/shm/cache/nginx/client_body
-                       
-                       ! getent passwd php5 >/dev/null ||
-                       sudo install -d -m 1771 -o php5 -g php5 \
-                        /run/php5 \
-                        /run/php5/fpm \
-                        /run/shm/cache/php5 \
-                        /run/shm/cache/php5/fpm \
-                        /run/shm/tmp/php5
-                       
-                       ! getent passwd fcgi-gitweb >/dev/null ||
-                       sudo install -d -m 1771 -o fcgi-gitweb -g fcgi-gitweb \
-                        /run/shm/tmp/gitweb
-                       
-                       ! getent passwd mysql >/dev/null ||
-                       sudo install -d -m 1771 -o mysql -g mysql \
-                        /run/mysqld \
-                        /run/mysqld/sock
-                       
-                       ! getent passwd postgres >/dev/null ||
-                       sudo install -d -m 710 -o postgres -g postgres-data \
-                        /run/postgresql
-                       
-                       ! getent passwd postgrey >/dev/null ||
-                       sudo install -d -m 2710 -o postgrey -g postfix \
-                        /run/postgrey
-                       
-                       sudo install -d -m 1771 -o root -g root \
-                        /run/spawn-fcgi
-                fi
-               
-               ES=$?
-               [ "$VERBOSE" != no ] && log_end_msg $ES
-               return $ES
-        fi
- }
-
-case "$1" in
- (start|restart)
-       do_start
-       ;;
- (reload|force-reload)
-       echo "Error: argument '$1' not supported" >&2
-       exit 3
-       ;;
- (stop)
-       ;;
- (*)
-       echo "Usage: $0 start|restart|stop" >&2
-       exit 3
-       ;;
- esac
index 316af64..35e05b9 100644 (file)
@@ -10,7 +10,7 @@ ipv4-edns-size: 4096
 # ipv6-edns-size: 4096
 # logfile: "/var/log/nsd.log"
 # nsid: "aabbccdd"
-# pidfile: "/run/nsd3.pid"
+pidfile: "/dev/null"
 port: 53
 rrl-ratelimit: 200
 rrl-size: 10000
index 3f78af2..150854d 100755 (executable)
@@ -1,6 +1,10 @@
 #!/bin/sh -eux
 exec 2>&1
 sv=${PWD#/etc/sv/}
+install -d -m 1771 -o root -g root \
+ /run/spawn-fcgi
+install -d -m 1771 -o fcgi-gitweb -g fcgi-gitweb \
+ /run/shm/tmp/gitweb
 exec /usr/bin/spawn-fcgi \
  -u fcgi-"$sv" \
  -g fcgi-"$sv" \
index 23bfe9e..0f2c6bb 100755 (executable)
@@ -2,6 +2,8 @@
 exec 2>&1
 sv=${PWD#/etc/sv/}
 /usr/bin/sv -w 3 start sshd
+install -d -m 1771 -o root -g root \
+ /run/spawn-fcgi
 exec /usr/bin/spawn-fcgi \
  -u fcgi-"$sv" \
  -g fcgi-"$sv" \
index 6a4b625..84bf3b3 100755 (executable)
@@ -1,6 +1,9 @@
 #!/bin/sh -eux
 exec 2>&1
 sv=${PWD#/etc/sv/}
+install -d -m 1771 -o mysql -g mysql \
+ /run/mysqld \
+ /run/mysqld/sock
 eval "home=~$sv"
 exec /usr/bin/chpst \
  -u "$sv":"$sv" \
index 4cb7f40..aa49fd8 100755 (executable)
@@ -5,6 +5,12 @@ sv=${PWD#/etc/sv/}
  lhc-remorque \
  gitweb \
  php5-fpm
+install -d -m 770 -o www-data -g www-data \
+ /run/nginx \
+ /run/nginx/fastcgi \
+ /run/shm/cache/nginx \
+ /run/shm/cache/nginx/fastcgi \
+ /run/shm/cache/nginx/client_body
 exec /usr/sbin/nginx \
  -c /etc/nginx/nginx.conf \
  -g 'daemon off;'
index a59c393..9989289 100755 (executable)
@@ -1,6 +1,8 @@
 #!/bin/sh -eux
 exec 2>&1
 sv=${PWD#/etc/sv/}
+install -d -m 770 -o root -g root \
+ /run/nsd3
 exec /usr/sbin/nsd \
  -c /etc/nsd3/nsd.conf \
  -d
index c1c042f..4af1b26 100755 (executable)
@@ -1,6 +1,12 @@
 #!/bin/sh -eux
 exec 2>&1
 sv=${PWD#/etc/sv/}
+install -d -m 1771 -o php5 -g php5 \
+ /run/php5 \
+ /run/php5/fpm \
+ /run/shm/cache/php5 \
+ /run/shm/cache/php5/fpm \
+ /run/shm/tmp/php5
 exec /usr/sbin/php5-fpm \
  --fpm-config /etc/php5/fpm/php-fpm.conf \
  --php-ini    /etc/php5/fpm/php.ini
index d8eedca..addd8eb 100755 (executable)
@@ -1,6 +1,8 @@
 #!/bin/sh -eux
 exec 2>&1
 sv=${PWD#/etc/sv/}
+install -d -m 710 -o postgres -g postgres-data \
+ /run/postgresql
 eval "home=~$sv"
 exec /usr/bin/chpst \
  -u "$sv":"$sv":"$sv"-data \
index fba506a..38725ef 100755 (executable)
@@ -1,6 +1,8 @@
 #!/bin/sh -eux
 exec 2>&1
 sv=${PWD#/etc/sv/}
+install -d -m 2710 -o postgrey -g postfix \
+ /run/postgrey
 exec /usr/bin/chpst \
  -u "$sv":"$sv" \
  /usr/sbin/postgrey \
index 477eebe..6a287a0 100755 (executable)
@@ -1,4 +1,8 @@
 #!/bin/sh -eux
 exec 2>&1
 sv=${PWD#/etc/sv/}
+install -d -m 755 -o root -g root /run/sshd
+install -d -m 1777 -o root -g root \
+ /run/shm/cache \
+ /run/shm/tmp
 exec /usr/sbin/sshd -D
index ed42445..3259ef1 100755 (executable)
--- a/vm_hosted
+++ b/vm_hosted
@@ -299,7 +299,7 @@ rule_boot_configure () {
  }
 rule_dovecot_configure () {
        rule apt_get_install dovecot-imapd dovecot-managesieved dovecot-sieve
-       rule insserv_remove dovecot
+       rule insserv_remove  dovecot
        local hint="run vm_remote dovecot_key_send before"
        assert "sudo test -f /etc/dovecot/\"$vm_domainname\"/imap/x509/key.pem" hint
        sudo install -m 400 -o root -g root \
@@ -324,8 +324,7 @@ rule_dovecot_configure () {
                \$USER:\$(/usr/bin/doveadm pw -s SHA512-CRYPT):::::::
                _EOF
                EOF
-       rule runit_sv_configure dovecot
-       rule runit_sv_restart   dovecot
+       rule runit_configure dovecot
  }
 rule_etckeeper_configure () {
        sudo install -m 644 -o root -g root /dev/stdin /etc/etckeeper/etckeeper.conf <<-EOF
@@ -418,8 +417,9 @@ rule_initramfs_configure () {
  }
 rule_insserv_remove () { # SYNTAX: $sv
        local sv="$1"
-       sudo chmod u+x /etc/init.d/"$sv"
+       #sudo chmod u+x /etc/init.d/"$sv"
        sudo insserv --force --remove "$sv"
+       sudo test ! -x /etc/init.d/"$sv" ||
        sudo /etc/init.d/"$sv" stop
        sudo chmod ugo-x /etc/init.d/"$sv"
  }
@@ -528,7 +528,6 @@ rule_gitolite_configure () {
         do test ! -d /home/git/etc/gitolite/"$d" ||
                rmdir /home/git/etc/gitolite/"$d"
         done
-       rule tmpfs_configure
  }
 rule_locales_configure () {
        sudo debconf-set-selections <<-EOF
@@ -568,7 +567,7 @@ rule_mail_configure () {
  }
 rule_mysql_configure () {
        rule apt_get_install mysql-server-5.5
-       rule insserv_remove mysql
+       rule insserv_remove  mysql
        rule adduser mysql \
         --disabled-login \
         --disabled-password \
@@ -607,9 +606,7 @@ rule_mysql_configure () {
                 --datadir=/home/mysql/data \
                 --no-defaults
         fi
-       rule tmpfs_configure
-       rule runit_sv_configure mysql
-       rule runit_sv_restart   mysql
+       rule runit_configure mysql
        while ! sudo -u mysql mysql -u mysql </dev/null
        do sleep 0.3; done
        # NOTE:
@@ -741,9 +738,7 @@ rule_nginx_configure () {
                test ! -r "$tool"/etc/nginx/site.d/"$site"/configure.sh ||
                .         "$tool"/etc/nginx/site.d/"$site"/configure.sh
         done
-       rule tmpfs_configure
-       rule runit_sv_configure nginx
-       rule runit_sv_restart   nginx
+       rule runit_configure nginx
  }
 rule_nsd3_configure () { # NOTE: DNS autoritaire uniquement
        local -; set +f
@@ -787,15 +782,13 @@ rule_nsd3_configure () { # NOTE: DNS autoritaire uniquement
        sudo install -m 640 -o root -g nsd /dev/stdin \
         /etc/nsd3/nsd.conf
        sudo nsdc rebuild
-       rule runit_sv_configure nsd3
-       rule runit_sv_restart   nsd3
+       rule runit_configure nsd3
  }
 rule_ntp_configure () {
        # NOTE: http://my.opera.com/marcomarongiu/blog/2011/01/05/independent-wallclock-in-xen-4
-       rule apt_get_install    ntp
-       rule insserv_remove     ntp
-       rule runit_sv_configure ntp
-       rule runit_sv_restart   ntp
+       rule apt_get_install ntp
+       rule insserv_remove  ntp
+       rule runit_configure ntp
  }
 rule_openerp_configure () {
        sudo install -m 660 -o root -g root /dev/stdin /etc/apt/sources.list.d/openerp.list <<-EOF
@@ -909,9 +902,7 @@ rule_php5_fpm_configure () {
                 "$tool"/etc/php5/fpm/php.ini \
                        /etc/php5/fpm/php.ini
         done
-       rule tmpfs_configure
-       rule runit_sv_configure php5-fpm
-       rule runit_sv_restart   php5-fpm
+       rule runit_configure php5-fpm
  }
 rule_postfix_configure () {
        local hint="run vm_remote postfix_key_send before"
@@ -1002,13 +993,12 @@ rule_postfix_configure () {
         "$tool"/etc/postfix/$vm_domainname/virtual_alias \
                /etc/postfix/$vm_domainname/virtual_alias
        sudo postmap hash:/etc/postfix/$vm_domainname/virtual_alias
-       rule runit_sv_configure postfix
-       rule runit_sv_restart   postfix
+       rule runit_configure postfix
  }
 rule_postgresql_configure () {
  # DOC: http://wiki.postgresql.org/wiki/Shared_Database_Hosting
        rule apt_get_install postgresql-9.1
-       rule insserv_remove postgresql
+       rule insserv_remove  postgresql
        rule adduser postgres \
         --disabled-login \
         --disabled-password \
@@ -1041,7 +1031,6 @@ rule_postgresql_configure () {
         /home/postgresql/log \
         /home/postgresql/log/9.1 \
         /home/postgresql/log/9.1/main
-       rule tmpfs_configure
        if sudo test ! -d /home/postgresql/data
         then
                sudo install -d -m 750 -o postgres -g postgres \
@@ -1072,8 +1061,7 @@ rule_postgresql_configure () {
        sudo install -m 640 -o postgres -g postgres-data \
         "$tool"/etc/postgresql/9.1/main/postgresql.conf \
                /etc/postgresql/9.1/main/postgresql.conf
-       rule runit_sv_configure postgres
-       rule runit_sv_restart   postgres
+       rule runit_configure postgres
        while ! sudo -u postgres psql </dev/null
        do sleep 1; done
        # NOTE: supprime l'accès au schéma public depuis public,
@@ -1193,9 +1181,7 @@ rule_postgresql_db_user_add () { # SYNTAX: $db $user
 rule_postgrey_configure () {
        rule apt_get_install    postgrey
        rule insserv_remove     postgrey
-       rule tmpfs_configure
-       rule runit_sv_configure postgrey
-       rule runit_sv_restart   postgrey
+       rule runit_configure postgrey
  }
 rule_procmail_configure () {
        rule apt_get_install procmail
@@ -1208,39 +1194,31 @@ rule_procmail_configure () {
         "$tool"/etc/skel/etc/mail/delivery.procmailrc \
                /etc/skel/etc/mail/delivery.procmailrc
  }
-rule_runit_configure () { # SYNTAX: $service
+rule_runit_configure () { # SYNTAX: $sv
        rule apt_get_install runit
        local -; set +f
-       for sv in ${1-/etc/service/*}
-        # NOTE: stoppe les services en retenant leur status de départ
-        do sv=${sv##*/}
-               local sv_hash=$(printf %s "$sv" | sha1sum | cut -f 1 -d ' ')
-               local sv_status
-               IFS= read -r sv_status_$sv_hash <<-EOF
-                       $(sudo sv status "$sv" || true)
-                       EOF
-               sudo rm -f /etc/service/"$sv"
-        done
+       sudo find /etc/sv -mindepth 1 -maxdepth 1 -type d -name "${1:-*}" -exec \
+               /bin/sh -efux -c 'case $(sv stop "$1") in
+                (*": runsv not running") true;;
+                (*": unable to open supervise/ok: file does not exist") true;;
+                ("ok: down:"*) true;;
+                (*) false;;
+                esac' '' {} +
        set -$- ${1-"$tool"/etc/sv/*}
        while test -n "$*"
-        # NOTE: configure et (re-)démarre les services
         do local first=yes
                for sv in "$@"
                do sv=${sv##*/}
                        case $first in
                         (yes) shift $#; first=;;
                         esac
-                       local sv_hash=$(printf %s "$sv" | sha1sum | cut -f 1 -d ' ')
-                       rule runit_sv_configure "$sv"
-                       eval local sv_status=\"\${sv_status_$sv_hash-}\"
-                       case $sv_status in
-                        ("") true;;
-                        (run:*|fail:*) rule runit_sv_restart "$sv";;
-                        esac
+                       rule _runit_sv_configure "$sv"
+                       rule runit_sv_restart    "$sv"
                 done
         done
+       sudo find -L /etc/service -type l -delete
  }
-rule_runit_sv_configure () { # SYNTAX: $sv
+rule__runit_sv_configure () { # SYNTAX: $sv
        local sv="$1"
        sudo install -d -m 770 -o root -g root \
         /etc/sv/"$sv"
@@ -1267,7 +1245,6 @@ rule_runit_sv_configure () { # SYNTAX: $sv
  }
 rule_runit_sv_restart () { # SYNTAX: $sv
        local sv="$1"
-       rule runit_sv_configure "$sv"
        while true
         do case $(sudo sv restart "$sv") in
                 ("fail: $sv: runsv not running") sleep 1;;
@@ -1339,8 +1316,7 @@ rule_ssh_configure () {
        sudo install -m 644 -o root -g root \
         "$tool"/etc/ssh/ssh_config \
                /etc/ssh/ssh_config
-       rule runit_sv_configure sshd
-       rule runit_sv_restart   sshd
+       rule runit_configure sshd
  }
 rule_sysctl_configure () {
        local -; set +f
@@ -1367,11 +1343,6 @@ rule_tmpfs_configure () {
                TMP_SIZE=200m
                TMPFS_SIZE=20%VM
                EOF
-       sudo install -m 775 -o root -g root \
-        "$tool"/etc/init.d/tmpfs \
-               /etc/init.d/tmpfs
-       sudo update-rc.d tmpfs defaults
-       sudo service tmpfs restart
  }
 rule_time_configure () {
        sudo install -m 644 -o root -g root /dev/stdin /etc/timezone <<-EOF
@@ -1386,7 +1357,7 @@ rule_time_configure () {
  }
 rule_unbound_configure () {
        sudo apt-get install unbound
-       rule insserv_remove unbound
+       rule insserv_remove  unbound
        sudo install -m 644 -o root -g root /dev/stdin /etc/resolv.conf <<-EOF
                search ${vm_host#*.}
                nameserver 127.0.0.1
@@ -1400,8 +1371,7 @@ rule_unbound_configure () {
         <"$tool"/etc/unbound/unbound.conf |
        sudo install -m 440 -o unbound -g unbound /dev/stdin \
         /etc/unbound/unbound.conf
-       rule runit_sv_configure unbound
-       rule runit_sv_restart   unbound
+       rule runit_configure unbound
  }
 rule_user_add () { # SYNTAX: $user
        local user="$1"; shift