Start / stop buttons
authorJamie Cameron <jcameron@webmin.com>
Mon, 18 Apr 2011 18:30:20 +0000 (11:30 -0700)
committerJamie Cameron <jcameron@webmin.com>
Mon, 18 Apr 2011 18:30:20 +0000 (11:30 -0700)
init/atboot.pl
init/edit_upstart.cgi [changed mode: 0644->0755]
init/init-lib.pl
init/lang/en
init/save_upstart.cgi [changed mode: 0644->0755]

index c4b38da..ed25b22 100755 (executable)
@@ -120,7 +120,9 @@ elsif ($init_mode eq "win32") {
 elsif ($init_mode eq "rc" || $init_mode eq "upstart") {
        # Create RC or upstart script
        &enable_at_boot($product, $ucproduct, "$config_directory/start",
-                                             "$config_directory/stop");
+                                             "$config_directory/stop",
+                                             undef,
+                                             { 'fork' => 1 });
        }
 
 $config{'atboot_product'} = $product;
old mode 100644 (file)
new mode 100755 (executable)
index 6c7355a..825903b
@@ -37,7 +37,8 @@ if ($in{'new'}) {
 
        # Server command
        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?
        print &ui_table_row($text{'upstart_boot'},
@@ -72,6 +73,8 @@ if ($in{'new'}) {
        }
 else {
        print &ui_form_end([ [ undef, $text{'save'} ],
+                            [ 'start', $text{'index_start'} ],
+                            [ 'stop', $text{'index_stop'} ],
                             [ 'delete', $text{'delete'} ] ]);
        }
 
index c2a8a8f..e1d808b 100755 (executable)
@@ -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
 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 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
 enabled), only the first parameter needs to be given.
 
@@ -610,7 +612,7 @@ if ($init_mode eq "upstart" && (!-r "$config{'init_dir'}/$_[0]" ||
                }
        else {
                # 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");
                }
        }
@@ -1623,14 +1625,14 @@ my $out = &backquote_logged(
 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.
 
 =cut
 sub create_upstart_service
 {
-my ($name, $desc, $server, $prestart) = @_;
+my ($name, $desc, $server, $prestart, $forks) = @_;
 my $cfile = "/etc/init/$name.conf";
 &open_lock_tempfile(CFILE, ">$cfile");
 &print_tempfile(CFILE,
@@ -1642,10 +1644,14 @@ my $cfile = "/etc/init/$name.conf";
   "\n".
   "start on runlevel [2345]\n".
   "stop on runlevel [!2345]\n".
-  "\n".
-  "expect fork\n".
   "\n"
   );
+if ($forks) {
+       &print_tempfile(CFILE,
+         "expect fork\n".
+         "\n"
+         );
+       }
 if ($prestart) {
        &print_tempfile(CFILE,
          "pre-start script\n".
index 235b1a8..b83a197 100644 (file)
@@ -191,8 +191,9 @@ upstart_elegacy=Not an upstart service!
 upstart_header=Upstart service details
 upstart_name=Service name
 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_fork=Server forks into the background?
 upstart_conf=Configuration file
 upstart_boot=Start at boot time?
 upstart_status=Current status
old mode 100644 (file)
new mode 100755 (executable)
index cdae3c1..3a1c87b
@@ -15,6 +15,13 @@ if (!$in{'new'}) {
        $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'}) {
        # Delete the service
        &disable_at_boot($in{'name'});
@@ -36,7 +43,7 @@ elsif ($in{'new'}) {
 
        # Create the config file
        &create_upstart_service($in{'name'}, $in{'desc'}, $in{'server'},
-                               $in{'prestart'});
+                               $in{'prestart'}, $in{'fork'});
 
        # Enable at boot if selected
        if ($in{'boot'} == 0) {