source: llxcfg/trunk/fuentes/debian/llxcfg-runtime.llxcfg-backend-daemon.init @ 98

Last change on this file since 98 was 96, checked in by hectorgh, 5 years ago

adding proyect files

  • Property svn:executable set to *
File size: 4.4 KB
Line 
1#! /bin/bash
2### BEGIN INIT INFO
3# Provides:          llxcfg-backend
4# Required-Start:    $local_fs $remote_fs
5# Required-Stop:     $local_fs $remote_fs
6# Default-Start:     S 2 3 4 5
7# Default-Stop:      0 1 6
8# Short-Description: backend daemon for llxcfg
9# Description:       backend daemon for llxcfg
10### END INIT INFO
11
12# Author: Luis Garcia Gisbert <garcia_luigis@gva.es>
13#
14
15# Do NOT "set -e"
16
17# PATH should only include /usr/* if it runs after the mountnfs.sh script
18PATH=/usr/sbin:/usr/bin:/sbin:/bin
19
20LIB_FILE="/usr/share/lliurex/llxcfg-backend/llxcfg-backend-common.sh"
21[ -r "$LIB_FILE" ] || exit 0
22. "$LIB_FILE"
23
24DESC="backend daemon for llxcfg"
25NAME=llxcfg-backend-daemon
26PIDFILE=/var/run/$NAME.pid
27DAEMON=/usr/sbin/$NAME
28DAEMON_ARGS="$LBACK_SOCKET --pidfile $PIDFILE --unix --daemon --in --out $LBACK_SERVER"
29SCRIPTNAME=/etc/init.d/$NAME
30
31# Exit if the package is not installed
32[ -x "$DAEMON" ] || exit 0
33[ -x "$LBACK_SERVER" ] || exit 0
34
35# Read configuration variable file if it is present
36[ -r /etc/default/$NAME ] && . /etc/default/$NAME
37
38# Load the VERBOSE setting and other rcS variables
39[ -f /etc/default/rcS ] && . /etc/default/rcS
40
41# Define LSB log_* functions.
42# Depend on lsb-base (>= 3.0-6) to ensure that this file is present.
43. /lib/lsb/init-functions
44
45#
46# Function that starts the daemon/service
47#
48prepare_socket(){
49   mkdir -p "$(dirname "$LBACK_SOCKET")"
50}
51remove_socket(){
52   rm -f "$LBACK_SOCKET"   
53}
54enable_socket(){
55   chgrp llxcfg "$LBACK_SOCKET"
56   chmod g+w,g+r "$LBACK_SOCKET"
57}
58
59do_start()
60{
61        # Return
62        #   0 if daemon has been started
63        #   1 if daemon was already running
64        #   2 if daemon could not be started
65        start-stop-daemon --start --quiet --pidfile $PIDFILE --exec $DAEMON --test > /dev/null \
66                || return 1
67        remove_socket
68        prepare_socket
69        start-stop-daemon --start --quiet --pidfile $PIDFILE --exec $DAEMON -- \
70                $DAEMON_ARGS \
71                || return 2
72        # Add code here, if necessary, that waits for the process to be ready
73        # to handle requests from services started subsequently which depend
74        # on this one.  As a last resort, sleep for some time.
75        enable_socket
76}
77
78#
79# Function that stops the daemon/service
80#
81do_stop()
82{
83        # Return
84        #   0 if daemon has been stopped
85        #   1 if daemon was already stopped
86        #   2 if daemon could not be stopped
87        #   other if a failure occurred
88        start-stop-daemon --stop --quiet --retry=TERM/30/KILL/5 --pidfile $PIDFILE
89        RETVAL="$?"
90        [ "$RETVAL" = 2 ] && return 2
91        # Wait for children to finish too if this is a daemon that forks
92        # and if the daemon is only ever run from this initscript.
93        # If the above conditions are not satisfied then add some other code
94        # that waits for the process to drop all resources that could be
95        # needed by services started subsequently.  A last resort is to
96        # sleep for some time.
97#       start-stop-daemon --stop --quiet --oknodo --retry=0/30/KILL/5 --exec $DAEMON
98#       [ "$?" = 2 ] && return 2
99        # Many daemons don't delete their pidfiles when they exit.
100        rm -f $PIDFILE
101        remove_socket
102        return "$RETVAL"
103}
104
105#
106# Function that sends a SIGHUP to the daemon/service
107#
108do_reload() {
109        #
110        # If the daemon can reload its configuration without
111        # restarting (for example, when it is sent a SIGHUP),
112        # then implement that here.
113        #
114        start-stop-daemon --stop --signal 1 --quiet --pidfile $PIDFILE
115        return 0
116}
117
118case "$1" in
119  start)
120        [ "$VERBOSE" != no ] && log_daemon_msg "Starting $DESC" "$NAME"
121        do_start
122        case "$?" in
123                0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;;
124                2) [ "$VERBOSE" != no ] && log_end_msg 1 ;;
125        esac
126        ;;
127  stop)
128        [ "$VERBOSE" != no ] && log_daemon_msg "Stopping $DESC" "$NAME"
129        do_stop
130        case "$?" in
131                0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;;
132                2) [ "$VERBOSE" != no ] && log_end_msg 1 ;;
133        esac
134        ;;
135  #reload|force-reload)
136        #
137        # If do_reload() is not implemented then leave this commented out
138        # and leave 'force-reload' as an alias for 'restart'.
139        #
140        #log_daemon_msg "Reloading $DESC" "$NAME"
141        #do_reload
142        #log_end_msg $?
143        #;;
144  restart|force-reload)
145        #
146        # If the "reload" option is implemented then remove the
147        # 'force-reload' alias
148        #
149        log_daemon_msg "Restarting $DESC" "$NAME"
150        do_stop
151        case "$?" in
152          0|1)
153                do_start
154                case "$?" in
155                        0) log_end_msg 0 ;;
156                        1) log_end_msg 1 ;; # Old process is still running
157                        *) log_end_msg 1 ;; # Failed to start
158                esac
159                ;;
160          *)
161                # Failed to stop
162                log_end_msg 1
163                ;;
164        esac
165        ;;
166  *)
167        #echo "Usage: $SCRIPTNAME {start|stop|restart|reload|force-reload}" >&2
168        echo "Usage: $SCRIPTNAME {start|stop|restart|force-reload}" >&2
169        exit 3
170        ;;
171esac
172
173:
Note: See TracBrowser for help on using the repository browser.