Blob Blame History Raw
diff -up ./contrib/systemd/cjdns-online.sh.sbin ./contrib/systemd/cjdns-online.sh
--- ./contrib/systemd/cjdns-online.sh.sbin	2016-04-18 15:53:17.316245094 -0400
+++ ./contrib/systemd/cjdns-online.sh	2016-04-18 15:53:17.316245094 -0400
@@ -0,0 +1,75 @@
+#!/bin/sh
+#   Check whether cjdns IPs are available
+#   Copyright (C) 2016  Stuart D. Gathman <stuart@gathman.org>
+#
+#   This program is free software: you can redistribute it and/or modify
+#   it under the terms of the GNU General Public License as published by
+#   the Free Software Foundation, either version 3 of the License, or
+#   (at your option) any later version.
+#
+#   This program is distributed in the hope that it will be useful,
+#   but WITHOUT ANY WARRANTY; without even the implied warranty of
+#   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+#   GNU General Public License for more details.
+#
+#   You should have received a copy of the GNU General Public License
+#   along with this program.  If not, see <http://www.gnu.org/licenses/>.
+
+cjdns_ips() {
+  ip -6 -o addr | while read i dev fam ip rem; do
+    case "$ip" in
+    fc*:*/8) echo "${ip%/8}";;
+    esac
+  done
+}
+
+die() {
+  echo "$1" >&2
+  exit 1
+}
+
+PROGRAM_NAME="/usr/bin/cjdns-online"
+
+ARGS=$(getopt -n $PROGRAM_NAME -o t:xqsh \
+	--long timeout:,exit,quiet,wait-for-startup,help -- "$@")
+
+# Die if they fat finger arguments, this program may be run as root
+[ $? = 0 ] || die "Error parsing arguments. Try $PROGRAM_NAME --help"
+
+help() {
+        cat <<EOH
+Usage: $PROGRAM_NAME [options]
+        -t, --timeout <timeout_value>	time to wait in seconds, default 30
+        -x, --exit		exit immediately if cjdns is not online
+        -q, --quiet		don't print anything
+        -s, --wait-for-startup	wait for full startup instead of just tun dev
+EOH
+        exit 2
+}
+
+let timeout="30"
+let nowait="0"
+let quiet="0"
+let startup="0"
+
+eval set -- "$ARGS"
+while true; do
+  case "$1" in
+    -t|--timeout)	   let timeout="$2" || help; shift 2; continue;;
+    -x|--exit)		   let nowait="1"; shift;;
+    -q|--quiet)		   let quiet="1"; shift;;
+    -s|--wait-for-startup) let startup="1"; shift;;
+    --) shift; break;;
+    *)	help;;
+  esac
+done
+
+let started="$(date +%s)"
+while test -z "$(cjdns_ips)"; do
+  let elapsed="$(date +%s) - $started"
+  [ $elapsed -gt $timeout ] && exit 1
+  sleep 2
+done
+if [ "$quiet" -eq 0 ]; then
+  cjdns_ips
+fi
diff -up ./contrib/systemd/cjdns-resume.service.sbin ./contrib/systemd/cjdns-resume.service
--- ./contrib/systemd/cjdns-resume.service.sbin	2016-04-18 15:53:17.316245094 -0400
+++ ./contrib/systemd/cjdns-resume.service	2016-04-18 15:53:17.316245094 -0400
@@ -0,0 +1,10 @@
+[Unit]
+Description=Restart cjdns on resume from sleep
+After=sleep.target
+
+[Service]
+Type=oneshot
+ExecStart=/usr/bin/systemctl restart cjdns
+
+[Install]
+WantedBy=sleep.target
diff -up ./contrib/systemd/cjdns.service.sbin ./contrib/systemd/cjdns.service
--- ./contrib/systemd/cjdns.service.sbin	2016-01-27 03:07:49.000000000 -0500
+++ ./contrib/systemd/cjdns.service	2016-04-18 15:55:59.579483155 -0400
@@ -9,10 +9,10 @@ ProtectSystem=true
 SyslogIdentifier=cjdroute
 ExecStartPre=/bin/sh -ec "if ! test -s /etc/cjdroute.conf; \
                 then umask 077; \
-                /usr/bin/cjdroute --genconf > /etc/cjdroute.conf; \
+                /usr/sbin/cjdroute --genconf | cat > /etc/cjdroute.conf; \
                 echo 'WARNING: A new /etc/cjdroute.conf file has been generated.'; \
-            fi"
-ExecStart=/bin/sh -c "exec cjdroute --nobg < /etc/cjdroute.conf"
+            fi; test -c /dev/net/tun || /usr/sbin/modprobe tun"
+ExecStart=/bin/sh -c "exec /usr/sbin/cjdroute --nobg < /etc/cjdroute.conf"
 Restart=always
 
 [Install]
diff -up ./contrib/systemd/cjdns-wait-online.service.sbin ./contrib/systemd/cjdns-wait-online.service
--- ./contrib/systemd/cjdns-wait-online.service.sbin	2016-04-18 15:53:17.317245114 -0400
+++ ./contrib/systemd/cjdns-wait-online.service	2016-04-18 15:53:17.317245114 -0400
@@ -0,0 +1,13 @@
+[Unit]
+Description=CJDNS Wait Online
+Requisite=cjdns.service
+After=cjdns.service
+Wants=network.target
+Before=network-online.target
+
+[Service]
+Type=oneshot
+ExecStart=/usr/bin/cjdns-online -s -q --timeout=30
+
+[Install]
+WantedBy=multi-user.target
diff -up ./contrib/upstart/cjdns.conf.sbin ./contrib/upstart/cjdns.conf
--- ./contrib/upstart/cjdns.conf.sbin	2016-01-27 03:07:49.000000000 -0500
+++ ./contrib/upstart/cjdns.conf	2016-04-18 15:55:07.845450771 -0400
@@ -13,10 +13,13 @@ pre-start script
     if ! [ -s /etc/cjdroute.conf ]; then
         ( # start a subshell to avoid side effects of umask later on
             umask 077 # to create the file with 600 permissions without races
-            /usr/bin/cjdroute --genconf > /etc/cjdroute.conf
+	    # use cat because cjdroute can't write directly to /etc
+            /usr/sbin/cjdroute --genconf | cat > /etc/cjdroute.conf
         ) # exit subshell; umask no longer applies
         echo 'WARNING: A new cjdns cjdroute.conf file has been generated.'
     fi
+    # preload tun driver, since we prevent module_request
+    test -c /dev/net/tun || /sbin/modprobe tun
 
     # If you need a non-standard setup, as described in
     # https://github.com/cjdelisle/cjdns#non-standard-setups,
@@ -25,4 +28,4 @@ pre-start script
     # see http://upstart.ubuntu.com/cookbook/#setuid
 end script
 
-exec /usr/bin/cjdroute --nobg < /etc/cjdroute.conf
+exec /usr/sbin/cjdroute --nobg < /etc/cjdroute.conf