diff --git a/init/index.cgi b/init/index.cgi index d48b7939e..1c9e183ea 100755 --- a/init/index.cgi +++ b/init/index.cgi @@ -379,6 +379,41 @@ elsif ($init_mode eq "systemd" && $access{'bootup'}) { ]); } +elsif ($init_mode eq "launchd" && $access{'bootup'}) { + # Show launchd agents + print &ui_form_start("mass_launchd.cgi", "post"); + @links = ( &select_all_link("d"), + &select_invert_link("d"), + &ui_link("edit_launchd.cgi?new=1", $text{'index_ladd'}) ); + print &ui_links_row(\@links); + print &ui_columns_start([ "", $text{'index_lname'}, + $text{'index_uboot'}, + $text{'index_ustatus'}, ]); + foreach $u (&list_launchd_agents()) { + $l = "edit_launchd.cgi?name=".&urlize($u->{'name'}); + print &ui_columns_row([ + &ui_checkbox("d", $u->{'name'}, undef), + &ui_link($l, $u->{'name'}), + $u->{'boot'} == 1 ? $text{'yes'} : + "$text{'no'}", + $u->{'status'} ? $text{'yes'} : + "$text{'no'}", + ]); + } + print &ui_columns_end(); + print &ui_links_row(\@links); + print &ui_form_end([ [ "start", $text{'index_start'} ], + [ "stop", $text{'index_stop'} ], + [ "restart", $text{'index_restart'} ], + undef, + [ "addboot", $text{'index_addboot'} ], + [ "delboot", $text{'index_delboot'} ], + undef, + [ "addboot_start", $text{'index_addboot_start'} ], + [ "delboot_stop", $text{'index_delboot_stop'} ], + ]); + + } # reboot/shutdown buttons print &ui_hr(); diff --git a/init/init-lib.pl b/init/init-lib.pl index da33803f7..f849d3cea 100755 --- a/init/init-lib.pl +++ b/init/init-lib.pl @@ -28,7 +28,9 @@ use WebminCore; This variable is set based on the bootup system in use. Possible values are : -=item osx - MacOSX hostconfig files +=item osx - MacOSX hostconfig files, for older versions + +=item launchd - MacOS Launchd, for newer versions =item rc - FreeBSD 6+ RC files @@ -38,14 +40,17 @@ This variable is set based on the bootup system in use. Possible values are : =item win32 - Windows services -=item upstart - Upstart, seend on Ubuntu 11 +=item upstart - Upstart, seen on Ubuntu 11 -=item systemd - SystemD, as seen on Fedora 16 +=item systemd - SystemD, seen on Fedora 16 =cut if ($config{'init_mode'}) { $init_mode = $config{'init_mode'}; } +elsif (&has_command("launchd")) { + $init_mode = "launchd"; + } elsif ($config{'hostconfig'}) { $init_mode = "osx"; } @@ -2235,4 +2240,55 @@ elsif ($out =~ /stopped/i) { return -1; } +# list_launchd_agents() +# Returns an array of hash refs, each of which is a launchd daemon/agent +sub list_launchd_agents +{ +my @rv; + +# Get the initial list of actions +my $out = &backquote_command("launchctl list"); +&error("Failed to list launchd agents : $out") if ($?); +foreach my $l (split(/\r?\n/, $out)) { + next if ($l =~ /^PID/); # Header line + my ($pid, $status, $label) = split(/\s+/, $l); + next if ($label =~ /^0x/); # Not really a launchd job + push(@rv, { 'name' => $label, + 'status' => $pid eq "-" ? 0 : 1, + 'pid' => $pid eq "-" ? undef : $pid, }); + } + +# Get details on each one +foreach my $a (@rv) { + my $out = &backquote_command("launchctl list ".quotemeta($a->{'name'})); + my %attrs; + foreach my $l (split(/\r?\n/, $out)) { + if ($l =~ /"(\S+)"\s*=\s*"([^"]*)";/ || + $l =~ /"(\S+)"\s*=\s*\S+;/) { + $attrs{lc($1)} = $2; + } + } + $a->{'start'} = $attrs{'program'}; + $a->{'file'} = &get_launchd_file($a->{'name'}); + # XXX started at boot? + } + +return @rv; +} + +# get_launchd_file(name) +# Returns the path to the launchd config file for some name +sub get_launchd_file +{ +my ($name) = @_; +foreach my $dir ("/Library/LaunchAgents", + "/Library/LaunchDaemons/", + "/System/Library/LaunchAgents", + "/System/Library/LaunchDaemons") { + my $path = $dir."/".$name.".plist"; + return $path if (-r $path); + } +return "/Library/LaunchDaemons/".$name.".plist"; +} + 1; diff --git a/init/lang/en b/init/lang/en index c4ceee0c4..0699570af 100644 --- a/init/lang/en +++ b/init/lang/en @@ -50,6 +50,8 @@ index_ustatus=Running now? index_uadd=Create a new upstart service. index_sadd=Create a new systemd service. index_always=Always +index_ladd=Create a new launchd agent. +index_lname=Agent name edit_title=Edit Action create_title=Create Action @@ -187,6 +189,7 @@ mode_win32=Windows services mode_rc=FreeBSD RC scripts mode_upstart=Upstart mode_systemd=Systemd +mode_launchd=LaunchD upstart_title1=Create Upstart Service upstart_title2=Edit Upstart Service