From ac438e27d97af770901b19e1b11129f4e6400a4f Mon Sep 17 00:00:00 2001 From: Jamie Cameron Date: Wed, 12 Mar 2008 20:48:58 +0000 Subject: [PATCH] Added startup API on OSX --- init/CHANGELOG | 2 ++ init/atboot.pl | 44 ++--------------------------- init/init-lib.pl | 73 ++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 78 insertions(+), 41 deletions(-) diff --git a/init/CHANGELOG b/init/CHANGELOG index d15371a60..7b7fe82ff 100644 --- a/init/CHANGELOG +++ b/init/CHANGELOG @@ -16,3 +16,5 @@ Added support for Unbuntu, which has not /etc/inittab file. Added start_action and stop_action functions for starting and stopping services in an OS-independent manner. ---- Changes since 1.390 ---- Re-wrote all user interface code to use the new Webmin UI library, for a more consistent look. +---- Changes since 1.400 ---- +Updated the API used by other modules to allow new actions to be created on MacOS X systems, such as the firewall startup script. diff --git a/init/atboot.pl b/init/atboot.pl index 7050d7daa..b2b939a91 100755 --- a/init/atboot.pl +++ b/init/atboot.pl @@ -9,47 +9,9 @@ $ucproduct = ucfirst($product); if ($init_mode eq "osx") { # Darwin System - &open_tempfile(LOCAL, ">>$config{'hostconfig'}"); - &print_tempfile(LOCAL, "WEBMIN=-YES-\n"); - &close_tempfile(LOCAL); - - $paramlist = "$config{'darwin_setup'}/$ucproduct/$config{'plist'}"; - $scriptfile = "$config{'darwin_setup'}/$ucproduct/$ucproduct"; - - # On a Virgin darwin system, $config{'darwin_setup'} may not yet exist - -d "$config{'darwin_setup'}/$ucproduct" || do { - if ( -d "$config{'darwin_setup'}" ) { - mkdir ("$config{'darwin_setup'}/$ucproduct", 0755); - } else { - mkdir ("$config{'darwin_setup'}", 0755); - mkdir ("$config{'darwin_setup'}/$ucproduct",0755); - } - } until -d "$config{'darwin_setup'}/$ucproduct"; - - &open_tempfile(PLIST, ">$paramlist"); - &print_tempfile(PLIST, "{\n"); - &print_tempfile(PLIST, "\t\tDescription\t\t= \"$ucproduct system administration daemon\";\n"); - &print_tempfile(PLIST, "\t\tProvides\t\t= (\"$ucproduct\");\n"); - &print_tempfile(PLIST, "\t\tRequires\t\t= (\"Resolver\");\n"); - &print_tempfile(PLIST, "\t\tOrderPreference\t\t= \"None\";\n"); - &print_tempfile(PLIST, "\t\tMessages =\n"); - &print_tempfile(PLIST, "\t\t{\n"); - &print_tempfile(PLIST, "\t\t\tstart\t= \"Starting $ucproduct Server\";\n"); - &print_tempfile(PLIST, "\t\t\tstop\t= \"Stopping $ucproduct Server\";\n"); - &print_tempfile(PLIST, "\t\t};\n"); - &print_tempfile(PLIST, "}\n"); - &close_tempfile(PLIST); - - # Create Bootup Script - &open_tempfile(STARTUP, ">$scriptfile"); - &print_tempfile(STARTUP, "#!/bin/sh\n\n"); - &print_tempfile(STARTUP, ". /etc/rc.common\n\n"); - &print_tempfile(STARTUP, "if [ \"\${WEBMIN:=-NO-}\" = \"-YES-\" ]; then\n"); - &print_tempfile(STARTUP, "\tConsoleMessage \"Starting $ucproduct\"\n"); - &print_tempfile(STARTUP, "\t$config_directory/start >/dev/null 2>&1 /dev/null 2>&1 {'enabled'} ? 2 : 1; } +elsif ($init_mode eq "osx") { + # Look for a hostconfig entry + local $ucname = uc($_[0]); + local %hc; + &read_env_file($config{'hostconfig'}, \%hc); + return $hc{$ucname} eq '-YES-' ? 2 : + $hc{$ucname} eq '-NO-' ? 1 : 0; + } } # enable_at_boot(action, description, startcode, stopcode, statuscode) @@ -661,6 +669,59 @@ elsif ($init_mode eq "rc") { } &unlock_rc_files(); } +elsif ($init_mode eq "osx") { + # Add hostconfig file entry + local $ucname = uc($_[0]); + local %hc; + &lock_file($config{'hostconfig'}); + &read_env_file($config{'hostconfig'}, \%hc); + if (!$hc{$ucname}) { + # Need to create action + local $ucfirst = ucfirst($_[0]); + local $dir = "$config{'darwin_setup'}/$ucfirst"; + local $paramlist = "$dir/$config{'plist'}"; + local $scriptfile = "$dir/$ucfirst"; + + # Create dirs if missing + if (!-d $config{'darwin_setup'}) { + &make_dir($config{'darwin_setup'}, 0755); + } + if (!-d $dir) { + &make_dir($dir, 0755); + } + + # Make params list file + &open_lock_tempfile(PLIST, ">$paramlist"); + &print_tempfile(PLIST, "{\n"); + &print_tempfile(PLIST, "\t\tDescription\t\t= \"$_[1]\";\n"); + &print_tempfile(PLIST, "\t\tProvides\t\t= (\"$ucfirst\");\n"); + &print_tempfile(PLIST, "\t\tRequires\t\t= (\"Resolver\");\n"); + &print_tempfile(PLIST, "\t\tOrderPreference\t\t= \"None\";\n"); + &print_tempfile(PLIST, "\t\tMessages =\n"); + &print_tempfile(PLIST, "\t\t{\n"); + &print_tempfile(PLIST, "\t\t\tstart\t= \"Starting $ucfirst\";\n"); + &print_tempfile(PLIST, "\t\t\tstop\t= \"Stopping $ucfirst\";\n"); + &print_tempfile(PLIST, "\t\t};\n"); + &print_tempfile(PLIST, "}\n"); + &close_tempfile(PLIST); + + # Create Bootup Script + &open_lock_tempfile(STARTUP, ">$scriptfile"); + &print_tempfile(STARTUP, "#!/bin/sh\n\n"); + &print_tempfile(STARTUP, ". /etc/rc.common\n\n"); + &print_tempfile(STARTUP, "if [ \"\${$ucname:=-NO-}\" = \"-YES-\" ]; then\n"); + &print_tempfile(STARTUP, "\tConsoleMessage \"Starting $ucfirst\"\n"); + &print_tempfile(STARTUP, "\t$_[2]\n"); + &print_tempfile(STARTUP, "fi\n"); + &close_tempfile(STARTUP); + &set_ownership_permissions(undef, undef, 0750, $scriptfile); + } + + # Update hostconfig file + $hc{$ucname} = '-YES-'; + &write_env_file($config{'hostconfig'}, \%hc); + &unlock_file($config{'hostconfig'}); + } } # disable_at_boot(action) @@ -739,6 +800,18 @@ elsif ($init_mode eq "rc") { &disable_rc_script($_[0]); &unlock_rc_files(); } +elsif ($init_mode eq "osx") { + # Disable in hostconfig + local $ucname = uc($_[0]); + local %hc; + &lock_file($config{'hostconfig'}); + &read_env_file($config{'hostconfig'}, \%hc); + if ($hc{$ucname} eq '-YES-' || $hc{$ucname} eq '-AUTOMATIC-') { + $hc{$ucname} = '-NO-'; + &write_env_file($config{'hostconfig'}, \%hc); + } + &unlock_file($config{'hostconfig'}); + } } # start_action(name)