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