File: openser.init

package info (click to toggle)
openser 1.1.0-9etch1
  • links: PTS
  • area: main
  • in suites: etch, etch-m68k
  • size: 9,828 kB
  • ctags: 11,809
  • sloc: ansic: 120,528; sh: 5,249; yacc: 1,716; makefile: 1,261; php: 656; perl: 205; sql: 190
file content (140 lines) | stat: -rw-r--r-- 3,677 bytes parent folder | download
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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
#! /bin/sh
#
### BEGIN INIT INFO
# Provides:          openser
# Required-Start:    $syslog $network $local_fs $time
# Required-Stop:     $syslog $network $local_fs
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
# Short-Description: Start the OpenSER SIP proxy server
# Description:       Start the OpenSER SIP proxy server
### END INIT INFO
#
# TODO:
# The following fields should be added (and completed):
# Should-Start:      postgresql mysql radius
# Should-Stop:       postgresql mysql radius

PATH=/sbin:/bin:/usr/sbin:/usr/bin
DAEMON=/usr/sbin/openser
NAME=openser
DESC=openser
HOMEDIR=/var/run/openser
PIDFILE=$HOMEDIR/$NAME.pid
DEFAULTS=/etc/default/openser
RUN_OPENSER=no

# Do not start openser if fork=no is set in the config file
# otherwise the boot process will just stop
check_fork ()
{
    if grep -q "^[[:space:]]*fork[[:space:]]*=[[:space:]]*no.*" /etc/openser/openser.cfg; then
	echo "Not starting $DESC: fork=no specified in config file; run /etc/init.d/openser debug instead"
	exit 1
    fi
}

check_openser_config ()
{
	# Check if openser configuration is valid before starting the server
	set +e
	out=$($DAEMON -c > /dev/null 2>&1)
	retcode=$?
	set -e
	if [ "$retcode" != '0' ]; then
	    echo "Not starting $DESC: invalid configuration file!"
	    exit 1
	fi
}

create_radius_seqfile ()
{
    # Create a radius sequence file to be used by the radius client if
    # radius accounting is enabled. This is needed to avoid any issue
    # with the file not being writable if openser first starts as user
    # root because DUMP_CORE is enabled and creates this file as user
    # root and then later it switches back to user openser and cannot
    # write to the file. If the file exists before openser starts, it
    # won't change it's ownership and will be writable for both root
    # and openser, no matter what options are chosen at install time
    RADIUS_SEQ_FILE=/var/run/openser/openser_radius.seq
    if [ -d /var/run/openser ]; then
	chown ${USER}:${GROUP} /var/run/openser

	if [ ! -f $RADIUS_SEQ_FILE ]; then
	    touch $RADIUS_SEQ_FILE
	fi

	chown ${USER}:${GROUP} $RADIUS_SEQ_FILE
	chmod 660 $RADIUS_SEQ_FILE
    fi
}

test -f $DAEMON || exit 0

# Load startup options if available
if [ -f $DEFAULTS ]; then
   . $DEFAULTS || true
fi

if [ "$RUN_OPENSER" != "yes" ]; then
    echo "OpenSER not yet configured. Edit /etc/default/openser first."
    exit 0
fi

set -e

MEMORY=$((`echo $MEMORY | sed -e 's/[^0-9]//g'`))
[ -z "$USER" ]  && USER=openser
[ -z "$GROUP" ] && GROUP=openser
[ $MEMORY -le 0 ] && MEMORY=32

if test "$DUMP_CORE" = "yes" ; then
    # Ignore USER and GROUP in this case and use root,
    # else it won't write the core file.
    OPTIONS="-P $PIDFILE -m $MEMORY -u root -g root -w $HOMEDIR"
    ulimit -c unlimited
else
    OPTIONS="-P $PIDFILE -m $MEMORY -u $USER -g $GROUP"
fi

case "$1" in
  start|debug)
	check_openser_config
	create_radius_seqfile

	if [ "$1" != "debug" ]; then
	    check_fork
	fi

	echo -n "Starting $DESC: $NAME"
	start-stop-daemon --start --quiet --pidfile $PIDFILE \
		--exec $DAEMON -- $OPTIONS || echo -n " already running"
	echo "."
	;;
  stop)
	echo -n "Stopping $DESC: $NAME"
	start-stop-daemon --oknodo --stop --quiet --pidfile $PIDFILE \
		--exec $DAEMON
	echo "."
	;;
  restart|force-reload)
	check_openser_config
	create_radius_seqfile

	echo -n "Restarting $DESC: $NAME"
	start-stop-daemon --oknodo --stop --quiet --pidfile \
		$PIDFILE --exec $DAEMON
	sleep 1
	start-stop-daemon --start --quiet --pidfile \
		$PIDFILE --exec $DAEMON  -- $OPTIONS
	echo "."
	;;
  *)
	N=/etc/init.d/$NAME
	echo "Usage: $N {start|stop|restart|force-reload|debug}" >&2
	exit 1
	;;
esac

exit 0