From The Compiler, 6 Years ago, written in Bash.
Embed
  1. #!/bin/bash
  2.  
  3. . /etc/rc.conf
  4. . /etc/rc.d/functions
  5. [[ -f /etc/conf.d/sshtunnel ]] && . /etc/conf.d/sshtunnel
  6.  
  7. user=florian
  8.  
  9. pid=$(cat /run/sshtunnel.pid 2>/dev/null)
  10. case "$1" in
  11.   start)
  12.     stat_busy "Starting sshtunnel"
  13.     if [ -z "$pid" ]; then
  14.             su - florian -c 'AUTOSSH_GATETIME=0 /usr/bin/autossh -M 20000 -q -n -N -D 9999 -R 1337:localhost:1337 -R 2222:localhost:222 -p 222 florian@the-compiler.org &>/dev/null' &>/dev/null &
  15.             echo "$!" > /run/sshtunnel.pid
  16.     fi
  17.     if [ $? -gt 0 ]; then
  18.       stat_fail
  19.     else
  20.       add_daemon sshtunnel
  21.       stat_done
  22.     fi
  23.     ;;
  24.   stop)
  25.     stat_busy "Stopping sshtunnel"
  26.     [ ! -z "$pid" ] && kill $pid &> /dev/null
  27.     if [ $? -gt 0 ]; then
  28.       stat_fail
  29.     else
  30.       rm /run/sshtunnel.pid
  31.       rm_daemon sshtunnel
  32.       stat_done
  33.     fi
  34.     ;;
  35.   restart)
  36.     $0 stop
  37.     sleep 1
  38.     $0 start
  39.     ;;
  40.   *)
  41.     echo "usage: $0 {start|stop|restart}"
  42. esac
  43. exit 0
  44.