source: OpenRLabs-Git/deploy/rlabs-docker/web2py-rlabs/scripts/web2py.ubuntu.sh

main
Last change on this file was 42bd667, checked in by David Fuertes <dfuertes@…>, 4 years ago

Historial Limpio

  • Property mode set to 100755
File size: 6.2 KB
Line 
1#! /bin/sh
2### BEGIN INIT INFO
3# startup script for Ubuntu and Debian Linux servers
4#
5# To use this file
6# cp ubuntu.sh /etc/init.d/web2py
7#
8# To automatitcally start at reboot
9# sudo update-rc.d web2py defaults
10#
11# Provides:          web2py
12# Required-Start:    $local_fs $remote_fs
13# Required-Stop:     $local_fs $remote_fs
14# Default-Start:     2 3 4 5
15# Default-Stop:      S 0 1 6
16# Short-Description: web2py initscript
17# Description:       This file starts up the web2py server.
18### END INIT INFO
19
20# Author: Mark Moore <mark.moore@fonjax.com>
21
22PATH=/usr/sbin:/usr/bin:/sbin:/bin
23DESC="Web Framework"
24NAME=web2py
25PIDDIR=/var/run/$NAME
26PIDFILE=$PIDDIR/$NAME.pid
27SCRIPTNAME=/etc/init.d/$NAME
28DAEMON=/usr/bin/python
29DAEMON_DIR=/usr/lib/$NAME
30DAEMON_ARGS="web2py.py --password=<recycle> --pid_filename=$PIDFILE"
31DAEMON_USER=web2py
32
33# Exit if the package is not installed
34[ -x "$DAEMON" ] || exit 0
35
36# Read configuration variable file if it is present
37[ -r /etc/default/$NAME ] && . /etc/default/$NAME
38
39# Load the VERBOSE setting and other rcS variables
40[ -f /etc/default/rcS ] && . /etc/default/rcS
41
42# Define LSB log_* functions.
43# Depend on lsb-base (>= 3.0-6) to ensure that this file is present.
44. /lib/lsb/init-functions
45
46#
47# Function that starts the daemon/service
48#
49do_start()
50{
51        # Return
52        #   0 if daemon has been started
53        #   1 if daemon was already running
54        #   2 if daemon could not be started
55
56        # The PIDDIR should normally be created during installation. This
57        # fixes things just in case.
58        [ -d $PIDDIR ] || mkdir -p $PIDDIR
59        [ -n "$DAEMON_USER" ] && chown --recursive $DAEMON_USER $PIDDIR
60
61        # Check to see if the daemon is already running.
62        start-stop-daemon --stop --test --quiet --pidfile $PIDFILE \
63                && return 1
64
65        start-stop-daemon --start --quiet -m --pidfile $PIDFILE \
66                ${DAEMON_USER:+--chuid $DAEMON_USER} --chdir $DAEMON_DIR \
67                --background --exec $DAEMON -- $DAEMON_ARGS \
68                || return 2
69
70        return 0;
71}
72
73#
74# Function that stops the daemon/service
75#
76do_stop()
77{
78        # Return
79        #   0 if daemon has been stopped
80        #   1 if daemon was already stopped
81        #   2 if daemon could not be stopped
82        #   other if a failure occurred
83
84        start-stop-daemon --stop --quiet --retry=TERM/30/KILL/5 --pidfile $PIDFILE
85        RETVAL=$?
86        # Many daemons don't delete their pidfiles when they exit.
87        rm -f $PIDFILE
88        return "$RETVAL"
89}
90
91#
92# Function that restarts the daemon/service
93#
94do_restart()
95{
96        # Return
97        #   0 if daemon was (re-)started
98        #   1 if daemon was not strated or re-started
99
100        do_stop
101        case "$?" in
102                0|1)
103                        do_start
104                        case "$?" in
105                                0) RETVAL=0 ;;
106                                1) RETVAL=1 ;; # Old process is still running
107                                *) RETVAL=1 ;; # Failed to start
108                        esac
109                        ;;
110                *) RETVAL=1 ;; # Failed to stop
111        esac
112
113        return "$RETVAL"
114}
115
116#
117# Function that sends a SIGHUP to the daemon/service
118#
119do_reload() {
120        #
121        # If the daemon can reload its configuration without
122        # restarting (for example, when it is sent a SIGHUP),
123        # then implement that here.
124        #
125        start-stop-daemon --stop --signal 1 --quiet --pidfile $PIDFILE
126        return 0
127}
128
129#
130# Function that queries the status of the daemon/service
131#
132do_status()
133{
134        # Return
135        #   0 if daemon is responding and OK
136        #   1 if daemon is not responding, but PIDFILE exists
137        #   2 if daemon is not responding, but LOCKFILE exists
138        #   3 if deamon is not running
139        #   4 if daemon status is unknown
140
141        # Check to see if the daemon is already running.
142        start-stop-daemon --stop --test --quiet --pidfile $PIDFILE \
143                && return 0
144        [ -f $PIDFILE ] && return 1
145        return 3
146}
147
148case "$1" in
149  start)
150        [ "$VERBOSE" != no ] && log_daemon_msg "Starting $DESC" "$NAME"
151        do_start
152        RETVAL=$?
153        [ "$VERBOSE" != no ] &&
154        case "$RETVAL" in
155                0|1) log_end_msg 0 ;;
156                *)   log_end_msg 1 ;;
157        esac
158        exit "$RETVAL"
159        ;;
160  stop)
161        [ "$VERBOSE" != no ] && log_daemon_msg "Stopping $DESC" "$NAME"
162        do_stop
163        RETVAL=$?
164        [ "$VERBOSE" != no ] &&
165        case "$RETVAL" in
166                0|1) log_end_msg 0 ;;
167                *)   log_end_msg 1 ;;
168        esac
169        exit "$RETVAL"
170        ;;
171  #reload|force-reload)
172        #
173        # If do_reload() is not implemented then leave this commented out
174        # and leave 'force-reload' as an alias for 'restart'.
175        #
176        #[ "$VERBOSE" != no ] && log_daemon_msg "Reloading $DESC" "$NAME"
177        #do_reload
178        #RETVAL=$?
179        #[ "$VERBOSE" != no ] && log_end_msg $?
180        #exit "$RETVAL"
181        #;;
182  restart|force-reload)
183        #
184        # If the "reload" option is implemented then remove the
185        # 'force-reload' alias
186        #
187        [ "$VERBOSE" != no ] && log_daemon_msg "Restarting $DESC" "$NAME"
188        do_restart
189        RETVAL=$?
190        [ "$VERBOSE" != no ] && log_end_msg "$RETVAL"
191        exit "$RETVAL"
192        ;;
193  status)
194    do_status
195        RETVAL=$?
196    [ "$VERBOSE" != no ] &&
197        case "$RETVAL" in
198          0) log_success_msg "$NAME is running" ;;
199          *) log_failure_msg "$NAME is not running" ;;
200        esac
201    exit "$RETVAL"
202        ;;
203  *)
204        echo "Usage: $SCRIPTNAME {start|stop|restart|force-reload|status}" >&2
205        exit 3
206        ;;
207esac
208
209:
210
211# This was based off /etc/init.d/skeleton from the Ubuntu 8.04 Hardy release.
212# (md5sum: da0162012b6a916bdbd4e2580282af78).  If we notice that changes, we
213# should re-examine things.
214
215# The configuration at the very top seems to be documented as part of the
216# Linux Standard Base (LSB) Specification.  See section 20.6 Facility Names
217# in particular.  This is also where I got the spec for the status parm.
218
219# References:
220# http://refspecs.linux-foundation.org/LSB_3.2.0/LSB-Core-generic/LSB-Core-generic.pdf
221# Debian Policy SysV init: http://www.debian.org/doc/debian-policy/ch-opersys.html#s-sysvinit
222# Examine files in /usr/share/doc/sysv-rc/
Note: See TracBrowser for help on using the repository browser.