4
# Required-Start: $network $local_fs $remote_fs $syslog
5
# Required-Stop: $remote_fs $syslog
6
# Default-Start: 2 3 4 5
8
# Short-Description: coturn TURN Server
9
# Description: STUN and TURN Relay Server for VoIP and WebRTC
12
# Author: Oleg Moskalenko <mom040267@gmail.com>
14
# PATH should only include /usr/* if it runs after the mountnfs.sh script
15
PATH=/usr/bin:/sbin:/usr/sbin:/bin
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
22
PIDFILE=/var/run/$PROCNAME.pid
23
SCRIPTNAME=/etc/init.d/$NAME
27
# Exit if the package is not installed
28
[ -x $DAEMON ] || exit 0
30
# Read configuration variable file if it is present
31
[ -r /etc/default/$NAME ] && . /etc/default/$NAME
33
if [ ! -d "$PIDFILE_DIR" ];then
34
mkdir -p "$PIDFILE_DIR"
35
chown $USER:$GROUP "$PIDFILE_DIR"
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
43
# Function that starts the daemon/service
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 \
53
start-stop-daemon --start --quiet --pidfile $PIDFILE --exec $DAEMON -- \
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.
62
# Function that stops the daemon/service
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}
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.
88
# Function that sends a SIGHUP to the daemon/service
92
# If the daemon can reload its configuration without
93
# restarting (for example, when it is sent a SIGHUP),
94
# then implement that here.
96
start-stop-daemon --stop --signal 1 --quiet --pidfile $PIDFILE --name $PROCNAME
103
if test "$TURNSERVER_ENABLED" = 1; then
104
log_daemon_msg "Starting $DESC " "$PROCNAME"
107
0|1) log_end_msg 0 ;;
111
log_daemon_msg "${NAME} disabled in /etc/default/${NAME}" "${PROCNAME}"
113
log_daemon_msg "See /etc/default/${NAME} for instructions on enabling" "${PROCNAME}"
119
log_daemon_msg "Stopping $DESC" "$PROCNAME"
122
0|1) log_end_msg 0 ;;
127
status_of_proc "$DAEMON" "$PROCNAME" && exit 0 || exit $?
129
restart|force-reload)
130
log_daemon_msg "Restarting $DESC" "$PROCNAME"
137
1) log_end_msg 1 ;; # Old process is still running
138
*) log_end_msg 1 ;; # Failed to start
148
#echo "Usage: $SCRIPTNAME {start|stop|restart|reload|force-reload}" >&2
149
echo "Usage: $SCRIPTNAME {start|stop|status|restart|force-reload}" >&2