summaryrefslogtreecommitdiffstats
path: root/perl-install/services.pm
diff options
context:
space:
mode:
authorOlivier Blin <oblin@mandriva.org>2005-05-24 09:09:51 +0000
committerOlivier Blin <oblin@mandriva.org>2005-05-24 09:09:51 +0000
commit198b116b2992debe37b4e86ea5e2447ce7d44818 (patch)
treeaf616383d134475ffcfcc61a803d1a882fee05e6 /perl-install/services.pm
parentb3e8cdcc5a896bda62c3af20168d2bcf0d4a4488 (diff)
downloaddrakx-198b116b2992debe37b4e86ea5e2447ce7d44818.tar
drakx-198b116b2992debe37b4e86ea5e2447ce7d44818.tar.gz
drakx-198b116b2992debe37b4e86ea5e2447ce7d44818.tar.bz2
drakx-198b116b2992debe37b4e86ea5e2447ce7d44818.tar.xz
drakx-198b116b2992debe37b4e86ea5e2447ce7d44818.zip
- introduce set_status(), restart_or_start() and service_exists()
- cleanups (use run_program success status)
Diffstat (limited to 'perl-install/services.pm')
-rw-r--r--perl-install/services.pm51
1 files changed, 33 insertions, 18 deletions
diff --git a/perl-install/services.pm b/perl-install/services.pm
index 9d356756d..35c0b88a6 100644
--- a/perl-install/services.pm
+++ b/perl-install/services.pm
@@ -320,49 +320,53 @@ sub services() {
# the following functions are mostly by printer related modules
+sub service_exists {
+ my ($service) = @_;
+ -x "$::prefix/etc/rc.d/init.d/$service";
+}
sub restart ($) {
my ($service) = @_;
# Exit silently if the service is not installed
- return 1 if !(-x "$::prefix/etc/rc.d/init.d/$service");
+ service_exists($service) or return 1;
run_program::rooted($::prefix, "/etc/rc.d/init.d/$service", "restart");
}
+sub restart_or_start ($) {
+ my ($service) = @_;
+ # Exit silently if the service is not installed
+ service_exists($service) or return 1;
+ is_service_running($service) ?
+ run_program::rooted($::prefix, "/etc/rc.d/init.d/$service", "restart") :
+ run_program::rooted($::prefix, "/etc/rc.d/init.d/$service", "start");
+}
+
sub start ($) {
my ($service) = @_;
# Exit silently if the service is not installed
- return 1 if !(-x "$::prefix/etc/rc.d/init.d/$service");
+ service_exists($service) or return 1;
run_program::rooted($::prefix, "/etc/rc.d/init.d/$service", "start");
- return (($? >> 8) != 0) ? 0 : 1;
}
sub start_not_running_service ($) {
my ($service) = @_;
# Exit silently if the service is not installed
- return 1 if !(-x "$::prefix/etc/rc.d/init.d/$service");
- run_program::rooted($::prefix, "/etc/rc.d/init.d/$service", "status");
- if (($? >> 8) != 0) {
- run_program::rooted($::prefix,
- "/etc/rc.d/init.d/$service", "start");
- }
- return (($? >> 8) != 0) ? 0 : 1;
+ service_exists($service) or return 1;
+ is_service_running($service) || run_program::rooted($::prefix, "/etc/rc.d/init.d/$service", "start");
}
sub stop ($) {
my ($service) = @_;
# Exit silently if the service is not installed
- return 1 if !(-x "$::prefix/etc/rc.d/init.d/$service");
+ service_exists($service) or return 1;
run_program::rooted($::prefix, "/etc/rc.d/init.d/$service", "stop");
- return (($? >> 8) != 0) ? 0 : 1;
}
sub is_service_running ($) {
my ($service) = @_;
# Exit silently if the service is not installed
- return 0 if !(-x "$::prefix/etc/rc.d/init.d/$service");
- run_program::rooted($::prefix, "/etc/rc.d/init.d/$service", "status");
- # The exit status is not zero when the service is not running
- return (($? >> 8) != 0) ? 0 : 1;
+ service_exists($service) or return 1;
+ run_program::rooted($::prefix, "/etc/rc.d/init.d/$service", '>', '/dev/null', '2>', '/dev/null', "status");
}
sub starts_on_boot {
@@ -373,12 +377,23 @@ sub starts_on_boot {
sub start_service_on_boot ($) {
my ($service) = @_;
- run_program::rooted($::prefix, "/sbin/chkconfig", "--add", $service) ? 1 : 0;
+ run_program::rooted($::prefix, "/sbin/chkconfig", "--add", $service);
}
sub do_not_start_service_on_boot ($) {
my ($service) = @_;
- run_program::rooted($::prefix, "/sbin/chkconfig", "--del", $service) ? 1 : 0;
+ run_program::rooted($::prefix, "/sbin/chkconfig", "--del", $service);
+}
+
+sub set_status {
+ my ($service, $enable, $o_dont_apply) = @_;
+ if ($enable) {
+ services::start_service_on_boot($service);
+ services::restart_or_start($service) unless $o_dont_apply;
+ } else {
+ services::do_not_start_service_on_boot($service);
+ services::stop($service) unless $o_dont_apply;
+ }
}
1;