#!/usr/bin/perl -w
#
# Creates a sysvinit file from a metainit description.
+#
use Parse;
+$filename = shift || die "Filename expected!\n";
# Parse the metainit in
-%initparams = parse($ARGV[0]);
+%initparams = Parse::parse($filename);
# Print the "dynamic" part of the initskript
-print << EOF
+print << "EOF"
#! /bin/sh
### BEGIN INIT INFO
-# Provides: $initparams{Name}
-# Required-Start: $initparams{Required-Start}
-# Required-Stop: $initparams{Required-Stop}
+# Provides: $initparams{"Name"}
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
+# Short-Description: $initparams{"Desc"}
+EOF
+;
+
+print "# Riequired-Start: " . join(" ",@{$initparams{"Required-Start"}}) . "\n";
+print "# Required-Stop: " . join(" ",@{$initparams{"Required-Stop"}}) . "\n";
+print "# Description: ";
+print join("\n# ",split("\n",$initparams{"Description"})). "\n";
+print "\n";
+
+print << "EOF"
### END INIT INFO
# WARNING:
# PATH should only include /usr/* if it runs after the mountnfs.sh script
PATH=/sbin:/usr/sbin:/bin:/usr/bin
-DESC="Description of the service"
-NAME=$parsed{Name}
-DAEMON=$parsed{Path}
-DAEMON_ARGS=$parsed{Args}
+DESC="$initparams{"Desc"}"
+NAME=$initparams{"Name"}
+DAEMON=$initparams{"Path"}
+DAEMON_ARGS="$initparams{"Args"}"
PIDFILE=/var/run/\$NAME.pid
SCRIPTNAME=/etc/init.d/\$NAME
EOF
+;
# ... and the rest of the initscript, that is identical for all
# metainit-created scripts.
#
do_start()
{
+EOF
+;
+
+if($initparams{"Prestart-Hook"}) {
+ print "\t" . join("\n\t",split("\n",$initparams{"Prestart-Hook"}));
+ print "\n";
+}
+
+print << 'EOF'
# Return
# 0 if daemon has been started
# 1 if daemon was already running
# 2 if daemon could not be started
- start-stop-daemon --start --quiet --pidfile $PIDFILE --exec $DAEMON --test > /dev/null \
+ start-stop-daemon --start --background --quiet --pidfile $PIDFILE --exec $DAEMON --test > /dev/null \
|| return 1
- start-stop-daemon --start --quiet --pidfile $PIDFILE --exec $DAEMON -- \
+ start-stop-daemon --start --background --quiet --pidfile $PIDFILE --exec $DAEMON -- \
$DAEMON_ARGS \
|| return 2
# Add code here, if necessary, that waits for the process to be ready
[ "$?" = 2 ] && return 2
# Many daemons don't delete their pidfiles when they exit.
rm -f $PIDFILE
+EOF
+;
+
+if($initparams{"Poststop-Hook"}) {
+ print "\t" . join("\n\t",split("\n",$initparams{"Poststop-Hook"}));
+ print "\n";
+}
+
+print << 'EOF';
return "$RETVAL"
}