From 046406ab6b13659f4be843d3d2d5639efaf425fe Mon Sep 17 00:00:00 2001 From: Thierry Vignaud Date: Tue, 12 Nov 2002 12:05:40 +0000 Subject: printer related modules cleaning : - create the printer/ hierarchy - split services related stuff into services.pm & printer::services, - move things that've nothing to do with printers into common.pm (alternatives, permissions, ...) - move eveything related to cups, gimp-print, detection, {star,open}office to the corresponding splited printer:: module - big consolidation of printer::office (it was obvious there were tons of duplication between staroffice and openoffice managment) - move other stuff into printer::main, printer::common, status : print.pm has been heavily splited (now one can begin to understand the little bits). printerdrake still needs to be splited/cleaned and eventually removed since printer/printerdrake modules separation is not understandable by other people till, in printer::gimp, $lprcommand is neither declared nor setted nowhere. idem in mdk9.0 ... --- perl-install/printer/services.pm | 61 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 61 insertions(+) create mode 100644 perl-install/printer/services.pm (limited to 'perl-install/printer/services.pm') diff --git a/perl-install/printer/services.pm b/perl-install/printer/services.pm new file mode 100644 index 000000000..1b68da96a --- /dev/null +++ b/perl-install/printer/services.pm @@ -0,0 +1,61 @@ +package printer::services; + +use strict; +use services; +use run_program; + +sub restart ($) { + my ($service) = @_; + if (services::restart($service)) { + # CUPS needs some time to come up. + wait_for_cups() if $service eq "cups"; + return 1; + } else { return 0 } +} + +sub start ($) { + my ($service) = @_; + if (services::start($service)) { + # CUPS needs some time to come up. + wait_for_cups() if $service eq "cups"; + return 1; + } else { return 0 } +} + +sub start_not_running_service ($) { + my ($service) = @_; + # The exit status is not zero when the service is not running + if (services::start_not_running_service($service)) { + return 0; + } else { + run_program::rooted($::prefix, "/etc/rc.d/init.d/$service", "start"); + if (($? >> 8) != 0) { + return 0; + } else { + # CUPS needs some time to come up. + wait_for_cups() if $service eq "cups"; + return 1; + } + } +} + +sub wait_for_cups { + # CUPS needs some time to come up. Wait up to 30 seconds, checking + # whether CUPS is ready. + my $cupsready = 0; + my $i; + for ($i = 0; $i < 30; $i++) { + run_program::rooted($::prefix, "/usr/bin/lpstat", "-r"); + if (($? >> 8) != 0) { + # CUPS is not ready, continue + sleep 1; + } else { + # CUPS is ready, quit + $cupsready = 1; + last; + } + } + return $cupsready; +} + +1; -- cgit v1.2.1