package testPackage; sub new { my $that = shift; my $class = ref($that) || $that; my $self; $self->{DEBUG} = shift; bless $self, $class; return $self; } 1; ----------- use Win32::Daemon; use strict; use testPackage; my $LOGFILE = "test.log"; sub verbose { warn "TRACE ($$) : $_[0]"; } open (STDERR, ">$LOGFILE") || die "cannot open log file $LOGFILE\n"; Win32::Daemon::StartService(); my $prevState = SERVICE_STOPPED; while (SERVICE_STOPPED != ( my $State = Win32::Daemon::State() ) ) { if ( SERVICE_START_PENDING == $State ) { Win32::Daemon::State( SERVICE_RUNNING ); $prevState = SERVICE_RUNNING; verbose("$0 started at " . localtime().$/); } elsif ( SERVICE_PAUSE_PENDING == $State ) { verbose("Pausing Service\n"); Win32::Daemon::State( SERVICE_PAUSED ); $prevState = SERVICE_PAUSED; next; } elsif ( SERVICE_CONTINUE_PENDING == $State ) { verbose("Resuming Service\n"); Win32::Daemon::State( SERVICE_RUNNING ); $prevState = SERVICE_RUNNING; next; } elsif ( SERVICE_STOP_PENDING == $State ) { verbose("Service Stopping"); Win32::Daemon::State( SERVICE_STOPPED ); $prevState = SERVICE_STOPPED; next; } elsif ( SERVICE_RUNNING == $State ) { if ($DEBUG) { verbose("Service Running"); } if ( $DEBUG ) { verbose ("Waiting 100 seconds to continue\n"); } sleep(100); } else { # unknown state : reset to previous state Win32::Daemon::State( $prevState ); } sleep(1); } Win32::Daemon::StopService();