in reply to perlsvc or firedaemon?

I wrote some code 6 years ago, to get around this issue, when they started charging money for Firedaemon.

I posted the code here last year.

Update:I have noticed that Win32::Daemon appears not to be available for current perl versions.

For this app, since performance for this code is not an issue, you can use the external "sc" (Service Controller) command.

Here is the (untested) revised sub, that allows you to comment-out use Win32::Daemon:

sub MakeService{ my $ServiceName = shift or die "Service Name Not Specified\n"; my $ServiceDir = shift; my $ServiceCommandLine = shift; my %ServiceStatus; # See if registered in SERVICES if (Win32::Service::GetStatus("", $ServiceName, \%ServiceStatus)){ # Service Already Exists .. complain warn "**Service $ServiceName is Already defined as a SERVICE and +". $ServiceStatusCode{$ServiceStatus{CurrentState}} . "; Please Remove this service before adding**\n"; return 1; } #It may be in REGISTRY, but not registered as a service - check if (exists $Registry->{"LMachine/System/CurrentControlSet/Services/$ +ServiceName/"}) { warn "**Service $ServiceName is Already defined in Registry ". "; Please Remove this service before adding**\n"; return 1; } my %ServiceInfo = ( machine => '', name => "MRTG$ServiceName", display => "MRTG $ServiceName", path => '', user => '', pwd => '', description => "$ServiceName MRTG Service", parameters =>"%SystemRoot%\\system32\\srvany.exe", ); # if( Win32::Daemon::CreateService( \%ServiceInfo ) ) # { # print "Successfully added Service $ServiceInfo{name}.\n"; # } # else # { # print "Failed to add service $ServiceInfo{name}: " . Win32::F +ormatMessage( Win32::Daemon::GetLastError() ) . "\n"; # return 1; # } print "\t:$_" for qx|sc create $ServiceInfo{name} binpath=$ServiceIn +fo{parameters} DisplayName="$ServiceInfo{description}"|; $Registry->{"LMachine/System/CurrentControlSet/Services/$ServiceName/ +Parameters"}= { "/Application" => [$ServiceCommandLine ,"REG_SZ"], "/AppDirectory" => [$ServiceDir ,"REG_SZ"], } or die "Can not create services Parameter entry\n"; ## Need to actually START the new service ... print "Service $ServiceName Created. (Will AutoStart on reboot)\n"; print "To start it NOW, use the command:\n NET START MRTG$ServiceNa +me\n"; } ################################# sub DeleteThisService{ my $ServiceName = shift or die "No service specified to DELETE\n"; my $rslt = qx|sc delete $ServiceName|; #Win32::Daemon::DeleteService('', $ServiceName ); print "Service $ServiceName DELETED = $rslt ***\n"; }

     ..to maintain is to slowly feel your soul, sanity and sentience ebb away as you become one with the Evil.

Replies are listed 'Best First'.
Re^2: perlsvc or firedaemon?
by Anonymous Monk on Feb 18, 2009 at 09:14 UTC
Re^2: perlsvc or firedaemon?
by smanicka (Scribe) on Feb 18, 2009 at 16:59 UTC
    Here's the issue.The network people in the company say they would prefer if i could bundle perl and the reqd modules into an exe or something and then manke it a service so that they don't have to instal perl if and ever the server breaks.Would this make any difference in the choice?

    BTW ,1) I am real stupid and 2) I don't have much time to figure stuff out, since i have to get this into production on saturday.

    So If anyone could provide a step by step tutorial as to how to create a service i would like to learn.I see your code, but could you explain what each bit does, where my code could potentially go in this big bit of code and how would i be able to do graceful shutdown?
      From women's eyes this doctrine I derive: They sparkle still the right Promethean fire; They are the books, the arts, the academes, That show, contain, and nourish all the world.
      -- From| Love's Labour's Lost

      In other words - Sorry - I have neither the time, patience or motivation to educate.

           ..to maintain is to slowly feel your soul, sanity and sentience ebb away as you become one with the Evil.