From 000387d10bd612334b265667fc4f2932923353a7 Mon Sep 17 00:00:00 2001 From: Kirill Zaitsev Date: Sun, 2 Nov 2014 16:35:22 +0300 Subject: [PATCH] Added support for sysV systems, like debian 7 --- packaging/root/usr/share/drone/init.d/drone | 75 +++++++++++++++++++++ packaging/scripts/postinst.deb | 22 +++++- packaging/scripts/postrm.deb | 7 +- packaging/scripts/prerm.deb | 10 ++- 4 files changed, 111 insertions(+), 3 deletions(-) create mode 100644 packaging/root/usr/share/drone/init.d/drone diff --git a/packaging/root/usr/share/drone/init.d/drone b/packaging/root/usr/share/drone/init.d/drone new file mode 100644 index 00000000..bd2e94c2 --- /dev/null +++ b/packaging/root/usr/share/drone/init.d/drone @@ -0,0 +1,75 @@ +#! /bin/sh + +### BEGIN INIT INFO +# Provides: drone +# Required-Start: $local_fs $remote_fs $network $syslog +# Required-Stop: $local_fs $remote_fs $network $syslog +# Default-Start: 2 3 4 5 +# Default-Stop: 0 1 6 +# Short-Description: Drone continuous integration server +### END INIT INFO + +DAEMON_OPTS="--config=/etc/drone/drone.toml" + +pid() { + if [ -f /usr/local/bin/droned ]; then + pidof /usr/local/bin/droned + fi +} + +stop() { + if pidof /usr/local/bin/droned >/dev/null; then + kill -9 "$(pid)" + else + echo "Drone not runned" + exit 1 + fi +} + +start() { + if pidof /usr/local/bin/droned >/dev/null; then + echo "Drone already runned" + exit 1 + else + nohup droned $DAEMON_OPTS > /var/log/drone.log 2>&1 & + fi +} + +restart() { + if pidof /usr/local/bin/droned >/dev/null; then + kill -9 "$(pid)" + nohup droned $DAEMON_OPTS > /var/log/drone.log 2>&1 & + exit 0 + else + nohup droned $DAEMON_OPTS > /var/log/drone.log 2>&1 & + exit 0 + fi +} + +status() { + if pidof /usr/local/bin/droned >/dev/null; then + echo "Drone with pid $(pid) is running" + else + echo "Drone is not running" + fi + exit 0 +} + +case "$1" in + start) + start + ;; + stop) + stop + ;; + restart) + restart + ;; + status) + status + ;; + *) + echo "Usage: service drone {start|stop|restart|status}" + exit 1 + ;; +esac \ No newline at end of file diff --git a/packaging/scripts/postinst.deb b/packaging/scripts/postinst.deb index 8d0031eb..e6c79c53 100644 --- a/packaging/scripts/postinst.deb +++ b/packaging/scripts/postinst.deb @@ -42,6 +42,26 @@ upstart() { fi } +sysv() { + if [ -d /etc/init.d ]; then + echo "Your system $(dist) $(version): using SysV to control Drone" + if [ -f /usr/local/bin/droned ] && [ -f /etc/init.d/drone ]; then + if pidof /usr/local/bin/droned >/dev/null; then + /etc/init.d/drone stop + fi + fi + + cp -r /usr/share/drone/init.d/drone /etc/init.d/drone + chmod 0755 /etc/init.d/drone + update-rc.d drone defaults + exec /etc/init.d/drone start || : + else + echo "Couldn't find SysV to control Drone, cannot proceed." + echo "Open an issue and tell us about your system." + exit 1 + fi +} + systemd() { if which systemctl > /dev/null; then cp /usr/share/drone/systemd/drone.service /lib/systemd/system/drone.service @@ -62,7 +82,7 @@ systemd() { case "$(dist)" in debian) if [ "$(version)" -lt "8" ]; then - upstart + sysv else systemd $1 fi diff --git a/packaging/scripts/postrm.deb b/packaging/scripts/postrm.deb index 9808fdce..f560a9e2 100644 --- a/packaging/scripts/postrm.deb +++ b/packaging/scripts/postrm.deb @@ -18,6 +18,11 @@ systemd() { rm -f /lib/systemd/system/drone.service } +sysv() { + update-rc.d -f drone remove + rm -f /etc/init.d/drone +} + validate_ver() { echo "$(version) < $1" | bc } @@ -25,7 +30,7 @@ validate_ver() { case "$(dist)" in debian) if [ "$(version)" -lt "8" ]; then - upstart + sysv else systemd fi diff --git a/packaging/scripts/prerm.deb b/packaging/scripts/prerm.deb index 78a5d99e..9a685d38 100644 --- a/packaging/scripts/prerm.deb +++ b/packaging/scripts/prerm.deb @@ -22,6 +22,14 @@ systemd() { fi } +sysv() { + if [ -f /etc/init.d/drone ] ; then + if pidof /usr/local/bin/droned >/dev/null; then + exec /etc/init.d/drone stop || : + fi + fi +} + validate_ver() { echo "$(version) < $1" | bc } @@ -29,7 +37,7 @@ validate_ver() { case "$(dist)" in debian) if [ "$(version)" -lt "8" ]; then - upstart + sysv else systemd $1 fi