More work on upstart
authorJamie Cameron <jcameron@webmin.com>
Sat, 16 Apr 2011 20:06:39 +0000 (13:06 -0700)
committerJamie Cameron <jcameron@webmin.com>
Sat, 16 Apr 2011 20:06:39 +0000 (13:06 -0700)
init/edit_upstart.cgi
init/lang/en
init/save_upstart.cgi

index 97317e1..6c7355a 100644 (file)
@@ -24,12 +24,24 @@ print &ui_table_start($text{'upstart_header'}, undef, 2);
 
 if ($in{'new'}) {
        # Service name
+       print &ui_table_row($text{'upstart_name'},
+                           &ui_textbox("name", undef, 30));
 
        # Description
+       print &ui_table_row($text{'upstart_desc'},
+                           &ui_textbox("desc", undef, 60));
 
        # Pre-start script
+       print &ui_table_row($text{'upstart_prestart'},
+                           &ui_textarea("prestart", undef, 5, 80));
 
        # Server command
+       print &ui_table_row($text{'upstart_server'},
+                           &ui_textbox("server", undef, 60));
+
+       # Start at boot?
+       print &ui_table_row($text{'upstart_boot'},
+                           &ui_yesno_radio("boot", 1));
        }
 else {
        # Service name (non-editable)
index 8094948..235b1a8 100644 (file)
@@ -190,6 +190,9 @@ upstart_egone=Service no longer exists!
 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_server=Server program and parameters
 upstart_conf=Configuration file
 upstart_boot=Start at boot time?
 upstart_status=Current status
@@ -197,5 +200,10 @@ upstart_status0=Not running
 upstart_status1=Running with PID $1
 upstart_err=Failed to save upstart service
 upstart_econf=No configuration file contents entered
+upstart_ename=Missing or invalid-lookup upstart service name
+upstart_eclash=A service with the same name already exists
+upstart_edesc=Missing service description
+upstart_eserver=No server command entered
+upstart_eserver2=Server command does not exist
 
 __norefs=1
index 3fe2547..cd1df4d 100644 (file)
@@ -5,10 +5,10 @@ require './init-lib.pl';
 &error_setup($text{'upstart_err'});
 $access{'bootup'} || &error($text{'edit_ecannot'});
 &ReadParse();
+@upstarts = &list_upstart_services();
 
 # 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'});
@@ -19,9 +19,21 @@ if ($in{'delete'}) {
        # XXX
        }
 elsif ($in{'new'}) {
+       # Validate inputs and check for clash
+       $in{'name'} =~ /^[a-z0-9\.\_\-]+$/i ||
+               &error($text{'upstart_ename'});
+       ($clash) = grep { $_->{'name'} eq $in{'name'} } @upstarts;
+       $clash && &error($text{'upstart_eclash'});
+       $in{'desc'} || &error($text{'upstart_edesc'});
+       $in{'server'} =~ /\S/ || &error($text{'upstart_eserver'});
+       ($bin, $args) = split(/\s+/, $in{'server'});
+       &has_command($bin) || &error($text{'upstart_eserver2'});
+
        # Create the config file
+       # XXX
 
-       # Enable at boot
+       # Enable at boot if selected
+       &enable_at_boot($in{'name'}) if ($in{'boot'});
        }
 else {
        # Just save the config file