Harald Welte | 1e9b27b | 2010-08-26 13:26:07 +0200 | [diff] [blame] | 1 | #!/bin/sh |
| 2 | ### BEGIN INIT INFO |
Harald Welte | 632e843 | 2017-09-05 18:12:14 +0200 | [diff] [blame] | 3 | # Provides: osmo-ggsn |
Holger Hans Peter Freyther | 827aec1 | 2014-09-23 16:40:53 +0200 | [diff] [blame] | 4 | # Required-Start: $network $local_fs $remote_fs |
| 5 | # Required-Stop: $network $remote_fs |
Harald Welte | 1e9b27b | 2010-08-26 13:26:07 +0200 | [diff] [blame] | 6 | # Default-Start: 2 3 4 5 |
| 7 | # Default-Stop: 0 1 6 |
Eric Butler | ab9ff09 | 2012-08-24 21:16:01 -0700 | [diff] [blame] | 8 | # Short-Description: Gateway GPRS Support Node |
| 9 | # Description: Gateway GPRS Support Node |
Harald Welte | 1e9b27b | 2010-08-26 13:26:07 +0200 | [diff] [blame] | 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 |
| 15 | PATH=/sbin:/usr/sbin:/bin:/usr/bin |
Harald Welte | 632e843 | 2017-09-05 18:12:14 +0200 | [diff] [blame] | 16 | DESC="OsmoGGSN Gateway GPRS Support Node" |
Eric Butler | ab9ff09 | 2012-08-24 21:16:01 -0700 | [diff] [blame] | 17 | NAME=ggsn |
Harald Welte | 632e843 | 2017-09-05 18:12:14 +0200 | [diff] [blame] | 18 | DAEMON=/usr/bin/osmo-ggsn |
Eric Butler | ab9ff09 | 2012-08-24 21:16:01 -0700 | [diff] [blame] | 19 | DAEMON_ARGS="" # Arguments to run the daemon with |
Harald Welte | 1e9b27b | 2010-08-26 13:26:07 +0200 | [diff] [blame] | 20 | PIDFILE=/var/run/$NAME.pid |
Harald Welte | 632e843 | 2017-09-05 18:12:14 +0200 | [diff] [blame] | 21 | SCRIPTNAME=/etc/init.d/osmo-ggsn |
Harald Welte | 1e9b27b | 2010-08-26 13:26:07 +0200 | [diff] [blame] | 22 | |
| 23 | # Exit if the package is not installed |
| 24 | [ -x $DAEMON ] || exit 0 |
| 25 | |
| 26 | # Read configuration variable file if it is present |
Harald Welte | 632e843 | 2017-09-05 18:12:14 +0200 | [diff] [blame] | 27 | [ -r /etc/default/osmo-ggsn ] && . /etc/default/osmo-ggsn |
Harald Welte | 1e9b27b | 2010-08-26 13:26:07 +0200 | [diff] [blame] | 28 | |
| 29 | # Load the VERBOSE setting and other rcS variables |
| 30 | . /lib/init/vars.sh |
Harald Welte | 1e9b27b | 2010-08-26 13:26:07 +0200 | [diff] [blame] | 31 | # Depend on lsb-base (>= 3.0-6) to ensure that this file is present. |
| 32 | . /lib/lsb/init-functions |
| 33 | |
Eric Butler | ab9ff09 | 2012-08-24 21:16:01 -0700 | [diff] [blame] | 34 | DAEMON_ARGS="$DAEMON_ARGS" |
Harald Welte | 1e9b27b | 2010-08-26 13:26:07 +0200 | [diff] [blame] | 35 | |
| 36 | # |
| 37 | # Function that starts the daemon/service |
| 38 | # |
| 39 | do_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 Welte | 632e843 | 2017-09-05 18:12:14 +0200 | [diff] [blame] | 49 | if [ ! -d /var/lib/osmo-ggsn ]; then |
| 50 | mkdir /var/lib/osmo-ggsn |
Harald Welte | 1e9b27b | 2010-08-26 13:26:07 +0200 | [diff] [blame] | 51 | fi |
| 52 | |
| 53 | # Check for GTP restart counter |
Harald Welte | 632e843 | 2017-09-05 18:12:14 +0200 | [diff] [blame] | 54 | if [ ! -f /var/lib/osmo-ggsn/gsn_restart ]; then |
| 55 | echo 0 > /var/lib/osmo-ggsn/gsn_restart |
Harald Welte | 1e9b27b | 2010-08-26 13:26:07 +0200 | [diff] [blame] | 56 | 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 | # |
| 69 | do_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 | # |
| 95 | do_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 | |
| 105 | case "$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 | ;; |
| 161 | esac |
| 162 | |
| 163 | : |