updated on Fri Jan 20 20:16:25 UTC 2012
[aur-mirror.git] / autosshd / autosshd
blob89de3494169dab15abd8f1be9e0cea13e79d48a2
1 #!/bin/bash
3 . /etc/rc.conf
4 . /etc/rc.d/functions
5 . /etc/conf.d/autosshd
7 PIDDIR="/var/run/autosshd"
8 [ -d "$PIDDIR" ] || mkdir -p $PIDDIR
9 PIDFILE="$PIDDIR/autosshd.pid"
10 PID=$(cat "$PIDFILE" 2>/dev/null)
12 case "$1" in
13 start)
14 stat_busy "Starting autossh"
15 [ "$AUTOSSH_USER" == "" ] || chown -R $AUTOSSH_USER $PIDDIR
16 [ -z "$PID" ] && sudo -u $AUTOSSH_USER env AUTOSSH_PIDFILE="$PIDFILE" /usr/bin/autossh -M $AUTOSSH_PORT -f $SSH_OPTIONS
17 if [ $? -gt 0 ]; then
18 stat_die
19 else
20 add_daemon autosshd
21 stat_done
24 stop)
25 stat_busy "Stopping autossh"
26 if [ -n "$PID" ]; then
27 kill $PID &> /dev/null
28 if [ $? -gt 0 ]; then
29 stat_die
30 else
31 rm_daemon autosshd
32 stat_done
34 else
35 stat_die
38 restart)
39 $0 stop
40 sleep 1
41 $0 start
43 status)
44 if [ -z "$PID" ]; then
45 status_stopped
46 else
47 status_started
51 echo "usage: $0 {start|stop|status|restart}"
52 esac
53 exit 0