Skip to content

Instantly share code, notes, and snippets.

@sctfic
Created June 24, 2014 12:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sctfic/0509a90f0de72c3c1b77 to your computer and use it in GitHub Desktop.
Save sctfic/0509a90f0de72c3c1b77 to your computer and use it in GitHub Desktop.
tunnel-ssh New
#! /bin/sh -e
DAEMON="/usr/bin/ssh" #ligne de commande du programme
DEAMON_OPT=$2 #argument à utiliser par le programme
DAEMONUSER="coaxis" #utilisateur du programme
DEAMON_NAME="tunnelSsh" #Nom du programme (doit être identique à l'exécutable)
PATH="/sbin:/bin:/usr/sbin:/usr/bin" #Ne pas toucher
test -x $DAEMON || exit 0
. /lib/lsb/init-functions
d_start () {
grep -q "Host $DEAMON_OPT" "/home/$DAEMONUSER/.ssh/config" || d_status
log_daemon_msg "Starting system $DEAMON_NAME Daemon"
start-stop-daemon --background --name $DEAMON_NAME --start --quiet --chuid $DAEMONUSER --exec $DAEMON -- $DEAMON_OPT
log_end_msg $?
}
d_stop () {
log_daemon_msg "Stopping system $DEAMON_NAME Daemon"
start-stop-daemon --name $DEAMON_NAME --stop --retry 5 --quiet --name $DEAMON_NAME
log_end_msg $?
}
d_status () {
status_of_proc "$DEAMON_NAME" "$DAEMON" "system-wide $DEAMON_NAME" && exit 0 || exit $?
}
case "$1" in
start|stop)
d_${1}
;;
restart|reload|force-reload)
d_stop
d_start
;;
force-stop)
d_stop
killall -q $DEAMON_NAME || true
sleep 2
killall -q -9 $DEAMON_NAME || true
;;
status)
d_status
;;
*)
echo "Usage: /etc/init.d/$DEAMON_NAME {start|stop|force-stop|restart|reload|force-reload|status}"
exit 1
;;
esac
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment