Ability to edit existing upstart actions
authorJamie Cameron <jcameron@webmin.com>
Sat, 16 Apr 2011 07:13:35 +0000 (00:13 -0700)
committerJamie Cameron <jcameron@webmin.com>
Sat, 16 Apr 2011 07:13:35 +0000 (00:13 -0700)
init/edit_upstart.cgi
init/lang/en
init/mass_upstarts.cgi
init/save_upstart.cgi [new file with mode: 0644]

index cb9edfb..97317e1 100644 (file)
@@ -41,6 +41,17 @@ else {
        $conf = &read_file_contents($cfile);
        print &ui_table_row($text{'upstart_conf'},
                            &ui_textarea("conf", $conf, 20, 80));
+
+       # Current status
+       if ($u->{'boot'} eq 'start' || $u->{'boot'} eq 'stop') {
+               print &ui_table_row($text{'upstart_boot'},
+                           &ui_yesno_radio("boot", $u->{'boot'} eq 'start'));
+               }
+       if ($u->{'status'} eq 'waiting' || $u->{'status'} eq 'running') {
+               print &ui_table_row($text{'upstart_status'},
+                       $u->{'status'} eq 'waiting' ? $text{'upstart_status0'} :
+                               &text('upstart_status1', $u->{'pid'}));
+               }
        }
 
 print &ui_table_end();
@@ -48,7 +59,7 @@ if ($in{'new'}) {
        print &ui_form_end([ [ undef, $text{'create'} ] ]);
        }
 else {
-       print &ui_form_end([ [ undef, $text{'create'} ],
+       print &ui_form_end([ [ undef, $text{'save'} ],
                             [ 'delete', $text{'delete'} ] ]);
        }
 
index 6e62d71..8094948 100644 (file)
@@ -191,5 +191,11 @@ upstart_elegacy=Not an upstart service!
 upstart_header=Upstart service details
 upstart_name=Service name
 upstart_conf=Configuration file
+upstart_boot=Start at boot time?
+upstart_status=Current status
+upstart_status0=Not running
+upstart_status1=Running with PID $1
+upstart_err=Failed to save upstart service
+upstart_econf=No configuration file contents entered
 
 __norefs=1
index 18f58a6..b04bd8a 100755 (executable)
@@ -49,7 +49,7 @@ if ($enable || $disable) {
                        &disable_at_boot($b);
                        }
                }
-       &webmin_log($enable ? 'massenable' : 'massdisable', 'action',
+       &webmin_log($enable ? 'massenable' : 'massdisable', 'upstart',
                    join(" ", @sel));
        }
 
diff --git a/init/save_upstart.cgi b/init/save_upstart.cgi
new file mode 100644 (file)
index 0000000..3fe2547
--- /dev/null
@@ -0,0 +1,48 @@
+#!/usr/local/bin/perl
+# Create, update or delete an upstart service
+
+require './init-lib.pl';
+&error_setup($text{'upstart_err'});
+$access{'bootup'} || &error($text{'edit_ecannot'});
+&ReadParse();
+
+# Get the service
+if (!$in{'new'}) {
+       @upstarts = &list_upstart_services();
+       ($u) = grep { $_->{'name'} eq $in{'name'} } @upstarts;
+       $u || &error($text{'upstart_egone'});
+       $u->{'legacy'} && &error($text{'upstart_elegacy'});
+       }
+
+if ($in{'delete'}) {
+       # Delete the service
+       # XXX
+       }
+elsif ($in{'new'}) {
+       # Create the config file
+
+       # Enable at boot
+       }
+else {
+       # Just save the config file
+       $cfile = "/etc/init/$in{'name'}.conf";
+       $in{'conf'} =~ /\S/ || &error($text{'upstart_econf'});
+       $in{'conf'} =~ s/\r//g;
+       &open_lock_tempfile(CONF, ">$cfile");
+       &print_tempfile(CONF, $in{'conf'});
+       &close_tempfile(CONF);
+
+       # Enable or disable
+       if (defined($in{'boot'})) {
+               if ($in{'boot'} == 0) {
+                       &disable_at_boot($in{'name'});
+                       }
+               else {
+                       &enable_at_boot($in{'name'});
+                       }
+               }
+
+       &webmin_log("modify", "upstart", $in{'name'});
+       }
+&redirect("");
+