Win32::Daemon::RegisterCallbacks( { start => \&startService, stop => \&stopService, pause => \&pauseService, continue => \&continueService, running => \&runService, } ); #### sub startService { # start the win32 service daemon # ------------------------------ my ($event, $context) = @_; $context -> { last_state } = SERVICE_RUNNING; Win32::Daemon::State( SERVICE_START_PENDING, 30000 ); # do what need to be done # exit Win32::Daemon::State( SERVICE_RUNNING ); } # ============================================================================== sub stopService { # stop the win32 service daemon # ----------------------------- my ($event, $context) = @_; $context -> { last_state } = SERVICE_STOPPED; Win32::Daemon::State( SERVICE_STOP_PENDING, 30000 ); # do what needs to be done # exit Win32::Daemon::State( SERVICE_STOPPED ); Win32::Daemon::StopService(); } # ============================================================================== sub pauseService { # let the win32 service daemon make a pause # ----------------------------------------- my ($event, $context) = @_; $context -> { last_state } = SERVICE_PAUSED; # do what needs to be done # exit Win32::Daemon::State( SERVICE_PAUSED ); } # ============================================================================== sub continueService { # let the win32 service daemon exit a pause # ----------------------------------------- my ($event, $context) = @_; $context -> { last_state } = SERVICE_RUNNING; # do what needs to be done # exit Win32::Daemon::State( SERVICE_RUNNING ); } # ============================================================================== sub runService { # this is the callback of by the win32 service daemon # --------------------------------------------------- my ($event, $context) = @_; if ( Win32::Daemon::State() == SERVICE_RUNNING ) { # count the number of calls (I do not know why) $context -> { count }++; } }