More work on upstart support

This commit is contained in:
Jamie Cameron
2011-04-16 16:50:39 -07:00
parent db41e955dd
commit 9a8024a0ec
2 changed files with 72 additions and 30 deletions

View File

@@ -610,7 +610,8 @@ if ($init_mode eq "upstart" && (!-r "$config{'init_dir'}/$_[0]" ||
}
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") {
@@ -1578,8 +1579,11 @@ foreach my $a (&list_actions()) {
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) = @_;
@@ -1588,8 +1592,11 @@ my $out = &backquote_logged(
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) = @_;
@@ -1598,6 +1605,56 @@ my $out = &backquote_logged(
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.

View File

@@ -18,7 +18,7 @@ if (!$in{'new'}) {
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'}) {
@@ -31,34 +31,19 @@ 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'});
}