diff --git a/init/edit_upstart.cgi b/init/edit_upstart.cgi new file mode 100644 index 000000000..cb9edfbef --- /dev/null +++ b/init/edit_upstart.cgi @@ -0,0 +1,56 @@ +#!/usr/local/bin/perl +# Show a form for creating or editing an upstart action + +require './init-lib.pl'; +$access{'bootup'} || &error($text{'edit_ecannot'}); +&ReadParse(); + +if ($in{'new'}) { + &ui_print_header(undef, $text{'upstart_title1'}, ""); + $u = { }; + } +else { + &ui_print_header(undef, $text{'upstart_title2'}, ""); + @upstarts = &list_upstart_services(); + ($u) = grep { $_->{'name'} eq $in{'name'} } @upstarts; + $u || &error($text{'upstart_egone'}); + $u->{'legacy'} && &error($text{'upstart_elegacy'}); + } + +print &ui_form_start("save_upstart.cgi", "post"); +print &ui_hidden("new", $in{'new'}); +print &ui_hidden("name", $in{'name'}) if (!$in{'new'}); +print &ui_table_start($text{'upstart_header'}, undef, 2); + +if ($in{'new'}) { + # Service name + + # Description + + # Pre-start script + + # Server command + } +else { + # Service name (non-editable) + print &ui_table_row($text{'upstart_name'}, + "$in{'name'}"); + + # Config file + $cfile = "/etc/init/$in{'name'}.conf"; + $conf = &read_file_contents($cfile); + print &ui_table_row($text{'upstart_conf'}, + &ui_textarea("conf", $conf, 20, 80)); + } + +print &ui_table_end(); +if ($in{'new'}) { + print &ui_form_end([ [ undef, $text{'create'} ] ]); + } +else { + print &ui_form_end([ [ undef, $text{'create'} ], + [ 'delete', $text{'delete'} ] ]); + } + +&ui_print_footer("", $text{'index_return'}); + diff --git a/init/index.cgi b/init/index.cgi index 5b104e2ac..5221de9dc 100755 --- a/init/index.cgi +++ b/init/index.cgi @@ -316,10 +316,15 @@ elsif ($init_mode eq "upstart" && $access{'bootup'}) { $text{'index_uboot'}, $text{'index_ustatus'}, ]); foreach $u (&list_upstart_services()) { + if ($u->{'legacy'}) { + $l = "edit_action.cgi?0+".&urlize($u->{'name'}); + } + else { + $l = "edit_upstart.cgi?name=".&urlize($u->{'name'}); + } print &ui_columns_row([ &ui_checkbox("d", $u->{'name'}, undef), - "$u->{'name'}", + "$u->{'name'}", $u->{'desc'}, $u->{'boot'} eq 'start' ? $text{'yes'} : $u->{'boot'} eq 'stop' ? diff --git a/init/init-lib.pl b/init/init-lib.pl index 6390a69b0..c7bce3ef9 100755 --- a/init/init-lib.pl +++ b/init/init-lib.pl @@ -912,14 +912,16 @@ if ($init_mode eq "upstart") { # Just use insserv to disable, and comment out start line in .conf file &system_logged("insserv -r ".quotemeta($_[0])." >/dev/null 2>&1"); my $cfile = "/etc/init/$_[0].conf"; - my $lref = &read_file_lines($cfile); - foreach my $l (@$lref) { - if ($l =~ /^\s*start/) { - $l = "#".$l; - last; + if (-r $cfile) { + my $lref = &read_file_lines($cfile); + foreach my $l (@$lref) { + if ($l =~ /^\s*start/) { + $l = "#".$l; + last; + } } + &flush_file_lines($cfile); } - &flush_file_lines($cfile); } if ($init_mode eq "init" || $init_mode eq "upstart") { # Unlink or disable init script @@ -1586,9 +1588,9 @@ my $out = &backquote_logged( return (!$?, $out); } -# stop_upstop_service(name) +# stop_upstart_service(name) # Shut down the upstop service with some name, and return an OK flag and output -sub stop_upstop_service +sub stop_upstart_service { my ($name) = @_; my $out = &backquote_logged( diff --git a/init/lang/en b/init/lang/en index 216413816..6e62d716e 100644 --- a/init/lang/en +++ b/init/lang/en @@ -165,6 +165,13 @@ mass_starting=Starting action $1 .. mass_stopping=Stopping action $1 .. mass_failed=.. failed! mass_ok=.. done. +mass_ustart=Starting Services +mass_urestart=Restarting Services +mass_ustop=Stopping Services +mass_uenable=Enabling service $1 at boot time. +mass_udisable=Disabling service $1 at boot time. +mass_ustarting=Starting service $1 .. +mass_ustopping=Stopping service $1 .. change_err=You are not allowed to switch runlevels change_title=Switch Runlevel @@ -177,4 +184,12 @@ mode_win32=Windows services mode_rc=FreeBSD RC scripts mode_upstart=Upstart +upstart_title1=Create Upstart Service +upstart_title2=Edit Upstart Service +upstart_egone=Service no longer exists! +upstart_elegacy=Not an upstart service! +upstart_header=Upstart service details +upstart_name=Service name +upstart_conf=Configuration file + __norefs=1 diff --git a/init/mass_upstarts.cgi b/init/mass_upstarts.cgi new file mode 100755 index 000000000..18f58a694 --- /dev/null +++ b/init/mass_upstarts.cgi @@ -0,0 +1,56 @@ +#!/usr/local/bin/perl +# Start or stop a bunch of upstart services + +require './init-lib.pl'; +&ReadParse(); +@sel = split(/\0/, $in{'d'}); +@sel || &error($text{'mass_enone'}); + +$start = 1 if ($in{'start'} || $in{'addboot_start'}); +$stop = 1 if ($in{'stop'} || $in{'delboot_stop'}); +$enable = 1 if ($in{'addboot'} || $in{'addboot_start'}); +$disable = 1 if ($in{'delboot'} || $in{'delboot_stop'}); + +&ui_print_unbuffered_header(undef, $start || $enable ? $text{'mass_ustart'} + : $text{'mass_ustop'}, ""); + +if ($start || $stop) { + # Starting or stopping a bunch of services + $access{'bootup'} || &error($text{'ss_ecannot'}); + foreach $s (@sel) { + if ($start) { + print &text('mass_ustarting', "$s"),"
\n"; + ($ok, $out) = &start_upstart_service($s); + } + else { + print &text('mass_ustopping', "$s"),"
\n"; + ($ok, $out) = &stop_upstart_service($s); + } + print "
$out"; + if (!$ok) { + print $text{'mass_failed'},"
\n"; + } + else { + print $text{'mass_ok'},"
\n"; + } + } + } + +if ($enable || $disable) { + # Enable or disable at boot + $access{'bootup'} == 1 || &error($text{'edit_ecannot'}); + foreach $b (@sel) { + if ($enable) { + print &text('mass_uenable', "$b"),"
\n"; + &enable_at_boot($b); + } + else { + print &text('mass_udisable', "$b"),"
\n"; + &disable_at_boot($b); + } + } + &webmin_log($enable ? 'massenable' : 'massdisable', 'action', + join(" ", @sel)); + } + +&ui_print_footer("", $text{'index_return'});