# -*- perl -*-
#
# $Revision: 1.2 $
package lpd;

require Exporter;
@ISA = qw(Exporter);
@EXPORT_OK = qw(&print_usage &print_version &service_test);
use lib $main::runtimedir;
use csl_utils qw($TIMEOUT %ERRORS);
use strict;

use Socket;

sub print_usage ();
sub print_version ();
sub service_test (%);

sub print_usage () {

    print "
Usage:  Check lpd service.
Options:
    [--verbose]
    --help
    --version
    --usage
";
    return $ERRORS{'OK'};
}

sub print_version () {
    my $version = '$Revision: 1.2 $';
    $version =~ s/^\$Revision: //;
    $version =~ s/ \$\s*$//;

    print "lpd.pm - $version\n";
    return $ERRORS{'OK'};
}

sub service_test (%) {
    my %options = @_;

    if ($options{"verbose"}) {
        foreach my $opt (sort keys(%options)) {
            if ($options{$opt}) {
                print "$opt - $options{$opt}\n";
            }
        }
    }

    my $pscmd = "/bin/ps aux";
    my $mesg = "";

    print "looking for lpd process running.\n" if ($options{"verbose"});
    	my $procs = `$pscmd`;
    	fail("lpd not running!  Please restart lp service!  $mesg") unless ($procs =~ /lpd\sWaiting/);

    print "OK: $mesg\n";
    exit $ERRORS{OK};
}

sub fail {
    my $text = shift;
    print "CRITICAL: $text\n";
    exit $ERRORS{CRITICAL};
}

