FIX: properly shut down services on "docker stop"
authorSam <sam.saffron@gmail.com>
Thu, 9 Oct 2014 08:10:31 +0000 (19:10 +1100)
committerSam <sam.saffron@gmail.com>
Thu, 9 Oct 2014 08:10:31 +0000 (19:10 +1100)
This protects against corrupt dbs and speeds up boot / bootstrap

image/base/Dockerfile
image/base/boot [new file with mode: 0755]
image/base/runit-2
image/base/runit-3 [new file with mode: 0755]
image/discourse/Dockerfile
launcher
templates/postgres.template.yml
templates/redis.template.yml
templates/sshd.template.yml
templates/web.template.yml

index a67d99708202af1ac700a96a5eb90844005d2e55..b22528c649133b74613ef26df20363e1e87d518b 100644 (file)
@@ -2,7 +2,7 @@
 # When new LTS ships we can upgrade
 
 # NAME:     discourse_base
-# VERSION:  1.0.4
+# VERSION:  1.0.5
 
 FROM ubuntu:14.04
 
@@ -67,12 +67,17 @@ RUN echo 'gem: --no-document' >> /usr/local/etc/gemrc &&\
     cd / && git clone https://github.com/SamSaffron/pups.git
 
 # clean up for docker squash
-RUN rm -fr /usr/share/man && rm -fr /usr/share/doc
+RUN rm -fr /usr/share/man && rm -fr /usr/share/doc && mkdir -p /etc/runit/3.d
 
 ADD runit-1 /etc/runit/1
 ADD runit-1.d-cleanup-pids /etc/runit/1.d/cleanup-pids
 ADD runit-1.d-anacron /etc/runit/1.d/anacron
 ADD runit-2 /etc/runit/2
+ADD runit-3 /etc/runit/3
+ADD boot /sbin/boot
 
 ADD cron /etc/service/cron/run
 ADD rsyslog /etc/service/rsyslog/run
+
+# this is temporary, remove in 2015
+RUN cp /sbin/boot /sbin/runit
diff --git a/image/base/boot b/image/base/boot
new file mode 100755 (executable)
index 0000000..38b5294
--- /dev/null
@@ -0,0 +1,10 @@
+#!/bin/bash
+
+# we use this to boot up cause runit will not handle TERM and will not exit when done
+
+/etc/runit/1
+/etc/runit/2&
+RUNSVDIR=$!
+echo "Started runsvdir, PID is $RUNSVDIR"
+trap "echo Shutting Down && /etc/runit/3 && kill -HUP $RUNSVDIR && wait $RUNSVDIR" SIGTERM SIGHUP
+wait $RUNSVDIR
index b3ec10e5c79af1a36389b322499659bd3723cc6c..ba3cfb2d9e05c2fcf864404cc455916e6ed4ce0b 100755 (executable)
@@ -1,2 +1,2 @@
 #!/bin/bash
-/usr/bin/runsvdir -P /etc/service
+exec /usr/bin/runsvdir -P /etc/service
diff --git a/image/base/runit-3 b/image/base/runit-3
new file mode 100755 (executable)
index 0000000..40e510c
--- /dev/null
@@ -0,0 +1,3 @@
+#!/bin/bash
+
+/bin/run-parts --verbose /etc/runit/3.d
index bd15c9ec371b9d53f0d8d982d9830351363c1a32..b612e5fffad7fe9b9e1fdcd51dba7872b1179233 100644 (file)
@@ -1,5 +1,5 @@
-# Current version 1.0.4
-FROM samsaffron/discourse_base:1.0.4
+# Current version 1.0.5
+FROM samsaffron/discourse_base:1.0.5
 
 MAINTAINER Sam Saffron "https://twitter.com/samsaffron"
 
@@ -11,7 +11,7 @@ RUN useradd discourse -s /bin/bash -m -U &&\
       git remote set-branches --add origin tests-passed &&\
     chown -R discourse:discourse /var/www/discourse &&\
     cd /var/www/discourse &&\
-     sudo -u discourse RAILS4=1 bundle install --deployment \
+     sudo -u discourse bundle install --deployment \
          --without test --without development &&\
     find /var/www/discourse/vendor/bundle -name tmp -type d -exec rm -rf {} +
 
index 797c58c9329bd45fa41884aa3475db0d37caeb55..c39d8a97f6e5f2c3d22aae6ab3ca4b3d375d5aef 100755 (executable)
--- a/launcher
+++ b/launcher
@@ -13,7 +13,7 @@ config_file=containers/"$config".yml
 cidfile=cids/"$config".cid
 cidbootstrap=cids/"$config"_boostrap.cid
 local_discourse=local_discourse
-image=samsaffron/discourse:1.0.4
+image=samsaffron/discourse:1.0.5
 docker_path=`which docker.io || which docker`
 
 if [ "${SUPERVISED}" = "true" ]; then
@@ -340,7 +340,7 @@ run_start(){
        fi
 
        $docker_path run $links $attach_on_run $restart_policy "${env[@]}" -h "`hostname`-$config" -e DOCKER_HOST_IP=$docker_ip --name $config -t --cidfile $cidfile $ports \
-                  $volumes $local_discourse/$config /sbin/runit
+                  $volumes $local_discourse/$config /sbin/boot
 
        exit 0
      else
index 0b2a3238d9b1699f8972172444e4a1502e311237..cb835c65f492e6ac2735c0482fe29deaad801ef8 100644 (file)
@@ -27,6 +27,14 @@ run:
         #!/bin/sh
         exec 2>&1
         HOME=/var/lib/postgresql USER=postgres exec chpst -u postgres:postgres:ssl-cert -U postgres:postgres:ssl-cert /usr/lib/postgresql/9.3/bin/postmaster -D /etc/postgresql/9.3/main
+
+  - file:
+     path: /etc/runit/3.d/99-postgres
+     chmod: "+x"
+     contents: |
+       #!/bin/bash
+       sv stop postgres
+
   - file:
      path: /root/upgrade_postgres
      chmod: "+x"
index 1c61d0cd04e71bbd507b1194885b26a0a210947f..249018a45c8a8a117bdf17e81efe19b10d37dfe0 100644 (file)
@@ -7,6 +7,13 @@ run:
         exec 2>&1
         exec chpst -u redis -U redis /usr/bin/redis-server /etc/redis/redis.conf
 
+  - file:
+     path: /etc/runit/3.d/10-redis
+     chmod: "+x"
+     contents: |
+       #!/bin/bash
+       sv stop redis
+
   - replace:
       filename: "/etc/redis/redis.conf"
       from: "daemonize yes"
index 9f365c498ffc29ba2fc30bc24e28e9070e208451..5b7f4b1a7ff641ce03b0571ab107515acc6b3e98 100644 (file)
@@ -23,6 +23,13 @@ run:
         exec 2>&1
         exec /usr/sbin/sshd -D -e
 
+  - file:
+     path: /etc/runit/3.d/99-ssh
+     chmod: "+x"
+     contents: |
+       #!/bin/bash
+       sv stop sshd
+
   - exec:
       hook: sshd
       cmd:
index fb2518e74c664706a2cccba84a6f3bb68778dd01..532a1b1abce6f8c0bc5ac9ba22956d46ac7eef0c 100644 (file)
@@ -54,6 +54,20 @@ run:
         mkdir -p /var/log/nginx
         exec /usr/sbin/nginx
 
+  - file:
+     path: /etc/runit/3.d/01-nginx
+     chmod: "+x"
+     contents: |
+       #!/bin/bash
+       sv stop nginx
+
+  - file:
+     path: /etc/runit/3.d/02-unicorn
+     chmod: "+x"
+     contents: |
+       #!/bin/bash
+       sv stop unicorn
+
   - exec:
       cd: $home
       hook: code