* 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.)
-
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.
|