]> git.parisson.com Git - mezzo.git/commitdiff
add sysv and systemd install scripts
authorGuillaume Pellerin <guillaume.pellerin@ircam.fr>
Wed, 20 Jan 2016 15:36:57 +0000 (16:36 +0100)
committerGuillaume Pellerin <guillaume.pellerin@ircam.fr>
Wed, 20 Jan 2016 15:36:57 +0000 (16:36 +0100)
init.sh.example [new file with mode: 0644]
install_systemd.py [new file with mode: 0755]
install_sysv.py [new file with mode: 0755]

diff --git a/init.sh.example b/init.sh.example
new file mode 100644 (file)
index 0000000..61fb249
--- /dev/null
@@ -0,0 +1,48 @@
+#!/bin/sh
+
+### BEGIN INIT INFO
+# Provides:        %s
+# Required-Start:      $docker
+# Required-Stop:       $docker
+# Default-Start:       2 3 4 5
+# Default-Stop:                0 1 6
+# Short-Description:   Docker Services
+### END INIT INFO
+
+set -e
+
+PROJECT_NAME=%s
+YAMLFILE=%s
+OPTS="-f $YAMLFILE -p $PROJECT_NAME"
+UPOPTS="-d --no-recreate --no-build --no-deps"
+
+. /lib/lsb/init-functions
+
+case "$1" in
+    start)
+        log_daemon_msg "Starting $PROJECT_NAME Compositon" "$PROJECT_NAME" || true
+        docker-compose $OPTS up $UPOPTS
+        ;;
+
+    stop)
+        log_daemon_msg "Stopping $PROJECT_NAME Composition" "$PROJECT_NAME" || true
+        docker-compose $OPTS stop
+        ;;
+
+    reload)
+        log_daemon_msg "Reloading $PROJECT_NAME Composition" "$PROJECT_NAME" || true
+        docker-compose $OPTS up $UPOPTS
+        ;;
+
+    restart)
+        docker-compose $OPTS stop
+        docker-compose $OPTS up $UPOPTS
+        ;;
+
+    *)
+        log_action_msg "Usage: /etc/init.d/$PROJECT_NAME {start|stop|restart|reload}" || true
+        exit 1
+        ;;
+esac
+
+exit 0
diff --git a/install_systemd.py b/install_systemd.py
new file mode 100755 (executable)
index 0000000..c16df44
--- /dev/null
@@ -0,0 +1,39 @@
+#!/usr/bin/python
+
+import os
+
+path = os.getcwd()
+name = path.split(os.sep)[-1]
+service = '/lib/systemd/system/' + name + '.service'
+
+print 'installing ' + name + '...'
+
+if not os.path.exists('/etc/init.d/docker'):
+    os.system('wget -qO- https://get.docker.com/ | sh')
+    os.system('pip install docker-compose')
+
+rules="""
+[Unit]
+Description=%s composition
+Requires=docker.service
+After=docker.service
+
+[Service]
+ExecStart=/usr/local/bin/docker-compose -f %s/docker-compose.yml up -d
+ExecStop=/usr/local/bin/docker-compose -f %s/docker-compose.yml stop
+
+[Install]
+WantedBy=local.target
+""" % (name, path, path)
+
+# print rules
+
+f = open(service, 'w')
+f.write(rules)
+f.close()
+
+os.system('systemctl enable ' + service)
+os.system('systemctl daemon-reload')
+os.system('systemctl start ' + name)
+
+print 'done'
diff --git a/install_sysv.py b/install_sysv.py
new file mode 100755 (executable)
index 0000000..14b3d5d
--- /dev/null
@@ -0,0 +1,27 @@
+#!/usr/bin/python
+
+import os
+
+path = os.getcwd()
+name = path.split(os.sep)[-1].lower()
+service = '/etc/init.d/' + name
+conf = path + os.sep + 'docker-compose.yml'
+
+print 'installing ' + name + '...'
+
+if not os.path.exists('/etc/init.d/docker'):
+    os.system('wget -qO- https://get.docker.com/ | sh')
+    os.system('pip install docker-compose')
+
+f = open('init.sh.example', 'r')
+rules = f.read() % (name, name, conf)
+f.close()
+
+f = open(service, 'w')
+f.write(rules)
+f.close()
+
+os.system('chmod 755 ' + service)
+os.system('update-rc.d ' + name + ' defaults 90 10')
+
+print 'done'