blob: 6fe1b87221355ea150e925d5aaeb93b9a6d5f848 [file] [log] [blame]
Harald Welte1e9b27b2010-08-26 13:26:07 +02001#!/bin/sh
2### BEGIN INIT INFO
Harald Welte632e8432017-09-05 18:12:14 +02003# Provides: osmo-ggsn
Holger Hans Peter Freyther827aec12014-09-23 16:40:53 +02004# Required-Start: $network $local_fs $remote_fs
5# Required-Stop: $network $remote_fs
Harald Welte1e9b27b2010-08-26 13:26:07 +02006# Default-Start: 2 3 4 5
7# Default-Stop: 0 1 6
Eric Butlerab9ff092012-08-24 21:16:01 -07008# Short-Description: Gateway GPRS Support Node
9# Description: Gateway GPRS Support Node
Harald Welte1e9b27b2010-08-26 13:26:07 +020010### 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
Harald Welte632e8432017-09-05 18:12:14 +020016DESC="OsmoGGSN Gateway GPRS Support Node"
Eric Butlerab9ff092012-08-24 21:16:01 -070017NAME=ggsn
Harald Welte632e8432017-09-05 18:12:14 +020018DAEMON=/usr/bin/osmo-ggsn
Eric Butlerab9ff092012-08-24 21:16:01 -070019DAEMON_ARGS="" # Arguments to run the daemon with
Harald Welte1e9b27b2010-08-26 13:26:07 +020020PIDFILE=/var/run/$NAME.pid
Harald Welte632e8432017-09-05 18:12:14 +020021SCRIPTNAME=/etc/init.d/osmo-ggsn
Harald Welte1e9b27b2010-08-26 13:26:07 +020022
23# Exit if the package is not installed
24[ -x $DAEMON ] || exit 0
25
26# Read configuration variable file if it is present
Harald Welte632e8432017-09-05 18:12:14 +020027[ -r /etc/default/osmo-ggsn ] && . /etc/default/osmo-ggsn
Harald Welte1e9b27b2010-08-26 13:26:07 +020028
29# Load the VERBOSE setting and other rcS variables
30. /lib/init/vars.sh
Harald Welte1e9b27b2010-08-26 13:26:07 +020031# Depend on lsb-base (>= 3.0-6) to ensure that this file is present.
32. /lib/lsb/init-functions
33
Eric Butlerab9ff092012-08-24 21:16:01 -070034DAEMON_ARGS="$DAEMON_ARGS"
Harald Welte1e9b27b2010-08-26 13:26:07 +020035
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 --pidfile $PIDFILE --exec $DAEMON --test > /dev/null \
46 || return 1
47
48 # Check for runtime directory of nonvolatile data
Harald Welte632e8432017-09-05 18:12:14 +020049 if [ ! -d /var/lib/osmo-ggsn ]; then
50 mkdir /var/lib/osmo-ggsn
Harald Welte1e9b27b2010-08-26 13:26:07 +020051 fi
52
53 # Check for GTP restart counter
Harald Welte632e8432017-09-05 18:12:14 +020054 if [ ! -f /var/lib/osmo-ggsn/gsn_restart ]; then
55 echo 0 > /var/lib/osmo-ggsn/gsn_restart
Harald Welte1e9b27b2010-08-26 13:26:07 +020056 fi
57
58 start-stop-daemon --start --quiet --pidfile $PIDFILE --exec $DAEMON -- \
59 $DAEMON_ARGS \
60 || return 2
61 # Add code here, if necessary, that waits for the process to be ready
62 # to handle requests from services started subsequently which depend
63 # on this one. As a last resort, sleep for some time.
64}
65
66#
67# Function that stops the daemon/service
68#
69do_stop()
70{
71 # Return
72 # 0 if daemon has been stopped
73 # 1 if daemon was already stopped
74 # 2 if daemon could not be stopped
75 # other if a failure occurred
76 start-stop-daemon --stop --quiet --retry=TERM/30/KILL/5 --pidfile $PIDFILE --name $NAME
77 RETVAL="$?"
78 [ "$RETVAL" = 2 ] && return 2
79 # Wait for children to finish too if this is a daemon that forks
80 # and if the daemon is only ever run from this initscript.
81 # If the above conditions are not satisfied then add some other code
82 # that waits for the process to drop all resources that could be
83 # needed by services started subsequently. A last resort is to
84 # sleep for some time.
85 start-stop-daemon --stop --quiet --oknodo --retry=0/30/KILL/5 --exec $DAEMON
86 [ "$?" = 2 ] && return 2
87 # Many daemons don't delete their pidfiles when they exit.
88 rm -f $PIDFILE
89 return "$RETVAL"
90}
91
92#
93# Function that sends a SIGHUP to the daemon/service
94#
95do_reload() {
96 #
97 # If the daemon can reload its configuration without
98 # restarting (for example, when it is sent a SIGHUP),
99 # then implement that here.
100 #
101 start-stop-daemon --stop --signal 1 --quiet --pidfile $PIDFILE --name $NAME
102 return 0
103}
104
105case "$1" in
106 start)
107 [ "$VERBOSE" != no ] && log_daemon_msg "Starting $DESC " "$NAME"
108 do_start
109 case "$?" in
110 0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;;
111 2) [ "$VERBOSE" != no ] && log_end_msg 1 ;;
112 esac
113 ;;
114 stop)
115 [ "$VERBOSE" != no ] && log_daemon_msg "Stopping $DESC" "$NAME"
116 do_stop
117 case "$?" in
118 0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;;
119 2) [ "$VERBOSE" != no ] && log_end_msg 1 ;;
120 esac
121 ;;
122 status)
123 status_of_proc "$DAEMON" "$NAME" && exit 0 || exit $?
124 ;;
125 #reload|force-reload)
126 #
127 # If do_reload() is not implemented then leave this commented out
128 # and leave 'force-reload' as an alias for 'restart'.
129 #
130 #log_daemon_msg "Reloading $DESC" "$NAME"
131 #do_reload
132 #log_end_msg $?
133 #;;
134 restart|force-reload)
135 #
136 # If the "reload" option is implemented then remove the
137 # 'force-reload' alias
138 #
139 log_daemon_msg "Restarting $DESC" "$NAME"
140 do_stop
141 case "$?" in
142 0|1)
143 do_start
144 case "$?" in
145 0) log_end_msg 0 ;;
146 1) log_end_msg 1 ;; # Old process is still running
147 *) log_end_msg 1 ;; # Failed to start
148 esac
149 ;;
150 *)
151 # Failed to stop
152 log_end_msg 1
153 ;;
154 esac
155 ;;
156 *)
157 #echo "Usage: $SCRIPTNAME {start|stop|restart|reload|force-reload}" >&2
158 echo "Usage: $SCRIPTNAME {start|stop|status|restart|force-reload}" >&2
159 exit 3
160 ;;
161esac
162
163: