3 # Creates a sysvinit file from a metainit description.
8 $filename = shift || die "Filename expected!\n";
9 # Parse the metainit in
10 %initparams = Parse::parse($filename);
12 # Print the "dynamic" part of the initskript
16 # Provides: $initparams{"Name"}
17 # Default-Start: 2 3 4 5
19 # Short-Description: $initparams{"Desc"}
23 print "# Riequired-Start: " . join(" ",@{$initparams{"Required-Start"}}) . "\n";
24 print "# Required-Stop: " . join(" ",@{$initparams{"Required-Stop"}}) . "\n";
25 print "# Description: ";
26 print join("\n# ",split("\n",$initparams{"Description"})). "\n";
33 # This initscript has been autogenerated my metainit.
34 # Do not edit this file, but edit the corresponding metainit
37 # PATH should only include /usr/* if it runs after the mountnfs.sh script
38 PATH=/sbin:/usr/sbin:/bin:/usr/bin
39 DESC="$initparams{"Desc"}"
40 NAME=$initparams{"Name"}
41 DAEMON=$initparams{"Path"}
42 DAEMON_ARGS="$initparams{"Args"}"
43 PIDFILE=/var/run/\$NAME.pid
44 SCRIPTNAME=/etc/init.d/\$NAME
48 # ... and the rest of the initscript, that is identical for all
49 # metainit-created scripts.
51 # Exit if the package is not installed
52 [ -x "$DAEMON" ] || exit 0
54 # Read configuration variable file if it is present
55 [ -r /etc/default/$NAME ] && . /etc/default/$NAME
57 # Load the VERBOSE setting and other rcS variables
60 # Define LSB log_* functions.
61 # Depend on lsb-base (>= 3.0-6) to ensure that this file is present.
62 . /lib/lsb/init-functions
65 # Function that starts the daemon/service
72 if($initparams{"Prestart-Hook"}) {
73 print "\t" . join("\n\t",split("\n",$initparams{"Prestart-Hook"}));
79 # 0 if daemon has been started
80 # 1 if daemon was already running
81 # 2 if daemon could not be started
82 start-stop-daemon --start --background --quiet --pidfile $PIDFILE --exec $DAEMON --test > /dev/null \
84 start-stop-daemon --start --background --quiet --pidfile $PIDFILE --exec $DAEMON -- \
87 # Add code here, if necessary, that waits for the process to be ready
88 # to handle requests from services started subsequently which depend
89 # on this one. As a last resort, sleep for some time.
93 # Function that stops the daemon/service
98 # 0 if daemon has been stopped
99 # 1 if daemon was already stopped
100 # 2 if daemon could not be stopped
101 # other if a failure occurred
102 start-stop-daemon --stop --quiet --retry=TERM/30/KILL/5 --pidfile $PIDFILE --name $NAME
104 [ "$RETVAL" = 2 ] && return 2
105 # Wait for children to finish too if this is a daemon that forks
106 # and if the daemon is only ever run from this initscript.
107 # If the above conditions are not satisfied then add some other code
108 # that waits for the process to drop all resources that could be
109 # needed by services started subsequently. A last resort is to
110 # sleep for some time.
111 start-stop-daemon --stop --quiet --oknodo --retry=0/30/KILL/5 --exec $DAEMON
112 [ "$?" = 2 ] && return 2
113 # Many daemons don't delete their pidfiles when they exit.
118 if($initparams{"Poststop-Hook"}) {
119 print "\t" . join("\n\t",split("\n",$initparams{"Poststop-Hook"}));
128 # Function that sends a SIGHUP to the daemon/service
132 # If the daemon can reload its configuration without
133 # restarting (for example, when it is sent a SIGHUP),
134 # then implement that here.
136 start-stop-daemon --stop --signal 1 --quiet --pidfile $PIDFILE --name $NAME
142 [ "$VERBOSE" != no ] && log_daemon_msg "Starting $DESC" "$NAME"
145 0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;;
146 2) [ "$VERBOSE" != no ] && log_end_msg 1 ;;
150 [ "$VERBOSE" != no ] && log_daemon_msg "Stopping $DESC" "$NAME"
153 0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;;
154 2) [ "$VERBOSE" != no ] && log_end_msg 1 ;;
157 #reload|force-reload)
159 # If do_reload() is not implemented then leave this commented out
160 # and leave 'force-reload' as an alias for 'restart'.
162 #log_daemon_msg "Reloading $DESC" "$NAME"
166 restart|force-reload)
168 # If the "reload" option is implemented then remove the
169 # 'force-reload' alias
171 log_daemon_msg "Restarting $DESC" "$NAME"
178 1) log_end_msg 1 ;; # Old process is still running
179 *) log_end_msg 1 ;; # Failed to start
189 #echo "Usage: $SCRIPTNAME {start|stop|restart|reload|force-reload}" >&2
190 echo "Usage: $SCRIPTNAME {start|stop|restart|force-reload}" >&2