Don't re-create init script if already there

This commit is contained in:
Jamie Cameron
2009-10-01 10:43:22 -07:00
parent b036193bed
commit 3aa486b925

View File

@@ -21,88 +21,91 @@ elsif ($init_mode eq "local") {
&flush_file_lines();
}
elsif ($init_mode eq "init") {
# Create a bootup action
# Create a bootup action, if missing
@start = &get_start_runlevels();
$fn = &action_filename($product);
&open_tempfile(ACTION,">$fn");
$desc = "Start/stop $ucproduct";
&print_tempfile(ACTION, "#!/bin/sh\n");
$start_order = "9" x $config{'order_digits'};
$stop_order = "9" x $config{'order_digits'};
if ($config{'chkconfig'}) {
# Redhat-style description: and chkconfig: lines
&print_tempfile(ACTION, "# description: $desc\n");
&print_tempfile(ACTION, "# chkconfig: $config{'chkconfig'} ",
"$start_order $stop_order\n");
}
elsif ($config{'init_info'}) {
# Suse-style init info section
&print_tempfile(ACTION, "### BEGIN INIT INFO\n",
"# Provides: $product\n",
"# Required-Start: \$network \$syslog\n",
"# Required-Stop: \$network\n",
"# Default-Start: ",join(" ", @start),"\n",
"# Description: $desc\n",
"### END INIT INFO\n");
}
else {
# Just description in a comment
&print_tempfile(ACTION, "# $desc\n");
}
&print_tempfile(ACTION, "\n");
&print_tempfile(ACTION, "case \"\$1\" in\n");
if (!-r $fn) {
&open_tempfile(ACTION,">$fn");
$desc = "Start/stop $ucproduct";
&print_tempfile(ACTION, "#!/bin/sh\n");
$start_order = "9" x $config{'order_digits'};
$stop_order = "9" x $config{'order_digits'};
if ($config{'chkconfig'}) {
# Redhat-style description: and chkconfig: lines
&print_tempfile(ACTION, "# description: $desc\n");
&print_tempfile(ACTION,
"# chkconfig: $config{'chkconfig'} ",
"$start_order $stop_order\n");
}
elsif ($config{'init_info'}) {
# Suse-style init info section
&print_tempfile(ACTION, "### BEGIN INIT INFO\n",
"# Provides: $product\n",
"# Required-Start: \$network \$syslog\n",
"# Required-Stop: \$network\n",
"# Default-Start: ",join(" ", @start),"\n",
"# Description: $desc\n",
"### END INIT INFO\n");
}
else {
# Just description in a comment
&print_tempfile(ACTION, "# $desc\n");
}
&print_tempfile(ACTION, "\n");
&print_tempfile(ACTION, "case \"\$1\" in\n");
&print_tempfile(ACTION, "'start')\n");
&print_tempfile(ACTION, "\t$config_directory/start >/dev/null 2>&1 </dev/null\n");
&print_tempfile(ACTION, "\tRETVAL=\$?\n");
if ($config{'subsys'}) {
&print_tempfile(ACTION, "\tif [ \"\$RETVAL\" = \"0\" ]; then\n");
&print_tempfile(ACTION, "\t\ttouch $config{'subsys'}/$product\n");
&print_tempfile(ACTION, "'start')\n");
&print_tempfile(ACTION, "\t$config_directory/start >/dev/null 2>&1 </dev/null\n");
&print_tempfile(ACTION, "\tRETVAL=\$?\n");
if ($config{'subsys'}) {
&print_tempfile(ACTION, "\tif [ \"\$RETVAL\" = \"0\" ]; then\n");
&print_tempfile(ACTION, "\t\ttouch $config{'subsys'}/$product\n");
&print_tempfile(ACTION, "\tfi\n");
}
&print_tempfile(ACTION, "\t;;\n");
&print_tempfile(ACTION, "'stop')\n");
&print_tempfile(ACTION, "\t$config_directory/stop\n");
&print_tempfile(ACTION, "\tRETVAL=\$?\n");
if ($config{'subsys'}) {
&print_tempfile(ACTION, "\tif [ \"\$RETVAL\" = \"0\" ]; then\n");
&print_tempfile(ACTION, "\t\trm -f $config{'subsys'}/$product\n");
&print_tempfile(ACTION, "\tfi\n");
}
&print_tempfile(ACTION, "\t;;\n");
&print_tempfile(ACTION, "'status')\n");
&print_tempfile(ACTION, "\tpidfile=`grep \"^pidfile=\" $config_directory/miniserv.conf | sed -e 's/pidfile=//g'`\n");
&print_tempfile(ACTION, "\tif [ -s \$pidfile ]; then\n");
&print_tempfile(ACTION, "\t\tpid=`cat \$pidfile`\n");
&print_tempfile(ACTION, "\t\tkill -0 \$pid >/dev/null 2>&1\n");
&print_tempfile(ACTION, "\t\tif [ \"\$?\" = \"0\" ]; then\n");
&print_tempfile(ACTION, "\t\t\techo \"$product (pid \$pid) is running\"\n");
&print_tempfile(ACTION, "\t\t\tRETVAL=0\n");
&print_tempfile(ACTION, "\t\telse\n");
&print_tempfile(ACTION, "\t\t\techo \"$product is stopped\"\n");
&print_tempfile(ACTION, "\t\t\tRETVAL=1\n");
&print_tempfile(ACTION, "\t\tfi\n");
&print_tempfile(ACTION, "\telse\n");
&print_tempfile(ACTION, "\t\techo \"$product is stopped\"\n");
&print_tempfile(ACTION, "\t\tRETVAL=1\n");
&print_tempfile(ACTION, "\tfi\n");
&print_tempfile(ACTION, "\t;;\n");
&print_tempfile(ACTION, "'restart')\n");
&print_tempfile(ACTION, "\t$config_directory/stop ; $config_directory/start\n");
&print_tempfile(ACTION, "\tRETVAL=\$?\n");
&print_tempfile(ACTION, "\t;;\n");
&print_tempfile(ACTION, "*)\n");
&print_tempfile(ACTION, "\techo \"Usage: \$0 { start | stop }\"\n");
&print_tempfile(ACTION, "\tRETVAL=1\n");
&print_tempfile(ACTION, "\t;;\n");
&print_tempfile(ACTION, "esac\n");
&print_tempfile(ACTION, "exit \$RETVAL\n");
&close_tempfile(ACTION);
chmod(0755, $fn);
}
&print_tempfile(ACTION, "\t;;\n");
&print_tempfile(ACTION, "'stop')\n");
&print_tempfile(ACTION, "\t$config_directory/stop\n");
&print_tempfile(ACTION, "\tRETVAL=\$?\n");
if ($config{'subsys'}) {
&print_tempfile(ACTION, "\tif [ \"\$RETVAL\" = \"0\" ]; then\n");
&print_tempfile(ACTION, "\t\trm -f $config{'subsys'}/$product\n");
&print_tempfile(ACTION, "\tfi\n");
}
&print_tempfile(ACTION, "\t;;\n");
&print_tempfile(ACTION, "'status')\n");
&print_tempfile(ACTION, "\tpidfile=`grep \"^pidfile=\" $config_directory/miniserv.conf | sed -e 's/pidfile=//g'`\n");
&print_tempfile(ACTION, "\tif [ -s \$pidfile ]; then\n");
&print_tempfile(ACTION, "\t\tpid=`cat \$pidfile`\n");
&print_tempfile(ACTION, "\t\tkill -0 \$pid >/dev/null 2>&1\n");
&print_tempfile(ACTION, "\t\tif [ \"\$?\" = \"0\" ]; then\n");
&print_tempfile(ACTION, "\t\t\techo \"$product (pid \$pid) is running\"\n");
&print_tempfile(ACTION, "\t\t\tRETVAL=0\n");
&print_tempfile(ACTION, "\t\telse\n");
&print_tempfile(ACTION, "\t\t\techo \"$product is stopped\"\n");
&print_tempfile(ACTION, "\t\t\tRETVAL=1\n");
&print_tempfile(ACTION, "\t\tfi\n");
&print_tempfile(ACTION, "\telse\n");
&print_tempfile(ACTION, "\t\techo \"$product is stopped\"\n");
&print_tempfile(ACTION, "\t\tRETVAL=1\n");
&print_tempfile(ACTION, "\tfi\n");
&print_tempfile(ACTION, "\t;;\n");
&print_tempfile(ACTION, "'restart')\n");
&print_tempfile(ACTION, "\t$config_directory/stop ; $config_directory/start\n");
&print_tempfile(ACTION, "\tRETVAL=\$?\n");
&print_tempfile(ACTION, "\t;;\n");
&print_tempfile(ACTION, "*)\n");
&print_tempfile(ACTION, "\techo \"Usage: \$0 { start | stop }\"\n");
&print_tempfile(ACTION, "\tRETVAL=1\n");
&print_tempfile(ACTION, "\t;;\n");
&print_tempfile(ACTION, "esac\n");
&print_tempfile(ACTION, "exit \$RETVAL\n");
&close_tempfile(ACTION);
chmod(0755, $fn);
# Add whatever links are needed to start at boot
&enable_at_boot($product);