diff options
author | Adam Ierymenko <adam.ierymenko@gmail.com> | 2014-02-14 15:18:59 -0800 |
---|---|---|
committer | Adam Ierymenko <adam.ierymenko@gmail.com> | 2014-02-14 15:18:59 -0800 |
commit | 87b26b0aaf57823d5f217fc94dc0c9940ab45ce9 (patch) | |
tree | 2263bf74b4e0cdd00764c0ee79ecc39ced1480ab /ext | |
parent | 01d13c153d312827a14b1adce6e83c2ac8456797 (diff) | |
download | infinitytier-87b26b0aaf57823d5f217fc94dc0c9940ab45ce9.tar.gz infinitytier-87b26b0aaf57823d5f217fc94dc0c9940ab45ce9.zip |
Systemd support on Linux - GitHub issue #39
Diffstat (limited to 'ext')
-rw-r--r-- | ext/installfiles/linux/install.tmpl.sh | 33 | ||||
-rw-r--r-- | ext/installfiles/linux/systemd/zerotier-one.service | 11 | ||||
-rwxr-xr-x | ext/installfiles/linux/uninstall.sh | 46 |
3 files changed, 78 insertions, 12 deletions
diff --git a/ext/installfiles/linux/install.tmpl.sh b/ext/installfiles/linux/install.tmpl.sh index 834ad64b..8202cc93 100644 --- a/ext/installfiles/linux/install.tmpl.sh +++ b/ext/installfiles/linux/install.tmpl.sh @@ -12,6 +12,22 @@ if [ "$UID" -ne 0 ]; then dryRun=1 fi +# Detect systemd vs. regular init +SYSTEMDUNITDIR= +if [ -e /bin/systemctl -o -e /usr/bin/systemctl -o -e /usr/local/bin/systemctl -o -e /sbin/systemctl -o -e /usr/sbin/systemctl ]; then + if [ -e /usr/bin/pkg-config ]; then + SYSTEMDUNITDIR=`/usr/bin/pkg-config systemd --variable=systemdsystemunitdir` + fi + if [ -z "$SYSTEMDUNITDIR" -o ! -d "$SYSTEMDUNITDIR" ]; then + if [ -d /usr/lib/systemd/system ]; then + SYSTEMDUNITDIR=/usr/lib/systemd/system + fi + if [ -d /etc/systemd/system ]; then + SYSTEMDUNITDIR=/etc/systemd/system + fi + fi +fi + if [ $dryRun -gt 0 ]; then alias ln="echo '>> dry run: ln'" alias rm="echo '>> dry run: rm'" @@ -21,6 +37,7 @@ if [ $dryRun -gt 0 ]; then alias chkconfig="echo '>> dry run: chkconfig'" alias zerotier-cli="echo '>> dry run: zerotier-cli'" alias service="echo '>> dry run: service'" + alias systemctl="echo '>> dry run: systemctl'" fi scriptPath="`dirname "$0"`/`basename "$0"`" @@ -62,11 +79,17 @@ ln -sf /var/lib/zerotier-one/zerotier-one /usr/bin/zerotier-cli echo 'Installing and (re-)starting zerotier-one daemon...' -chkconfig zerotier-one on -service zerotier-one restart - -sleep 1 -zerotier-cli info +if [ -n "$SYSTEMDUNITDIR" -a -d "$SYSTEMDUNITDIR" ]; then + cp -f /tmp/systemd_zerotier-one.service "$SYSTEMDUNITDIR/zerotier-one.service" + systemctl enable zerotier-one + systemctl restart zerotier-one +else + cp -f /tmp/init.d_zerotier-one /etc/init.d/zerotier-one + chmod 0755 /etc/init.d/zerotier-one + chkconfig zerotier-one on + service zerotier-one restart +fi +rm -f /tmp/systemd_zerotier-one.service /tmp/init.d_zerotier-one exit 0 diff --git a/ext/installfiles/linux/systemd/zerotier-one.service b/ext/installfiles/linux/systemd/zerotier-one.service new file mode 100644 index 00000000..c4a1c4d2 --- /dev/null +++ b/ext/installfiles/linux/systemd/zerotier-one.service @@ -0,0 +1,11 @@ +[Unit] +Description=ZeroTier One +After=network.target + +[Service] +ExecStart=/var/lib/zerotier-one/zerotier-one +Restart=always +KillMode=process + +[Install] +WantedBy=multi-user.target diff --git a/ext/installfiles/linux/uninstall.sh b/ext/installfiles/linux/uninstall.sh index cdc447de..deddf252 100755 --- a/ext/installfiles/linux/uninstall.sh +++ b/ext/installfiles/linux/uninstall.sh @@ -7,6 +7,22 @@ if [ "$UID" -ne 0 ]; then exit 1 fi +# Detect systemd vs. regular init +SYSTEMDUNITDIR= +if [ -e /bin/systemctl -o -e /usr/bin/systemctl -o -e /usr/local/bin/systemctl -o -e /sbin/systemctl -o -e /usr/sbin/systemctl ]; then + if [ -e /usr/bin/pkg-config ]; then + SYSTEMDUNITDIR=`/usr/bin/pkg-config systemd --variable=systemdsystemunitdir` + fi + if [ -z "$SYSTEMDUNITDIR" -o ! -d "$SYSTEMDUNITDIR" ]; then + if [ -d /usr/lib/systemd/system ]; then + SYSTEMDUNITDIR=/usr/lib/systemd/system + fi + if [ -d /etc/systemd/system ]; then + SYSTEMDUNITDIR=/etc/systemd/system + fi + fi +fi + echo echo "This will uninstall ZeroTier One, hit CTRL+C to abort." @@ -14,20 +30,36 @@ echo "Waiting 5 seconds..." sleep 5 echo "Killing any running zerotier-one service..." +if [ -n "$SYSTEMDUNITDIR" -a -d "$SYSTEMDUNITDIR" ]; then + systemctl stop zerotier-one + systemctl disable zerotier-one +else + service stop zerotier-one +fi +sleep 1 killall -q -TERM zerotier-one -sleep 2 +sleep 1 killall -q -KILL zerotier-one -echo "Removing SysV init items..." -rm -fv /etc/init.d/zerotier-one -find /etc/rc*.d -name '???zerotier-one' -print0 | xargs -0 rm -fv +if [ -f /etc/init.d/zerotier-one ]; then + echo "Removing SysV init items..." + rm -f /etc/init.d/zerotier-one + find /etc/rc*.d -name '???zerotier-one' -print0 | xargs -0 rm -f +fi + +if [ -n "$SYSTEMDUNITDIR" -a -d "$SYSTEMDUNITDIR" -a -f "$SYSTEMDUNITDIR/zerotier-one.service" ]; then + echo "Removing systemd service..." + rm -f "$SYSTEMDUNITDIR/zerotier-one.service" +fi echo "Erasing binary and support files..." -cd /var/lib/zerotier-one -rm -rfv zerotier-one *.persist authtoken.secret identity.public *.log *.pid *.sh updates.d networks.d iddb.d +if [ -d /var/lib/zerotier-one ]; then + cd /var/lib/zerotier-one + rm -rf zerotier-one *.persist identity.public *.log *.pid *.sh updates.d networks.d iddb.d +fi echo "Erasing anything installed into system bin directories..." -rm -fv /usr/local/bin/zerotier-* /usr/bin/zerotier-* +rm -f /usr/local/bin/zerotier-cli /usr/bin/zerotier-cli echo "Done." echo |