Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
* 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.)


In reply to Re: Executing script in normal/daemon mode and adding start/stop capability by almut
in thread Executing script in normal/daemon mode and adding start/stop capability by chanakya

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others browsing the Monastery: (7)
As of 2024-04-23 11:03 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found