Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
PerlMonks  

Re: Executing script in normal/daemon mode and adding start/stop capability

by almut (Canon)
on Oct 07, 2009 at 12:35 UTC ( #799705=note: print w/replies, xml ) Need Help??


in reply to Executing script in normal/daemon mode and adding start/stop capability

* How can I add start/stop commands for the script.

One way to do it would be to add the respective options to your script (as you're already using Getopt::Long, this should be rather straightforward).  The implementation would typically involve a pid-file to store the PID which you need to communicate with a potentially running instance of the script. Something like:

  • start

    • Check if there's a pid-file.
    • If so, read the PID from the file, and send that PID signal number zero to check if it's still alive.
    • If it is alive, output "... already running", and quit.
    • In case no running instance is found, start the daemon the same way you would do from the command line. When successful, create a pid-file containing the PID of the process.

  • stop

    • Check if there's a pid-file.
    • If there is no pid-file, output "... doesn't seem to be running", and quit.
    • Otherwise, read the PID from the file, and send that PID the TERM signal (or whatever signal makes your script quit gracefully).
    • Delete the pid-file. (In case you're paranoid, you might want to wait a while and then check whether the TERM signal did actually terminate the process, before deleting the pid-file. If not, output an error message.)

  • Comment on Re: Executing script in normal/daemon mode and adding start/stop capability

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://799705]
help
Chatterbox?
[1nickt]: Corion HPs? ugh. I was impressed with Lenovo's gaming laptops; if it weren't for the red backlighting and general flashiness of the aesthetic, I might have gone with that. But all that was until I discovered that the Dell Precision line is still around.
[1nickt]: stevieb I don;t doubt that there's a difference. BestBuy has "consumer" models only on display.
[ambrus]: 1nickt: for some reason, these days they call every computer "gaming", even ones that gamers wouldn't buy. I've bought a keyboard that was labelled "gamer", despite that it has hard springs and seems to be way better for typing than for gaming;
[1nickt]: I though the gamers like that because they bash the keys so hard.
[ambrus]: and I've seen motherboards with no fast expansion ports for a video card but built-in hardware RAID advertized as "gaming".
LanX has a shaming laptop

How do I use this? | Other CB clients
Other Users?
Others rifling through the Monastery: (14)
As of 2017-03-27 13:39 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Should Pluto Get Its Planethood Back?



    Results (320 votes). Check out past polls.