From 502cd6921f65f0f15dc5be80df1469c05b1412fe Mon Sep 17 00:00:00 2001 From: Adam Ierymenko Date: Wed, 27 May 2015 13:50:11 -0700 Subject: [PATCH 1/2] Fix for GitHub issue #133, and move restart out of installer to address restart problem. Installer probably should NOT mess with the running service, since Linux servers are likely to be production. --- ext/installfiles/linux/install.tmpl.sh | 71 ++++++++++++++------------ 1 file changed, 39 insertions(+), 32 deletions(-) diff --git a/ext/installfiles/linux/install.tmpl.sh b/ext/installfiles/linux/install.tmpl.sh index ff747daae..8773a21c7 100644 --- a/ext/installfiles/linux/install.tmpl.sh +++ b/ext/installfiles/linux/install.tmpl.sh @@ -12,22 +12,6 @@ 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 '>> ln'" alias rm="echo '>> rm'" @@ -51,6 +35,27 @@ if [ ! -r "$scriptPath" ]; then fi fi +# Check for systemd vs. old school SysV 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 + # Second check: test if systemd appears to actually be running. Apparently Ubuntu + # thought it was a good idea to ship with systemd installed but not used. Issue #133 + if [ -d /var/run/systemd/system -o -d /run/systemd/system ]; 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 +fi + +# Find the end of this script, which is where we have appended binary data. endMarkerIndex=`grep -a -b -E '^################' "$scriptPath" | head -c 16 | cut -d : -f 1` if [ "$endMarkerIndex" -le 100 ]; then echo 'Internal error: unable to find end of script / start of binary data marker.' @@ -86,7 +91,7 @@ echo -n 'Getting version of new install... ' newVersion=`/var/lib/zerotier-one/zerotier-one -v` echo $newVersion -echo 'Installing zerotier-cli command line utility...' +echo 'Creating symlinks...' rm -f /usr/bin/zerotier-cli /usr/bin/zerotier-idtool ln -sf /var/lib/zerotier-one/zerotier-one /usr/bin/zerotier-cli @@ -94,10 +99,9 @@ ln -sf /var/lib/zerotier-one/zerotier-one /usr/bin/zerotier-idtool echo 'Installing zerotier-one service...' -# Note: ensure that service restarts are the last thing this script actually -# does, since these may kill the script itself. Also note the & to allow -# them to finish independently. if [ -n "$SYSTEMDUNITDIR" -a -d "$SYSTEMDUNITDIR" ]; then + # SYSTEMD + # If this was updated or upgraded from an init.d based system, clean up the old # init.d stuff before installing directly via systemd. if [ -f /etc/init.d/zerotier-one ]; then @@ -114,11 +118,13 @@ if [ -n "$SYSTEMDUNITDIR" -a -d "$SYSTEMDUNITDIR" ]; then rm -f /tmp/systemd_zerotier-one.service /tmp/init.d_zerotier-one systemctl enable zerotier-one.service - if [ "$origVersion" != "$newVersion" ]; then - echo 'Version has changed, starting...' - systemctl restart zerotier-one.service - fi + #if [ "$origVersion" != "$newVersion" ]; then + # echo 'Version has changed, starting...' + # systemctl restart zerotier-one.service + #fi else + # SYSV INIT -- also covers upstart which supports SysVinit backward compatibility + cp -f /tmp/init.d_zerotier-one /etc/init.d/zerotier-one chmod 0755 /etc/init.d/zerotier-one rm -f /tmp/systemd_zerotier-one.service /tmp/init.d_zerotier-one @@ -126,6 +132,7 @@ else if [ -f /sbin/chkconfig -o -f /usr/sbin/chkconfig -o -f /usr/bin/chkconfig -o -f /bin/chkconfig ]; then chkconfig zerotier-one on else + # Yes Virginia, some systems lack chkconfig. if [ -d /etc/rc0.d ]; then rm -f /etc/rc0.d/???zerotier-one ln -sf /etc/init.d/zerotier-one /etc/rc0.d/K89zerotier-one @@ -156,14 +163,14 @@ else fi fi - if [ "$origVersion" != "$newVersion" ]; then - echo 'Version has changed, starting...' - if [ -f /sbin/service -o -f /usr/sbin/service ]; then - service zerotier-one restart - else - /etc/init.d/zerotier-one restart - fi - fi + #if [ "$origVersion" != "$newVersion" ]; then + # echo 'Version has changed, starting...' + # if [ -f /sbin/service -o -f /usr/sbin/service ]; then + # service zerotier-one restart + # else + # /etc/init.d/zerotier-one restart + # fi + #fi fi exit 0 From ea419c21d0c429cb43b157aa66b8a6845838bdc8 Mon Sep 17 00:00:00 2001 From: Adam Ierymenko Date: Thu, 28 May 2015 03:13:23 +0000 Subject: [PATCH 2/2] Fix installer path, add netconf option to make-linux. --- make-linux.mk | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/make-linux.mk b/make-linux.mk index fbd6d254f..5a76c546a 100644 --- a/make-linux.mk +++ b/make-linux.mk @@ -39,6 +39,13 @@ ifeq ($(ZT_AUTO_UPDATE),1) DEFS+=-DZT_AUTO_UPDATE endif +# Build with ZT_ENABLE_NETWORK_CONTROLLER=1 to build with the Sqlite network controller +ifeq ($(ZT_ENABLE_NETWORK_CONTROLLER),1) + DEFS+=-DZT_ENABLE_NETWORK_CONTROLLER + LIBS+=-L/usr/local/lib -lsqlite3 + OBJS+=controller/SqliteNetworkController.o +endif + # "make debug" is a shortcut for this ifeq ($(ZT_DEBUG),1) DEFS+=-DZT_TRACE @@ -74,7 +81,7 @@ selftest: $(OBJS) selftest.o $(STRIP) zerotier-selftest installer: one FORCE - ./buildinstaller.sh + ./ext/installfiles/linux/buildinstaller.sh clean: rm -rf *.o node/*.o controller/*.o osdep/*.o service/*.o ext/http-parser/*.o ext/lz4/*.o ext/json-parser/*.o zerotier-one zerotier-idtool zerotier-cli zerotier-selftest build-* ZeroTierOneInstaller-* *.deb *.rpm