Start / stop buttons

This commit is contained in:
Jamie Cameron
2011-04-18 11:30:20 -07:00
parent b1c0f9e561
commit a71cfc40c9
5 changed files with 29 additions and 10 deletions

View File

@ -120,7 +120,9 @@ elsif ($init_mode eq "win32") {
elsif ($init_mode eq "rc" || $init_mode eq "upstart") { elsif ($init_mode eq "rc" || $init_mode eq "upstart") {
# Create RC or upstart script # Create RC or upstart script
&enable_at_boot($product, $ucproduct, "$config_directory/start", &enable_at_boot($product, $ucproduct, "$config_directory/start",
"$config_directory/stop"); "$config_directory/stop",
undef,
{ 'fork' => 1 });
} }
$config{'atboot_product'} = $product; $config{'atboot_product'} = $product;

5
init/edit_upstart.cgi Normal file → Executable file
View File

@ -37,7 +37,8 @@ if ($in{'new'}) {
# Server command # Server command
print &ui_table_row($text{'upstart_server'}, print &ui_table_row($text{'upstart_server'},
&ui_textbox("server", undef, 60)); &ui_textbox("server", undef, 60)."<br>\n".
&ui_checkbox("fork", 1, $text{'upstart_fork'}, 0));
# Start at boot? # Start at boot?
print &ui_table_row($text{'upstart_boot'}, print &ui_table_row($text{'upstart_boot'},
@ -72,6 +73,8 @@ if ($in{'new'}) {
} }
else { else {
print &ui_form_end([ [ undef, $text{'save'} ], print &ui_form_end([ [ undef, $text{'save'} ],
[ 'start', $text{'index_start'} ],
[ 'stop', $text{'index_stop'} ],
[ 'delete', $text{'delete'} ] ]); [ 'delete', $text{'delete'} ] ]);
} }

View File

@ -566,7 +566,7 @@ elsif ($init_mode eq "osx") {
} }
} }
=head2 enable_at_boot(action, description, startcode, stopcode, statuscode) =head2 enable_at_boot(action, description, startcode, stopcode, statuscode, &opts)
Makes some action start at boot time, creating the script by copying the Makes some action start at boot time, creating the script by copying the
specified file if necessary. The parameters are : specified file if necessary. The parameters are :
@ -581,6 +581,8 @@ specified file if necessary. The parameters are :
=item statuscode - Shell code to output the action's status. =item statuscode - Shell code to output the action's status.
=item opts - Hash ref of additional options, like : fork -> server will fork into background
If this is called for a named action that already exists (even if it isn't If this is called for a named action that already exists (even if it isn't
enabled), only the first parameter needs to be given. enabled), only the first parameter needs to be given.
@ -610,7 +612,7 @@ if ($init_mode eq "upstart" && (!-r "$config{'init_dir'}/$_[0]" ||
} }
else { else {
# Need to create config # Need to create config
&create_upstart_service($_[0], $_[1], $_[2]); &create_upstart_service($_[0], $_[1], $_[2], $_[5]->{'fork'});
&system_logged("insserv ".quotemeta($_[0])." >/dev/null 2>&1"); &system_logged("insserv ".quotemeta($_[0])." >/dev/null 2>&1");
} }
} }
@ -1623,14 +1625,14 @@ my $out = &backquote_logged(
return (!$?, $out); return (!$?, $out);
} }
=head2 create_upstart_service(name, description, command, [pre-script]) =head2 create_upstart_service(name, description, command, [pre-script], [fork])
Create a new upstart service with the given details. Create a new upstart service with the given details.
=cut =cut
sub create_upstart_service sub create_upstart_service
{ {
my ($name, $desc, $server, $prestart) = @_; my ($name, $desc, $server, $prestart, $forks) = @_;
my $cfile = "/etc/init/$name.conf"; my $cfile = "/etc/init/$name.conf";
&open_lock_tempfile(CFILE, ">$cfile"); &open_lock_tempfile(CFILE, ">$cfile");
&print_tempfile(CFILE, &print_tempfile(CFILE,
@ -1642,10 +1644,14 @@ my $cfile = "/etc/init/$name.conf";
"\n". "\n".
"start on runlevel [2345]\n". "start on runlevel [2345]\n".
"stop on runlevel [!2345]\n". "stop on runlevel [!2345]\n".
"\n". "\n"
);
if ($forks) {
&print_tempfile(CFILE,
"expect fork\n". "expect fork\n".
"\n" "\n"
); );
}
if ($prestart) { if ($prestart) {
&print_tempfile(CFILE, &print_tempfile(CFILE,
"pre-start script\n". "pre-start script\n".

View File

@ -191,8 +191,9 @@ upstart_elegacy=Not an upstart service!
upstart_header=Upstart service details upstart_header=Upstart service details
upstart_name=Service name upstart_name=Service name
upstart_desc=Service description upstart_desc=Service description
upstart_prestart=Commands to run before starting server upstart_prestart=Commands to run before starting server<br>(Optional)
upstart_server=Server program and parameters upstart_server=Server program and parameters
upstart_fork=Server forks into the background?
upstart_conf=Configuration file upstart_conf=Configuration file
upstart_boot=Start at boot time? upstart_boot=Start at boot time?
upstart_status=Current status upstart_status=Current status

9
init/save_upstart.cgi Normal file → Executable file
View File

@ -15,6 +15,13 @@ if (!$in{'new'}) {
$u->{'legacy'} && &error($text{'upstart_elegacy'}); $u->{'legacy'} && &error($text{'upstart_elegacy'});
} }
if ($in{'start'} || $in{'stop'}) {
# Just redirect to the start page
&redirect("mass_upstarts.cgi?d=".&urlize($in{'name'}).
($in{'start'} ? "start=1" : "stop=1"));
exit;
}
if ($in{'delete'}) { if ($in{'delete'}) {
# Delete the service # Delete the service
&disable_at_boot($in{'name'}); &disable_at_boot($in{'name'});
@ -36,7 +43,7 @@ elsif ($in{'new'}) {
# Create the config file # Create the config file
&create_upstart_service($in{'name'}, $in{'desc'}, $in{'server'}, &create_upstart_service($in{'name'}, $in{'desc'}, $in{'server'},
$in{'prestart'}); $in{'prestart'}, $in{'fork'});
# Enable at boot if selected # Enable at boot if selected
if ($in{'boot'} == 0) { if ($in{'boot'} == 0) {