.\" -*- mode: troff; coding: utf-8 -*- .\" Automatically generated by Pod::Man 5.01 (Pod::Simple 3.43) .\" .\" Standard preamble: .\" ======================================================================== .de Sp \" Vertical space (when we can't use .PP) .if t .sp .5v .if n .sp .. .de Vb \" Begin verbatim text .ft CW .nf .ne \\$1 .. .de Ve \" End verbatim text .ft R .fi .. .\" \*(C` and \*(C' are quotes in nroff, nothing in troff, for use with C<>. .ie n \{\ . ds C` "" . ds C' "" 'br\} .el\{\ . ds C` . ds C' 'br\} .\" .\" Escape single quotes in literal strings from groff's Unicode transform. .ie \n(.g .ds Aq \(aq .el .ds Aq ' .\" .\" If the F register is >0, we'll generate index entries on stderr for .\" titles (.TH), headers (.SH), subsections (.SS), items (.Ip), and index .\" entries marked with X<> in POD. Of course, you'll have to process the .\" output yourself in some meaningful fashion. .\" .\" Avoid warning from groff about undefined register 'F'. .de IX .. .nr rF 0 .if \n(.g .if rF .nr rF 1 .if (\n(rF:(\n(.g==0)) \{\ . if \nF \{\ . de IX . tm Index:\\$1\t\\n%\t"\\$2" .. . if !\nF==2 \{\ . nr % 0 . nr F 2 . \} . \} .\} .rr rF .\" ======================================================================== .\" .IX Title "Control 3pm" .TH Control 3pm 2024-03-04 "perl v5.38.2" "User Contributed Perl Documentation" .\" For nroff, turn off justification. Always turn off hyphenation; it makes .\" way too many mistakes in technical documents. .if n .ad l .nh .SH NAME App::Control \- Perl module for apachectl style control of another script or executable .SH SYNOPSIS .IX Header "SYNOPSIS" .Vb 10 \& use App::Control; \& my $ctl = App::Control\->new( \& EXEC => $exec, \& ARGS => \e@args, \& PIDFILE => $pidfile, \& SLEEP => 1, \& VERBOSE => 1, \& ); \& my $pid = $ctl\->pid; \& if ( $ctl\->running ) \& { \& print "$pid is running\en"; \& } \& else \& { \& print "$pid is not running\en"; \& } \& # or alternatively ... \& print $ctl\->status; \& $ctl\->start; \& # or alternatively ... \& $ctl\->cmd( \*(Aqstart\*(Aq ); \& $ctl\->stop; \& $ctl\->hup; \& $ctl\->restart; .Ve .SH DESCRIPTION .IX Header "DESCRIPTION" App::Control is a simple module to replicate the kind of functionality you get with apachectl to control apache, but for any script or executable. There is a very simple OO interface, where the constructor is used to specify the executable, command line arguments, and pidfile, and various methods (start, stop, etc.) are used to control the executable in the obvious way. .PP The module is intended to be used in a simple wrapper control script. Currently the module does a fork and exec to start the executable, and sets the signal handler for SIGCHLD to 'IGNORE' to avoid zombie processes. .SH CONSTRUCTOR .IX Header "CONSTRUCTOR" The constructor is called with a hash of options in the standard way. The options are as follows: .SS EXEC .IX Subsection "EXEC" Path to the executable to be controlled. This option is REQUIRED. .SS ARGS .IX Subsection "ARGS" Command line arguments for the executable. This option is OPTIONAL, but if set, should be an ARRAY reference. .SS PIDFILE .IX Subsection "PIDFILE" Path to the pidfile for the executable. This need not exists, but the constructor will die if it thinks it can't create it. If the path where the pidfile lives doesn't exist the constructor will try to create it. This option is REQUIRED. .SS IGNOREFILE .IX Subsection "IGNOREFILE" The ignore file allows you to temporarily disable the control functionality. Suppose you have a chkdaemon / crontab entry that restarts a service; specifying an IGNOREFILE means that you can disable this wihtout having to edit the relevant config files. .SS CREATE_PIDFILE .IX Subsection "CREATE_PIDFILE" By default, App::Control depends on the application to manage the pid file. This is consistent will analogous utilities (apachectl, chkdaemon, etc.), but if you would like App::Control to create and remove pid files for you, then set this option to a true value. .SS SLEEP .IX Subsection "SLEEP" Number of seconds to sleep before checking that the process has been started. If the start fails, the control script will loop with a SLEEP delay per iteration until it has (see <"LOOP">). Default is 1 second. .PP head2 LOOP .PP Number of times to loop before giving up on starting the process. .SS VERBOSE .IX Subsection "VERBOSE" If set to a true value, the module will output verbose messages to STDERR. .SH METHODS .IX Header "METHODS" .SS start .IX Subsection "start" Start the executable specified in the constructor. This method waits until it is convinced that the executable has started. It then writes the new pid to the pidfile. .SS stop .IX Subsection "stop" Stop the executable specified in the constructor. It assumes that the pid listed in the pidfile specified in the constructor is the process to kill. This method waits until it is convinced that the executable has stopped. .SS hup .IX Subsection "hup" Send a SIGHUP to the executable. .SS restart .IX Subsection "restart" Basically; stop if running, and then start. .SS status .IX Subsection "status" Returns a status message along the lines of "$exec ($pid) is / is not running". .SS cmd .IX Subsection "cmd" All of the above methods can also be invoked using cmd; i.e.: .PP .Vb 1 \& $ctl\->start; .Ve .PP is equivilent to: .PP .Vb 1 \& $ctl\->cmd( \*(Aqstart\*(Aq ); .Ve .PP give or take a call to AUTOLOAD! .SS pid .IX Subsection "pid" Returns the current value of the pid in the pidfile. .SS running .IX Subsection "running" returns true if the pid in the pidfile is running. .SH AUTHOR .IX Header "AUTHOR" Ave Wrigley .SH COPYRIGHT .IX Header "COPYRIGHT" Copyright (c) 2001 Ave Wrigley. All rights reserved. This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.