}
else {
# Need to create config
- # XXX
+ &create_upstart_service($_[0], $_[1], $_[2]);
+ &system_logged("insserv ".quotemeta($_[0])." >/dev/null 2>&1");
}
}
if ($init_mode eq "init" || $init_mode eq "local" || $init_mode eq "upstart") {
return sort { $a->{'name'} cmp $b->{'name'} } @rv;
}
-# start_upstart_service(name)
-# Run the upstart service with some name, and return an OK flag and output
+=head2 start_upstart_service(name)
+
+Run the upstart service with some name, and return an OK flag and output
+
+=cut
sub start_upstart_service
{
my ($name) = @_;
return (!$?, $out);
}
-# stop_upstart_service(name)
-# Shut down the upstop service with some name, and return an OK flag and output
+=head2 stop_upstart_service(name)
+
+Shut down the upstop service with some name, and return an OK flag and output
+
+=cut
sub stop_upstart_service
{
my ($name) = @_;
return (!$?, $out);
}
+=head2 create_upstart_service(name, description, command, [pre-script])
+
+Create a new upstart service with the given details.
+
+=cut
+sub create_upstart_service
+{
+my ($name, $desc, $server, $prestart) = @_;
+my $cfile = "/etc/init/$name.conf";
+&open_lock_tempfile(CFILE, ">$cfile");
+&print_tempfile(CFILE,
+ "# $name\n".
+ "#\n".
+ "# $desc\n".
+ "\n".
+ "description \"$desc\"\n".
+ "\n".
+ "start on runlevel [2345]\n".
+ "stop on runlevel [!2345]\n".
+ "\n".
+ "expect fork\n".
+ "\n"
+ );
+if ($prestart) {
+ &print_tempfile(CFILE,
+ "pre-start script\n".
+ join("\n",
+ map { " ".$_."\n" }
+ split(/\n/, $prestart))."\n".
+ "end script\n".
+ "\n");
+ }
+&print_tempfile(CFILE, "exec ".$server."\n");
+&close_tempfile(CFILE);
+}
+
+=head2 delete_upstart_service(name)
+
+Delete all traces of some upstart service
+
+=cut
+sub delete_upstart_service
+{
+my ($name) = @_;
+&system_logged("insserv -r ".quotemeta($name)." >/dev/null 2>&1");
+my $cfile = "/etc/init/$name.conf";
+my $ifile = "/etc/init.d/$name";
+&unlink_logged($cfile, $ifile);
+}
+
=head2 reboot_system
Immediately reboots the system.
if ($in{'delete'}) {
# Delete the service
&disable_at_boot($in{'name'});
- &unlink_logged($cfile);
+ &delete_upstat_service($in{'name'});
&webmin_log("delete", "upstart", $in{'name'});
}
elsif ($in{'new'}) {
$in{'server'} =~ /\S/ || &error($text{'upstart_eserver'});
($bin, $args) = split(/\s+/, $in{'server'});
&has_command($bin) || &error($text{'upstart_eserver2'});
+ $in{'prestart'} =~ s/\r//g;
# Create the config file
- &open_lock_tempfile(CFILE, ">$cfile");
- &print_tempfile(CFILE,
- "# $in{'name'}\n".
- "#\n".
- "# $in{'desc'}\n".
- "\n".
- "description \"$in{'desc'}\"\n".
- "\n".
- "start on runlevel [2345]\n".
- "stop on runlevel [!2345]\n".
- "\n"
- );
- if ($in{'prestart'}) {
- &print_tempfile(CFILE,
- "pre-start script\n".
- join("\n",
- map { " ".$_."\n" }
- split(/\n/, $in{'prestart'}))."\n".
- "end script\n".
- "\n");
- }
- &print_tempfile(CFILE, "exec ".$in{'server'}."\n");
- &close_tempfile(CFILE);
+ &create_upstart_service($in{'name'}, $in{'desc'}, $in{'server'},
+ $in{'prestart'});
# Enable at boot if selected
- &enable_at_boot($in{'name'}) if ($in{'boot'});
+ if ($in{'boot'} == 0) {
+ &disable_at_boot($in{'name'});
+ }
+ else {
+ &enable_at_boot($in{'name'});
+ }
&webmin_log("create", "upstart", $in{'name'});
}