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"}));
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
70 # 0 if daemon has been started
71 # 1 if daemon was already running
72 # 2 if daemon could not be started
73 start-stop-daemon --start --background --quiet --pidfile $PIDFILE --exec $DAEMON --test > /dev/null \
75 start-stop-daemon --start --background --quiet --pidfile $PIDFILE --exec $DAEMON -- \
78 # Add code here, if necessary, that waits for the process to be ready
79 # to handle requests from services started subsequently which depend
80 # on this one. As a last resort, sleep for some time.
84 # Function that stops the daemon/service
89 # 0 if daemon has been stopped
90 # 1 if daemon was already stopped
91 # 2 if daemon could not be stopped
92 # other if a failure occurred
93 start-stop-daemon --stop --quiet --retry=TERM/30/KILL/5 --pidfile $PIDFILE --name $NAME
95 [ "$RETVAL" = 2 ] && return 2
96 # Wait for children to finish too if this is a daemon that forks
97 # and if the daemon is only ever run from this initscript.
98 # If the above conditions are not satisfied then add some other code
99 # that waits for the process to drop all resources that could be
100 # needed by services started subsequently. A last resort is to
101 # sleep for some time.
102 start-stop-daemon --stop --quiet --oknodo --retry=0/30/KILL/5 --exec $DAEMON
103 [ "$?" = 2 ] && return 2
104 # Many daemons don't delete their pidfiles when they exit.
110 # Function that sends a SIGHUP to the daemon/service
114 # If the daemon can reload its configuration without
115 # restarting (for example, when it is sent a SIGHUP),
116 # then implement that here.
118 start-stop-daemon --stop --signal 1 --quiet --pidfile $PIDFILE --name $NAME
124 [ "$VERBOSE" != no ] && log_daemon_msg "Starting $DESC" "$NAME"
127 0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;;
128 2) [ "$VERBOSE" != no ] && log_end_msg 1 ;;
132 [ "$VERBOSE" != no ] && log_daemon_msg "Stopping $DESC" "$NAME"
135 0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;;
136 2) [ "$VERBOSE" != no ] && log_end_msg 1 ;;
139 #reload|force-reload)
141 # If do_reload() is not implemented then leave this commented out
142 # and leave 'force-reload' as an alias for 'restart'.
144 #log_daemon_msg "Reloading $DESC" "$NAME"
148 restart|force-reload)
150 # If the "reload" option is implemented then remove the
151 # 'force-reload' alias
153 log_daemon_msg "Restarting $DESC" "$NAME"
160 1) log_end_msg 1 ;; # Old process is still running
161 *) log_end_msg 1 ;; # Failed to start
171 #echo "Usage: $SCRIPTNAME {start|stop|restart|reload|force-reload}" >&2
172 echo "Usage: $SCRIPTNAME {start|stop|restart|force-reload}" >&2