~upstart-devel/upstart/upstart-jobs

« back to all changes in this revision

Viewing changes to utopic/etc/init.d/coturn

  • Committer: Dimitri John Ledkov
  • Date: 2014-11-19 12:58:41 UTC
  • Revision ID: dimitri.j.ledkov@intel.com-20141119125841-98dr37roy8dvcv3b
auto update

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
#!/bin/sh
2
 
### BEGIN INIT INFO
3
 
# Provides:          coturn
4
 
# Required-Start:    $network $local_fs $remote_fs $syslog
5
 
# Required-Stop:     $remote_fs $syslog
6
 
# Default-Start:     2 3 4 5
7
 
# Default-Stop:      0 1 6
8
 
# Short-Description: coturn TURN Server
9
 
# Description:       STUN and TURN Relay Server for VoIP and WebRTC
10
 
### END INIT INFO
11
 
 
12
 
# Author: Oleg Moskalenko <mom040267@gmail.com>
13
 
 
14
 
# PATH should only include /usr/* if it runs after the mountnfs.sh script
15
 
PATH=/usr/bin:/sbin:/usr/sbin:/bin
16
 
DESC=coturn             # COTURN
17
 
NAME=coturn             # TURN Server
18
 
PROCNAME=turnserver                  # Binary name
19
 
DAEMON=/usr/bin/turnserver
20
 
DAEMON_ARGS="-c /etc/turnserver.conf -o -v"             # Arguments to run the daemon with
21
 
PIDFILE_DIR=/var/run
22
 
PIDFILE=/var/run/$PROCNAME.pid
23
 
SCRIPTNAME=/etc/init.d/$NAME
24
 
USER=turnserver
25
 
GROUP=turnserver
26
 
 
27
 
# Exit if the package is not installed
28
 
[ -x $DAEMON ] || exit 0
29
 
 
30
 
# Read configuration variable file if it is present
31
 
[ -r /etc/default/$NAME ] && . /etc/default/$NAME
32
 
 
33
 
if [ ! -d "$PIDFILE_DIR" ];then
34
 
        mkdir -p "$PIDFILE_DIR"
35
 
    chown $USER:$GROUP "$PIDFILE_DIR"
36
 
fi
37
 
 
38
 
# Define LSB log_* functions.
39
 
# Depend on lsb-base (>= 3.0-6) to ensure that this file is present.
40
 
. /lib/lsb/init-functions
41
 
 
42
 
#
43
 
# Function that starts the daemon/service
44
 
#
45
 
do_start()
46
 
{
47
 
        # Return
48
 
        #   0 if daemon has been started
49
 
        #   1 if daemon was already running
50
 
        #   2 if daemon could not be started
51
 
        start-stop-daemon --start --quiet --pidfile $PIDFILE --exec $DAEMON --test > /dev/null \
52
 
                || return 1
53
 
        start-stop-daemon --start --quiet --pidfile $PIDFILE --exec $DAEMON -- \
54
 
                $DAEMON_ARGS \
55
 
                || return 2
56
 
        # Add code here, if necessary, that waits for the process to be ready
57
 
        # to handle requests from services started subsequently which depend
58
 
        # on this one.  As a last resort, sleep for some time.
59
 
}
60
 
 
61
 
#
62
 
# Function that stops the daemon/service
63
 
#
64
 
do_stop()
65
 
{
66
 
        # Return
67
 
        #   0 if daemon has been stopped
68
 
        #   1 if daemon was already stopped
69
 
        #   2 if daemon could not be stopped
70
 
        #   other if a failure occurred
71
 
        start-stop-daemon --stop --quiet --retry=TERM/30/KILL/5 --pidfile $PIDFILE --name ${PROCNAME}
72
 
        RETVAL="$?"
73
 
        [ "$RETVAL" = 2 ] && return 2
74
 
        # Wait for children to finish too if this is a daemon that forks
75
 
        # and if the daemon is only ever run from this initscript.
76
 
        # If the above conditions are not satisfied then add some other code
77
 
        # that waits for the process to drop all resources that could be
78
 
        # needed by services started subsequently.  A last resort is to
79
 
        # sleep for some time.
80
 
        start-stop-daemon --stop --quiet --oknodo --retry=0/30/KILL/5 --exec $DAEMON
81
 
        [ "$?" = 2 ] && return 2
82
 
        # Many daemons don't delete their pidfiles when they exit.
83
 
        rm -f $PIDFILE
84
 
        return "$RETVAL"
85
 
}
86
 
 
87
 
#
88
 
# Function that sends a SIGHUP to the daemon/service
89
 
#
90
 
do_reload() {
91
 
        #
92
 
        # If the daemon can reload its configuration without
93
 
        # restarting (for example, when it is sent a SIGHUP),
94
 
        # then implement that here.
95
 
        #
96
 
        start-stop-daemon --stop --signal 1 --quiet --pidfile $PIDFILE --name $PROCNAME
97
 
        return 0
98
 
}
99
 
 
100
 
case "$1" in
101
 
    start)
102
 
        
103
 
        if test "$TURNSERVER_ENABLED" = 1; then
104
 
            log_daemon_msg "Starting $DESC " "$PROCNAME"
105
 
            do_start
106
 
            case "$?" in
107
 
                0|1) log_end_msg 0 ;;
108
 
                2) log_end_msg 1 ;;
109
 
            esac
110
 
        else
111
 
            log_daemon_msg "${NAME} disabled in /etc/default/${NAME}" "${PROCNAME}"
112
 
            log_end_msg 0
113
 
            log_daemon_msg "See /etc/default/${NAME} for instructions on enabling" "${PROCNAME}"
114
 
            log_end_msg 0
115
 
            exit 0
116
 
        fi
117
 
        ;;
118
 
    stop)
119
 
        log_daemon_msg "Stopping $DESC" "$PROCNAME"
120
 
        do_stop
121
 
        case "$?" in
122
 
            0|1) log_end_msg 0 ;;
123
 
            2) log_end_msg 1 ;;
124
 
        esac
125
 
        ;;
126
 
    status)
127
 
        status_of_proc "$DAEMON" "$PROCNAME" && exit 0 || exit $?
128
 
        ;;
129
 
    restart|force-reload)
130
 
        log_daemon_msg "Restarting $DESC" "$PROCNAME"
131
 
        do_stop
132
 
        case "$?" in
133
 
            0|1)
134
 
                do_start
135
 
                case "$?" in
136
 
                    0) log_end_msg 0 ;;
137
 
                    1) log_end_msg 1 ;; # Old process is still running
138
 
                    *) log_end_msg 1 ;; # Failed to start
139
 
                esac
140
 
                ;;
141
 
            *)
142
 
                # Failed to stop
143
 
                log_end_msg 1
144
 
                ;;
145
 
        esac
146
 
        ;;
147
 
    *)
148
 
        #echo "Usage: $SCRIPTNAME {start|stop|restart|reload|force-reload}" >&2
149
 
        echo "Usage: $SCRIPTNAME {start|stop|status|restart|force-reload}" >&2
150
 
        exit 3
151
 
        ;;
152
 
esac
153
 
 
154
 
exit 0