vpncloud/deb/vpncloud/vpncloud-control

75 lines
1.5 KiB
Bash
Executable File

#!/bin/bash
NAME=vpncloud
NETCONFIGS=/etc/vpncloud
# default settings
USER=root
GROUP=root
UMASK=022
NETWORKS=$(for net in $(ls $NETCONFIGS); do basename $net .net; done);
DAEMON=$(which $NAME)
# Exit if the package is not installed
[ -x $DAEMON ] || exit 0
# Read configuration variable file if it is present
[ -r /etc/default/$NAME ] && . /etc/default/$NAME
status() {
echo "Network status"
for net in $NETWORKS; do
[ -f "$NETCONFIGS/$net.net" ] || continue
echo -en "\t$net: "
if start-stop-daemon --status --pidfile /run/$NAME-$net.pid --name $NAME; then
echo "running"
else
echo "not running"
fi
done
}
start() {
# Return
# 0 if daemon has been started
# 1 if daemon was already running
# 2 if daemon could not be started
for net in $NETWORKS; do
[ -f "$NETCONFIGS/$net.net" ] || continue
start-stop-daemon --start --pidfile /run/$NAME-$net.pid --name $NAME -- "$DAEMON --daemon --config $NETCONFIGS/$net.net --pid-file /run/$NAME-$net.pid"
done
return 0
}
stop() {
# Return
# 0 if daemon has been stopped
# 1 if daemon was already stopped
# 2 if daemon could not be stopped
# other if a failure occurred
for net in $NETWORKS; do
[ -f "$NETCONFIGS/$net.net" ] || continue
start-stop-daemon --stop --quiet --pidfile /run/$NAME-$net.pid --retry 60
rm -f /run/$NAME-$net.pid
done
return 0
}
case "$1" in
start)
start
;;
stop)
stop
;;
status)
status
;;
*)
echo "Unsupported action: '$1'" >&2
exit 3
;;
esac