blob: 0794dc1d09fe5b810acb1c7b58773e299ac6e055 [file] [log] [blame]
Eric Butler6fcac632012-08-24 21:05:16 -07001#!/bin/sh
2### BEGIN INIT INFO
3# Provides: osmo-sgsn
4# Required-Start: $network $local_fs
5# Required-Stop:
6# Default-Start: 2 3 4 5
7# Default-Stop: 0 1 6
8# Short-Description: Osmocom Serving GPRS Support Node
9# Description: Osmocom Serving GPRS Support Node
10### END INIT INFO
11
12# Author: Harald Welte <laforge@gnumonks.org>
13
14# PATH should only include /usr/* if it runs after the mountnfs.sh script
15PATH=/sbin:/usr/sbin:/bin:/usr/bin
16NAME=osmo-sgsn # Introduce the short server's name here
17DESC="Osmocom Serving GPRS Support Node" # Introduce a short description here
18DAEMON=/usr/bin/osmo-sgsn # Introduce the server's location here
19SCRIPTNAME=/etc/init.d/osmocom-sgsn
20
21# Exit if the package is not installed
22[ -x $DAEMON ] || exit 0
23
24# Read configuration variable file if it is present
25[ -r /etc/default/osmocom-sgsn ] && . /etc/default/osmocom-sgsn
26
27# Load the VERBOSE setting and other rcS variables
28. /lib/init/vars.sh
29
30# Define LSB log_* functions.
31# Depend on lsb-base (>= 3.0-6) to ensure that this file is present.
32. /lib/lsb/init-functions
33
34DAEMON_ARGS="$DAEMON_ARGS -D -c $CONFIG_FILE"
35
36#
37# Function that starts the daemon/service
38#
39do_start()
40{
41 # Return
42 # 0 if daemon has been started
43 # 1 if daemon was already running
44 # 2 if daemon could not be started
45 start-stop-daemon --start --quiet --exec $DAEMON --test > /dev/null \
46 || return 1
47 start-stop-daemon --start --quiet --exec $DAEMON -- \
48 $DAEMON_ARGS \
49 || return 2
50 # Add code here, if necessary, that waits for the process to be ready
51 # to handle requests from services started subsequently which depend
52 # on this one. As a last resort, sleep for some time.
53}
54
55#
56# Function that stops the daemon/service
57#
58do_stop()
59{
60 # Return
61 # 0 if daemon has been stopped
62 # 1 if daemon was already stopped
63 # 2 if daemon could not be stopped
64 # other if a failure occurred
65 start-stop-daemon --stop --quiet --retry=TERM/30/KILL/5 --name $NAME
66 RETVAL="$?"
67 [ "$RETVAL" = 2 ] && return 2
68 # Wait for children to finish too if this is a daemon that forks
69 # and if the daemon is only ever run from this initscript.
70 # If the above conditions are not satisfied then add some other code
71 # that waits for the process to drop all resources that could be
72 # needed by services started subsequently. A last resort is to
73 # sleep for some time.
74 start-stop-daemon --stop --quiet --oknodo --retry=0/30/KILL/5 --exec $DAEMON
75 [ "$?" = 2 ] && return 2
76 return "$RETVAL"
77}
78
79#
80# Function that sends a SIGHUP to the daemon/service
81#
82do_reload() {
83 #
84 # If the daemon can reload its configuration without
85 # restarting (for example, when it is sent a SIGHUP),
86 # then implement that here.
87 #
88 start-stop-daemon --stop --signal 1 --quiet $PIDFILE --name $NAME
89 return 0
90}
91
92case "$1" in
93 start)
94 [ "$VERBOSE" != no ] && log_daemon_msg "Starting $DESC " "$NAME"
95 do_start
96 case "$?" in
97 0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;;
98 2) [ "$VERBOSE" != no ] && log_end_msg 1 ;;
99 esac
100 ;;
101 stop)
102 [ "$VERBOSE" != no ] && log_daemon_msg "Stopping $DESC" "$NAME"
103 do_stop
104 case "$?" in
105 0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;;
106 2) [ "$VERBOSE" != no ] && log_end_msg 1 ;;
107 esac
108 ;;
109 status)
110 status_of_proc "$DAEMON" "$NAME" && exit 0 || exit $?
111 ;;
112 #reload|force-reload)
113 #
114 # If do_reload() is not implemented then leave this commented out
115 # and leave 'force-reload' as an alias for 'restart'.
116 #
117 #log_daemon_msg "Reloading $DESC" "$NAME"
118 #do_reload
119 #log_end_msg $?
120 #;;
121 restart|force-reload)
122 #
123 # If the "reload" option is implemented then remove the
124 # 'force-reload' alias
125 #
126 log_daemon_msg "Restarting $DESC" "$NAME"
127 do_stop
128 case "$?" in
129 0|1)
130 do_start
131 case "$?" in
132 0) log_end_msg 0 ;;
133 1) log_end_msg 1 ;; # Old process is still running
134 *) log_end_msg 1 ;; # Failed to start
135 esac
136 ;;
137 *)
138 # Failed to stop
139 log_end_msg 1
140 ;;
141 esac
142 ;;
143 *)
144 #echo "Usage: $SCRIPTNAME {start|stop|restart|reload|force-reload}" >&2
145 echo "Usage: $SCRIPTNAME {start|stop|status|restart|force-reload}" >&2
146 exit 3
147 ;;
148esac
149
150: