Created
January 8, 2017 21:47
-
-
Save cpswan/a47bc7d790ca0e2df4f6f5aba1ef0807 to your computer and use it in GitHub Desktop.
autossh init script for keeping up a connection to a VPS
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
### BEGIN INIT INFO | |
# Provides: sshvps | |
# Required-Start: $local_fs $remote_fs | |
# Required-Stop: $local_fs $remote_fs | |
# Should-Start: $network | |
# Should-Stop: $network | |
# Default-Start: 2 3 4 5 | |
# Default-Stop: 0 1 6 | |
# Short-Description: Tunnel to VPS | |
# Description: This runs a script continuously in screen. | |
### END INIT INFO | |
case "$1" in | |
start) | |
echo "Starting sshvps" | |
su chris -c "screen -dmS sshvps /usr/lib/autossh/autossh -M 20001 -D 0.0.0.0:11111 [email protected]" | |
;; | |
stop) | |
echo "Stopping sshvps" | |
PID=`ps -ef | grep autossh | grep 20001 | grep -v grep | awk '{print $2}'` | |
kill -9 $PID | |
;; | |
restart|force-reload) | |
echo "Restarting sshvps" | |
PID=`ps -ef | grep autossh | grep 20001 | grep -v grep | awk '{print $2}'` | |
kill -9 $PID | |
sleep 15 | |
su chris -c "screen -dmS /usr/lib/autossh/autossh -M 20001 -D 0.0.0.0:11111 [email protected]" | |
;; | |
*) | |
N=/etc/init.d/$NAME | |
echo "Usage: $N {start|stop|restart}" >&2 | |
exit 1 | |
;; | |
esac | |
exit 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment