blob: b9c5d33be1aa4fef37c529679ec2695fda334367 [file] [log] [blame]
Harald Welte1e9b27b2010-08-26 13:26:07 +02001#!/bin/sh
2### BEGIN INIT INFO
3# Provides: openggsn
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 GSM network-in-a-box
9# Description: A minimal implementation of the GSM Base Station Controller,
10# Mobile Switching Center, Home Location regster and all other
11# components to run a self-contained GSM network.
12### END INIT INFO
13
14# Author: Harald Welte <laforge@gnumonks.org>
15
16# PATH should only include /usr/* if it runs after the mountnfs.sh script
17PATH=/sbin:/usr/sbin:/bin:/usr/bin
18DESC="OpenGGSN Gateway GPRS Support Node"
19NAME=openggsn
20DAEMON=/usr/bin/ggsn
21DAEMON_ARGS="-D" # Arguments to run the daemon with
22PIDFILE=/var/run/$NAME.pid
23SCRIPTNAME=/etc/init.d/$NAME
24
25# Exit if the package is not installed
26[ -x $DAEMON ] || exit 0
27
28# Read configuration variable file if it is present
29[ -r /etc/default/$NAME ] && . /etc/default/$NAME
30
31# Load the VERBOSE setting and other rcS variables
32. /lib/init/vars.sh
33
34# Define LSB log_* functions.
35# Depend on lsb-base (>= 3.0-6) to ensure that this file is present.
36. /lib/lsb/init-functions
37
38DAEMON_ARGS="$DAEMON_ARGS -c $CONFIG_FILE"
39
40#
41# Function that starts the daemon/service
42#
43do_start()
44{
45 # Return
46 # 0 if daemon has been started
47 # 1 if daemon was already running
48 # 2 if daemon could not be started
49 start-stop-daemon --start --quiet --pidfile $PIDFILE --exec $DAEMON --test > /dev/null \
50 || return 1
51
52 # Check for runtime directory of nonvolatile data
53 if [ ! -d /var/lib/ggsn ]; then
54 mkdir /var/lib/ggsn
55 fi
56
57 # Check for GTP restart counter
58 if [ ! -f /var/lib/ggsn/gsn_restart ]; then
59 echo 0 > /var/lib/ggsn/gsn_restart
60 fi
61
62 start-stop-daemon --start --quiet --pidfile $PIDFILE --exec $DAEMON -- \
63 $DAEMON_ARGS \
64 || return 2
65 # Add code here, if necessary, that waits for the process to be ready
66 # to handle requests from services started subsequently which depend
67 # on this one. As a last resort, sleep for some time.
68}
69
70#
71# Function that stops the daemon/service
72#
73do_stop()
74{
75 # Return
76 # 0 if daemon has been stopped
77 # 1 if daemon was already stopped
78 # 2 if daemon could not be stopped
79 # other if a failure occurred
80 start-stop-daemon --stop --quiet --retry=TERM/30/KILL/5 --pidfile $PIDFILE --name $NAME
81 RETVAL="$?"
82 [ "$RETVAL" = 2 ] && return 2
83 # Wait for children to finish too if this is a daemon that forks
84 # and if the daemon is only ever run from this initscript.
85 # If the above conditions are not satisfied then add some other code
86 # that waits for the process to drop all resources that could be
87 # needed by services started subsequently. A last resort is to
88 # sleep for some time.
89 start-stop-daemon --stop --quiet --oknodo --retry=0/30/KILL/5 --exec $DAEMON
90 [ "$?" = 2 ] && return 2
91 # Many daemons don't delete their pidfiles when they exit.
92 rm -f $PIDFILE
93 return "$RETVAL"
94}
95
96#
97# Function that sends a SIGHUP to the daemon/service
98#
99do_reload() {
100 #
101 # If the daemon can reload its configuration without
102 # restarting (for example, when it is sent a SIGHUP),
103 # then implement that here.
104 #
105 start-stop-daemon --stop --signal 1 --quiet --pidfile $PIDFILE --name $NAME
106 return 0
107}
108
109case "$1" in
110 start)
111 [ "$VERBOSE" != no ] && log_daemon_msg "Starting $DESC " "$NAME"
112 do_start
113 case "$?" in
114 0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;;
115 2) [ "$VERBOSE" != no ] && log_end_msg 1 ;;
116 esac
117 ;;
118 stop)
119 [ "$VERBOSE" != no ] && log_daemon_msg "Stopping $DESC" "$NAME"
120 do_stop
121 case "$?" in
122 0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;;
123 2) [ "$VERBOSE" != no ] && log_end_msg 1 ;;
124 esac
125 ;;
126 status)
127 status_of_proc "$DAEMON" "$NAME" && exit 0 || exit $?
128 ;;
129 #reload|force-reload)
130 #
131 # If do_reload() is not implemented then leave this commented out
132 # and leave 'force-reload' as an alias for 'restart'.
133 #
134 #log_daemon_msg "Reloading $DESC" "$NAME"
135 #do_reload
136 #log_end_msg $?
137 #;;
138 restart|force-reload)
139 #
140 # If the "reload" option is implemented then remove the
141 # 'force-reload' alias
142 #
143 log_daemon_msg "Restarting $DESC" "$NAME"
144 do_stop
145 case "$?" in
146 0|1)
147 do_start
148 case "$?" in
149 0) log_end_msg 0 ;;
150 1) log_end_msg 1 ;; # Old process is still running
151 *) log_end_msg 1 ;; # Failed to start
152 esac
153 ;;
154 *)
155 # Failed to stop
156 log_end_msg 1
157 ;;
158 esac
159 ;;
160 *)
161 #echo "Usage: $SCRIPTNAME {start|stop|restart|reload|force-reload}" >&2
162 echo "Usage: $SCRIPTNAME {start|stop|status|restart|force-reload}" >&2
163 exit 3
164 ;;
165esac
166
167: