| 1 | END {Log("ERROR: $@") if $@} | ||
| 2 | use strict; | ||
| 3 | use File::Spec; | ||
| 4 | use Win32::Daemon; | ||
| 5 | use Win32::Daemon::Simple | ||
| 6 | Service => 'TestSimpleService', | ||
| 7 | Name => 'Test Simple Service', | ||
| 8 | Version => '2.0', | ||
| 9 | Info => { | ||
| 10 | display => 'Test Simple Service', | ||
| 11 | description => 'Test Service for Win32::Daemon::Simple', | ||
| 12 | user => '', | ||
| 13 | pwd => '', | ||
| 14 | interactive => 0, | ||
| 15 | }, | ||
| 16 | Params => { | ||
| 17 | Tick => 0, | ||
| 18 | Talkative => 0, | ||
| 19 | Interval => 1, | ||
| 20 | LogFile => "TestSimple.log", | ||
| 21 | Description => <<'*END*', | ||
| 22 | Tick : (0/1) controls whether the service writes a "tick" message to | ||
| 23 | the log once a minute if there's nothing to do | ||
| 24 | Talkative : (0/1) controls the amount of logging information | ||
| 25 | Interval : how often does the service look for new or modified files | ||
| 26 | (in minutes) | ||
| 27 | *END* | ||
| 28 | }, | ||
| 29 | param_modify => { | ||
| 30 | LogFile => sub {File::Spec->rel2abs($_[0])}, | ||
| 31 | tAlkative => sub {undef}, | ||
| 32 | }; | ||
| 33 | |||
| 34 | LogNT("Running as ".SERVICEID); | ||
| 35 | ServiceLoop(\&doSomething); | ||
| 36 | Log("Going down"); | ||
| 37 | exit; | ||
| 38 | |||
| 39 | sub doSomething { | ||
| 40 | Log("Doing something"); | ||
| 41 | sleep(5 + rand(5)); # process your task | ||
| 42 | Log("Done something"); | ||
| 43 | } | ||
| 44 | |||
| 45 | __END__ |