summaryrefslogtreecommitdiff
path: root/puppet/modules/obfsproxy/files/obfsproxy_init
blob: 01c8013af9dbfdf11f0facac2de71885a93e2e08 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
#!/bin/sh

### BEGIN INIT INFO
# Provides:          obfsproxy daemon
# Required-Start:    $remote_fs $syslog
# Required-Stop:     $remote_fs $syslog
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
# Short-Description: obfsproxy daemon
# Description:       obfsproxy daemon
### END INIT INFO

. /lib/lsb/init-functions

DAEMON=/usr/bin/obfsproxy
NAME=obfsproxy
DESC="obfsproxy daemon"
USER=obfsproxy
DATDIR=/etc/obfsproxy
PIDFILE=/var/run/obfsproxy.pid
CONF=$DATDIR/obfsproxy.conf
LOGFILE=/var/log/obfsproxy.log

# If the daemon is not there, then exit.
test -x $DAEMON || exit 0

if [ -f $CONF ] ; then
  . $CONF
else
  echo "Obfsproxy configuration file is missing, aborting..."
  exit 2
fi

DAEMONARGS=" --log-min-severity=$LOG --log-file=$LOGFILE --data-dir=$DATDIR \
            $TRANSPORT $PARAM --dest=$DEST_IP:$DEST_PORT server $BINDADDR:$PORT"

start_obfsproxy() {
  start-stop-daemon --start --quiet --oknodo -m --pidfile $PIDFILE \
		-b -c $USER --startas $DAEMON --$DAEMONARGS
}

stop_obfsproxy() {
  start-stop-daemon --stop --quiet --oknodo --pidfile $PIDFILE
}

status_obfsproxy() {
  status_of_proc -p $PIDFILE $DAEMON $NAME
}

case $1 in
 start)
  if [ -e $PIDFILE ]; then
   status_obfsproxy
   if [ $? = "0" ]; then
    exit
   fi
  fi
  log_begin_msg "Starting $DESC"
  start_obfsproxy
  log_end_msg $?
  ;;
 stop)
  if [ -e $PIDFILE ]; then
   status_obfsproxy
   if [ $? = "0" ]; then
     log_begin_msg "Stopping $DESC"
     stop_obfsproxy
     rm -f $PIDFILE
     log_end_msg $?
   fi
  else
     status_obfsproxy
  fi
  ;;
 restart)
  $0 stop && sleep 2 && $0 start
  ;;
 status)
  status_obfsproxy
  ;;
 reload)
  if [ -e $PIDFILE ]; then
   start-stop-daemon --stop --signal USR1 --quiet --pidfile $PIDFILE --name $NAME
   log_success_msg "$DESC reloaded successfully"
  else
   log_failure_msg "$PIDFILE does not exist"
  fi
  ;;
 *)
  echo "Usage: $0 {start|stop|restart|reload|status}"
  exit 2
  ;;
esac