Mass enable or disable of upstart actions
authorJamie Cameron <jcameron@webmin.com>
Sat, 16 Apr 2011 06:53:29 +0000 (23:53 -0700)
committerJamie Cameron <jcameron@webmin.com>
Sat, 16 Apr 2011 06:53:29 +0000 (23:53 -0700)
init/edit_upstart.cgi [new file with mode: 0644]
init/index.cgi
init/init-lib.pl
init/lang/en
init/mass_upstarts.cgi [new file with mode: 0755]

diff --git a/init/edit_upstart.cgi b/init/edit_upstart.cgi
new file mode 100644 (file)
index 0000000..cb9edfb
--- /dev/null
@@ -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'},
+                           "<tt>$in{'name'}</tt>");
+
+       # 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'});
+
index 5b104e2..5221de9 100755 (executable)
@@ -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),
-                       "<a href='edit_upstart.cgi?name=".
-                         &urlize($u->{'name'})."'>$u->{'name'}</a>",
+                       "<a href='$l'>$u->{'name'}</a>",
                        $u->{'desc'},
                        $u->{'boot'} eq 'start' ? $text{'yes'} :
                          $u->{'boot'} eq 'stop' ?
index 6390a69..c7bce3e 100755 (executable)
@@ -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(
index 2164138..6e62d71 100644 (file)
@@ -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 (executable)
index 0000000..18f58a6
--- /dev/null
@@ -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', "<tt>$s</tt>"),"<p>\n";
+                       ($ok, $out) = &start_upstart_service($s);
+                       }
+               else {
+                       print &text('mass_ustopping', "<tt>$s</tt>"),"<p>\n";
+                       ($ok, $out) = &stop_upstart_service($s);
+                       }
+               print "<pre>$out</pre>";
+               if (!$ok) {
+                       print $text{'mass_failed'},"<p>\n";
+                       }
+               else {
+                       print $text{'mass_ok'},"<p>\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', "<tt>$b</tt>"),"<p>\n";
+                       &enable_at_boot($b);
+                       }
+               else {
+                       print &text('mass_udisable', "<tt>$b</tt>"),"<p>\n";
+                       &disable_at_boot($b);
+                       }
+               }
+       &webmin_log($enable ? 'massenable' : 'massdisable', 'action',
+                   join(" ", @sel));
+       }
+
+&ui_print_footer("", $text{'index_return'});