diff options
Diffstat (limited to 'lib')
-rw-r--r-- | lib/AdminPanel/Shared/Services.pm | 200 |
1 files changed, 105 insertions, 95 deletions
diff --git a/lib/AdminPanel/Shared/Services.pm b/lib/AdminPanel/Shared/Services.pm index 8402ee31..0a6737ef 100644 --- a/lib/AdminPanel/Shared/Services.pm +++ b/lib/AdminPanel/Shared/Services.pm @@ -26,7 +26,7 @@ my ($l, $on_services) = AdminPanel::Shared::Services::services(); xinetd_services is_service_running restart_or_start - stop + stopService start restart set_service @@ -80,11 +80,18 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA #-###################################################################################### use strict; -use lib qw(/usr/lib/libDrakX); -use common; -use run_program; +use diagnostics; +use Sys::Syslog; use File::Basename qw( basename ); +use AdminPanel::Shared qw(member); +use AdminPanel::Shared::Locales; + +use lib qw(/usr/lib/libDrakX); +use MDK::Common::Func qw(find); +use MDK::Common::File qw(cat_); +use run_program qw(rooted); + use base qw(Exporter); our @EXPORT = qw( @@ -93,8 +100,8 @@ our @EXPORT = qw( xinetd_services is_service_running restart_or_start - stop - start + stopService + startService restart set_service service_exists @@ -107,6 +114,9 @@ our @EXPORT = qw( set_status ); + +my $loc = AdminPanel::Shared::Locales->new(domain_name => 'libDrakX-standalone'); + #============================================================= =head2 description @@ -128,126 +138,126 @@ THis function return the description for the given service #============================================================= sub description { my %services = ( -acpid => N_("Listen and dispatch ACPI events from the kernel"), -alsa => N_("Launch the ALSA (Advanced Linux Sound Architecture) sound system"), -anacron => N_("Anacron is a periodic command scheduler."), -apmd => N_("apmd is used for monitoring battery status and logging it via syslog. +acpid => $loc->N_("Listen and dispatch ACPI events from the kernel"), +alsa => $loc->N_("Launch the ALSA (Advanced Linux Sound Architecture) sound system"), +anacron => $loc->N_("Anacron is a periodic command scheduler."), +apmd => $loc->N_("apmd is used for monitoring battery status and logging it via syslog. It can also be used for shutting down the machine when the battery is low."), -atd => N_("Runs commands scheduled by the at command at the time specified when +atd => $loc->N_("Runs commands scheduled by the at command at the time specified when at was run, and runs batch commands when the load average is low enough."), -'avahi-deamon' => N_("Avahi is a ZeroConf daemon which implements an mDNS stack"), -chronyd => N_("An NTP client/server"), -cpufreq => N_("Set CPU frequency settings"), -crond => N_("cron is a standard UNIX program that runs user-specified programs +'avahi-deamon' => $loc->N_("Avahi is a ZeroConf daemon which implements an mDNS stack"), +chronyd => $loc->N_("An NTP client/server"), +cpufreq => $loc->N_("Set CPU frequency settings"), +crond => $loc->N_("cron is a standard UNIX program that runs user-specified programs at periodic scheduled times. vixie cron adds a number of features to the basic UNIX cron, including better security and more powerful configuration options."), -cups => N_("Common UNIX Printing System (CUPS) is an advanced printer spooling system"), -dm => N_("Launches the graphical display manager"), -fam => N_("FAM is a file monitoring daemon. It is used to get reports when files change. +cups => $loc->N_("Common UNIX Printing System (CUPS) is an advanced printer spooling system"), +dm => $loc->N_("Launches the graphical display manager"), +fam => $loc->N_("FAM is a file monitoring daemon. It is used to get reports when files change. It is used by GNOME and KDE"), -g15daemon => N_("G15Daemon allows users access to all extra keys by decoding them and +g15daemon => $loc->N_("G15Daemon allows users access to all extra keys by decoding them and pushing them back into the kernel via the linux UINPUT driver. This driver must be loaded before g15daemon can be used for keyboard access. The G15 LCD is also supported. By default, with no other clients active, g15daemon will display a clock. Client applications and scripts can access the LCD via a simple API."), -gpm => N_("GPM adds mouse support to text-based Linux applications such the +gpm => $loc->N_("GPM adds mouse support to text-based Linux applications such the Midnight Commander. It also allows mouse-based console cut-and-paste operations, and includes support for pop-up menus on the console."), -haldaemon => N_("HAL is a daemon that collects and maintains information about hardware"), -harddrake => N_("HardDrake runs a hardware probe, and optionally configures +haldaemon => $loc->N_("HAL is a daemon that collects and maintains information about hardware"), +harddrake => $loc->N_("HardDrake runs a hardware probe, and optionally configures new/changed hardware."), -httpd => N_("Apache is a World Wide Web server. It is used to serve HTML files and CGI."), -inet => N_("The internet superserver daemon (commonly called inetd) starts a +httpd => $loc->N_("Apache is a World Wide Web server. It is used to serve HTML files and CGI."), +inet => $loc->N_("The internet superserver daemon (commonly called inetd) starts a variety of other internet services as needed. It is responsible for starting many services, including telnet, ftp, rsh, and rlogin. Disabling inetd disables all of the services it is responsible for."), -ip6tables => N_("Automates a packet filtering firewall with ip6tables"), -iptables => N_("Automates a packet filtering firewall with iptables"), -irqbalance => N_("Evenly distributes IRQ load across multiple CPUs for enhanced performance"), -keytable => N_("This package loads the selected keyboard map as set in +ip6tables => $loc->N_("Automates a packet filtering firewall with ip6tables"), +iptables => $loc->N_("Automates a packet filtering firewall with iptables"), +irqbalance => $loc->N_("Evenly distributes IRQ load across multiple CPUs for enhanced performance"), +keytable => $loc->N_("This package loads the selected keyboard map as set in /etc/sysconfig/keyboard. This can be selected using the kbdconfig utility. You should leave this enabled for most machines."), -kheader => N_("Automatic regeneration of kernel header in /boot for +kheader => $loc->N_("Automatic regeneration of kernel header in /boot for /usr/include/linux/{autoconf,version}.h"), -kudzu => N_("Automatic detection and configuration of hardware at boot."), -'laptop-mode' => N_("Tweaks system behavior to extend battery life"), -linuxconf => N_("Linuxconf will sometimes arrange to perform various tasks +kudzu => $loc->N_("Automatic detection and configuration of hardware at boot."), +'laptop-mode' => $loc->N_("Tweaks system behavior to extend battery life"), +linuxconf => $loc->N_("Linuxconf will sometimes arrange to perform various tasks at boot-time to maintain the system configuration."), -lpd => N_("lpd is the print daemon required for lpr to work properly. It is +lpd => $loc->N_("lpd is the print daemon required for lpr to work properly. It is basically a server that arbitrates print jobs to printer(s)."), -lvs => N_("Linux Virtual Server, used to build a high-performance and highly +lvs => $loc->N_("Linux Virtual Server, used to build a high-performance and highly available server."), -mandi => N_("Monitors the network (Interactive Firewall and wireless"), -mdadm => N_("Software RAID monitoring and management"), -messagebus => N_("DBUS is a daemon which broadcasts notifications of system events and other messages"), -msec => N_("Enables MSEC security policy on system startup"), -named => N_("named (BIND) is a Domain Name Server (DNS) that is used to resolve host names to IP addresses."), -netconsole => N_("Initializes network console logging"), -netfs => N_("Mounts and unmounts all Network File System (NFS), SMB (Lan +mandi => $loc->N_("Monitors the network (Interactive Firewall and wireless"), +mdadm => $loc->N_("Software RAID monitoring and management"), +messagebus => $loc->N_("DBUS is a daemon which broadcasts notifications of system events and other messages"), +msec => $loc->N_("Enables MSEC security policy on system startup"), +named => $loc->N_("named (BIND) is a Domain Name Server (DNS) that is used to resolve host names to IP addresses."), +netconsole => $loc->N_("Initializes network console logging"), +netfs => $loc->N_("Mounts and unmounts all Network File System (NFS), SMB (Lan Manager/Windows), and NCP (NetWare) mount points."), -network => N_("Activates/Deactivates all network interfaces configured to start +network => $loc->N_("Activates/Deactivates all network interfaces configured to start at boot time."), -'network-auth' => N_("Requires network to be up if enabled"), -'network-up' => N_("Wait for the hotplugged network to be up"), -nfs => N_("NFS is a popular protocol for file sharing across TCP/IP networks. +'network-auth' => $loc->N_("Requires network to be up if enabled"), +'network-up' => $loc->N_("Wait for the hotplugged network to be up"), +nfs => $loc->N_("NFS is a popular protocol for file sharing across TCP/IP networks. This service provides NFS server functionality, which is configured via the /etc/exports file."), -nfslock => N_("NFS is a popular protocol for file sharing across TCP/IP +nfslock => $loc->N_("NFS is a popular protocol for file sharing across TCP/IP networks. This service provides NFS file locking functionality."), -ntpd => N_("Synchronizes system time using the Network Time Protocol (NTP)"), -numlock => N_("Automatically switch on numlock key locker under console +ntpd => $loc->N_("Synchronizes system time using the Network Time Protocol (NTP)"), +numlock => $loc->N_("Automatically switch on numlock key locker under console and Xorg at boot."), -oki4daemon => N_("Support the OKI 4w and compatible winprinters."), -partmon => N_("Checks if a partition is close to full up"), -pcmcia => N_("PCMCIA support is usually to support things like ethernet and +oki4daemon => $loc->N_("Support the OKI 4w and compatible winprinters."), +partmon => $loc->N_("Checks if a partition is close to full up"), +pcmcia => $loc->N_("PCMCIA support is usually to support things like ethernet and modems in laptops. It will not get started unless configured so it is safe to have it installed on machines that do not need it."), -portmap => N_("The portmapper manages RPC connections, which are used by +portmap => $loc->N_("The portmapper manages RPC connections, which are used by protocols such as NFS and NIS. The portmap server must be running on machines which act as servers for protocols which make use of the RPC mechanism."), -portreserve => N_("Reserves some TCP ports"), -postfix => N_("Postfix is a Mail Transport Agent, which is the program that moves mail from one machine to another."), -random => N_("Saves and restores system entropy pool for higher quality random +portreserve => $loc->N_("Reserves some TCP ports"), +postfix => $loc->N_("Postfix is a Mail Transport Agent, which is the program that moves mail from one machine to another."), +random => $loc->N_("Saves and restores system entropy pool for higher quality random number generation."), -rawdevices => N_("Assign raw devices to block devices (such as hard disk drive +rawdevices => $loc->N_("Assign raw devices to block devices (such as hard disk drive partitions), for the use of applications such as Oracle or DVD players"), -resolvconf => N_("Nameserver information manager"), -routed => N_("The routed daemon allows for automatic IP router table updated via +resolvconf => $loc->N_("Nameserver information manager"), +routed => $loc->N_("The routed daemon allows for automatic IP router table updated via the RIP protocol. While RIP is widely used on small networks, more complex routing protocols are needed for complex networks."), -rstatd => N_("The rstat protocol allows users on a network to retrieve +rstatd => $loc->N_("The rstat protocol allows users on a network to retrieve performance metrics for any machine on that network."), -rsyslog => N_("Syslog is the facility by which many daemons use to log messages to various system log files. It is a good idea to always run rsyslog."), -rusersd => N_("The rusers protocol allows users on a network to identify who is +rsyslog => $loc->N_("Syslog is the facility by which many daemons use to log messages to various system log files. It is a good idea to always run rsyslog."), +rusersd => $loc->N_("The rusers protocol allows users on a network to identify who is logged in on other responding machines."), -rwhod => N_("The rwho protocol lets remote users get a list of all of the users +rwhod => $loc->N_("The rwho protocol lets remote users get a list of all of the users logged into a machine running the rwho daemon (similar to finger)."), -saned => N_("SANE (Scanner Access Now Easy) enables to access scanners, video cameras, ..."), -shorewall => N_("Packet filtering firewall"), -smb => N_("The SMB/CIFS protocol enables to share access to files & printers and also integrates with a Windows Server domain"), -sound => N_("Launch the sound system on your machine"), -'speech-dispatcherd' => N_("layer for speech analysis"), -sshd => N_("Secure Shell is a network protocol that allows data to be exchanged over a secure channel between two computers"), -syslog => N_("Syslog is the facility by which many daemons use to log messages +saned => $loc->N_("SANE (Scanner Access Now Easy) enables to access scanners, video cameras, ..."), +shorewall => $loc->N_("Packet filtering firewall"), +smb => $loc->N_("The SMB/CIFS protocol enables to share access to files & printers and also integrates with a Windows Server domain"), +sound => $loc->N_("Launch the sound system on your machine"), +'speech-dispatcherd' => $loc->N_("layer for speech analysis"), +sshd => $loc->N_("Secure Shell is a network protocol that allows data to be exchanged over a secure channel between two computers"), +syslog => $loc->N_("Syslog is the facility by which many daemons use to log messages to various system log files. It is a good idea to always run syslog."), -'udev-post' => N_("Moves the generated persistent udev rules to /etc/udev/rules.d"), -usb => N_("Load the drivers for your usb devices."), -vnStat => N_("A lightweight network traffic monitor"), -xfs => N_("Starts the X Font Server."), -xinetd => N_("Starts other deamons on demand."), +'udev-post' => $loc->N_("Moves the generated persistent udev rules to /etc/udev/rules.d"), +usb => $loc->N_("Load the drivers for your usb devices."), +vnStat => $loc->N_("A lightweight network traffic monitor"), +xfs => $loc->N_("Starts the X Font Server."), +xinetd => $loc->N_("Starts other deamons on demand."), ); my ($name) = @_; my $s = $services{$name}; if ($s) { - $s = translate($s); + $s = $loc->N($s); } else { my $file = "$::prefix/usr/lib/systemd/system/$name.service"; if (-e $file) { - $s = cat_($file); + $s = MDK::Common::File::cat_($file); $s = $s =~ /^Description=(.*)/mg ? $1 : ''; } else { - $file = find { -e $_ } map { "$::prefix$_/$name" } '/etc/rc.d/init.d', '/etc/init.d', '/etc/xinetd.d'; - $s = cat_($file); + $file = MDK::Common::Func::find { -e $_ } map { "$::prefix$_/$name" } '/etc/rc.d/init.d', '/etc/init.d', '/etc/xinetd.d'; + $s = MDK::Common::File::cat_($file); $s =~ s/\\\s*\n#\s*//mg; $s = $s =~ /^#\s+(?:Short-)?[dD]escription:\s+(.*?)^(?:[^#]|# {0,2}\S)/sm ? $1 : @@ -282,7 +292,7 @@ sub set_service { my @xinetd_services = map { $_->[0] } xinetd_services(); - if (member($service, @xinetd_services)) { + if (AdminPanel::Shared::member($service, @xinetd_services)) { run_program::rooted($::prefix, "chkconfig", $enable ? "--add" : "--del", $service); } elsif (_running_systemd() || _has_systemd()) { # systemctl rejects any symlinked units. You have to enabled the real file @@ -297,7 +307,7 @@ sub set_service { my $script = "/etc/rc.d/init.d/$service"; run_program::rooted($::prefix, "chkconfig", $enable ? "--add" : "--del", $service); #- FIXME: handle services with no chkconfig line and with no Default-Start levels in LSB header - if ($enable && cat_("$::prefix$script") =~ /^#\s+chkconfig:\s+-/m) { + if ($enable && MDK::Common::File::cat_("$::prefix$script") =~ /^#\s+chkconfig:\s+-/m) { run_program::rooted($::prefix, "chkconfig", "--level", "35", $service, "on"); } } @@ -357,7 +367,7 @@ sub _systemd_services() { my @services; my %loaded; # Running system using systemd - log::explanations("Detected systemd running. Using systemctl introspection."); + Sys::Syslog::syslog('info|local1', "Detected systemd running. Using systemctl introspection."); foreach (run_program::rooted_get_stdout($::prefix, '/bin/systemctl', '--full', '--all', 'list-units')) { if (my ($name) = m!^(\S+)\.service\s+loaded!) { # We only look at non-template, non-linked service files in /lib @@ -377,7 +387,7 @@ sub _systemd_services() { # also handled by systemd if (!exists $loaded{$name} && $name !~ /.*\@$/g && (-e "$::prefix/lib/systemd/system/$name.service" or -e "$::prefix/etc/rc.d/init.d/$name") && ! -l "$::prefix/lib/systemd/system/$name.service") { # Limit ourselves to "standard" targets which can be enabled - my $wantedby = cat_("$::prefix/lib/systemd/system/$name.service") =~ /^WantedBy=(graphical|multi-user).target$/sm ? $1 : ''; + my $wantedby = MDK::Common::File::cat_("$::prefix/lib/systemd/system/$name.service") =~ /^WantedBy=(graphical|multi-user).target$/sm ? $1 : ''; if ($wantedby) { push @services, [ $name, 0 ]; } @@ -398,14 +408,14 @@ sub _legacy_services() { # as much as is practicable from the native systemd unit files and # combine that with information from chkconfig regarding legacy sysvinit # scripts (which systemd will parse and include when running) - log::explanations("Detected systemd installed. Using fake service+chkconfig introspection."); + Sys::Syslog::syslog('info|local1', "Detected systemd installed. Using fake service+chkconfig introspection."); foreach (glob_("$::prefix/lib/systemd/system/*.service")) { my ($name) = m!([^/]*).service$!; # We only look at non-template, non-symlinked service files if (!(/.*\@\.service$/g) && ! -l $_) { # Limit ourselves to "standard" targets - my $wantedby = cat_($_) =~ /^WantedBy=(graphical|multi-user).target$/sm ? $1 : ''; + my $wantedby = MDK::Common::File::cat_($_) =~ /^WantedBy=(graphical|multi-user).target$/sm ? $1 : ''; if ($wantedby) { # Exclude if enabled statically # Note DO NOT use -e when testing for files that could @@ -420,7 +430,7 @@ sub _legacy_services() { } } } else { - log::explanations("Could not detect systemd. Using chkconfig service introspection."); + Sys::Syslog::syslog('info|local1', "Could not detect systemd. Using chkconfig service introspection."); } # Regardless of whether we expect to use systemd on next boot, we still @@ -471,15 +481,15 @@ all the active ones. sub services() { - my @services; + my @Services; if (_running_systemd()) { - @services = _systemd_services(); + @Services = _systemd_services(); } else { - @services = _legacy_services(); + @Services = _legacy_services(); } my @l = xinetd_services(); - push @l, @services; + push @l, @Services; @l = sort { $a->[0] cmp $b->[0] } @l; [ map { $_->[0] } @l ], [ map { $_->[0] } grep { $_->[1] } @l ]; } @@ -569,7 +579,7 @@ sub restart_or_start ($) { #============================================================= -=head2 start +=head2 startService =head3 INPUT @@ -583,7 +593,7 @@ This function starts a given service #============================================================= -sub start ($) { +sub startService ($) { my ($service) = @_; # Exit silently if the service is not installed service_exists($service) or return 1; @@ -615,7 +625,7 @@ sub start_not_running_service ($) { #============================================================= -=head2 stop +=head2 stopService =head3 INPUT @@ -628,7 +638,7 @@ This function stops a given service =cut #============================================================= -sub stop ($) { +sub stopService ($) { my ($service) = @_; # Exit silently if the service is not installed service_exists($service) or return 1; @@ -681,7 +691,7 @@ This function returns if the given service starts at boot sub starts_on_boot { my ($service) = @_; my (undef, $on_services) = services(); - member($service, @$on_services); + AdminPanel::Shared::member($service, @$on_services); } #============================================================= @@ -769,7 +779,7 @@ and stops it if o_dont_apply is not given sub disable { my ($service, $o_dont_apply) = @_; do_not_start_service_on_boot($service); - stop($service) unless $o_dont_apply; + stopService($service) unless $o_dont_apply; } #============================================================= |