6 PATH
=/usr
/local
/sbin
:/usr
/local
/bin
:/sbin
:/bin
:/usr
/sbin
:/usr
/bin
8 DAEMON
=/usr
/sbin
/chaosvpn
# Introduce the server's location here
9 TINCCTL
=/usr
/sbin
/tincctl
10 NAME
=chaosvpn
# Introduce the short server's name here
11 DESC
="Agora Link" # Introduce a short description here
13 PIDFILE
="overridden later"
15 test -x $DAEMON ||
exit 0
17 # Default options, these can be overriden by the information
18 # at /etc/conf.d/$NAME
19 DAEMON_OPTS
="-a" # Additional options given to the server
20 # -a == do not run as daemon, onetime fetch+update of config and tincd
23 DIETIME
=10 # Time to wait for the server to die, in seconds
24 # If this value is set too low you might not
25 # let some servers to die gracefully and
26 # 'restart' will not work
28 STARTTIME
=1 # Time to wait for the server to start, in seconds
29 # If this value is set each time the server is
30 # started (on start or restart) the script will
31 # stall to try to determine if it is running
32 # If it is not set and the server takes time
33 # to setup a pid file the log message might
34 # be a false positive (says it did not start
35 # when it actually did)
37 DAEMONUSER
="" # Users to run the daemons as. If this value
38 # is set start-stop-daemon will chuid the server
40 CONFIGS
="chaosvpn.conf" # which network config to startup
43 # Include defaults if available
44 if [ -f /etc
/conf.d
/$NAME ] ; then
48 # Use this if you want the user to explicitly set 'RUN' in
50 if [ "x$RUN" != "xyes" ] ; then
51 echo "$NAME disabled, please adjust the configuration to your needs "
52 echo "and then set RUN to 'yes' in /etc/conf.d/$NAME to enable it."
56 # Check that the user exists (if we set a user)
57 # Does the user exist?
58 if [ -n "$DAEMONUSER" ] ; then
59 if getent passwd |
grep -q "^$DAEMONUSER:"; then
60 # Obtain the uid and gid
61 DAEMONUID
=`getent passwd |grep "^$DAEMONUSER:" | awk -F : '{print $3}'`
62 DAEMONGID
=`getent passwd |grep "^$DAEMONUSER:" | awk -F : '{print $4}'`
64 echo "The user $DAEMONUSER, required to run $NAME does not exist."
71 # Check if a given process pid's cmdline matches a given name
74 [ -z "$pid" ] && return 1
75 [ ! -d /proc
/$pid ] && return 1
76 local cmd
=`cat /proc/$pid/cmdline | tr "\000" "\n"|head -n 1 |cut -d : -f 1`
77 # Is this the expected server
78 [ "$cmd" != "$name" ] && return 1
84 # Start the process using the wrapper
85 if [ -z "$DAEMONUSER" ] ; then
86 $DAEMON $DAEMON_OPTS >/dev
/null
89 # if we are using a daemonuser then change the user id
90 su
-s '/bin/sh' $DAEMONUSER -c "$DAEMON $DAEMON_OPTS"
96 extract_configinfos
() {
102 [ -f "/etc/tinc/$config" ] ||
return 1
104 # TODO: replace the following with something smaller like sed/busybox sed
105 networkname
=$
( perl
-ne 's/^.*?\$networkname\s*=\s*\"(.*?)\".*$/$1/ && print $_' <"/etc/tinc/$config" )
106 [ -z "$networkname" ] && return 1
108 PIDFILE
="/var/run/tinc.$networkname.pid"
109 DAEMON_OPTS
="-a -c /etc/tinc/$config"
117 for config
in $CONFIGS ; do
118 if [ "$mode" = "reload" ] ; then
119 stat_busy
"Reloading $DESC: $config"
121 stat_busy
"Starting $DESC: $config"
124 if extract_configinfos
"$config" ; then
125 start_server
&& stat_done || stat_fail
134 for config
in $CONFIGS ; do
135 stat_busy
"Stopping $DESC " "$config"
136 extract_configinfos
"$config"
137 if [ -x "$TINCCTL" ] ; then
138 # tincctl exists since tinc 1.1-git
139 "$TINCCTL" -n "$networkname" stop
2>/dev
/null
&& stat_done || stat_fail
141 if [ -f "$PIDFILE" ] ; then
142 kill `cat $PIDFILE` && stat_done || stat_fail
144 stat_append
"apparently not running"
166 restart|force-reload
)
167 stop_configs
&& start_configs
170 # echo "Checking status of $DESC" "$NAME"
172 # log_progress_msg "running"
175 # log_progress_msg "apparently not running"
181 #log_warning_msg "Reloading $NAME daemon: not implemented, as the daemon"
182 #log_warning_msg "cannot re-read the config file (use restart)."
183 # Reloading is the same as starting for us
184 start_configs
"reload"
188 echo "Usage: $N {start|stop|force-stop|restart|force-reload|status}" >&2