From: Guillaume Pellerin Date: Wed, 20 Jan 2016 15:36:57 +0000 (+0100) Subject: add sysv and systemd install scripts X-Git-Url: https://git.parisson.com/?a=commitdiff_plain;h=3a5506449a884a35e409e9dc75a174af2d7872f6;p=mezzo.git add sysv and systemd install scripts --- diff --git a/init.sh.example b/init.sh.example new file mode 100644 index 00000000..61fb2497 --- /dev/null +++ b/init.sh.example @@ -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 index 00000000..c16df44a --- /dev/null +++ b/install_systemd.py @@ -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 index 00000000..14b3d5d5 --- /dev/null +++ b/install_sysv.py @@ -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'