Control(3pm)

πŸ“¦
version 1.07 Β· 3 versions
, in debian trixie, ubuntu noble, ubuntu resolute, ubuntu stonking

πŸ’– Control(3pm) πŸ’–

okay bestie, sit down, grab a strawberry πŸ“, because we're about to talk about App::Control β€” the Perl module that gives you apachectl energy for literally any script or executable. it's giving "I control the daemons" main character vibes and honestly? iconic.


✨ NAME ✨

App::Control β€” a Perl module for apachectl style control of another script or executable πŸŽ€


🌸 SYNOPSIS 🌸

use App::Control;
my $ctl = App::Control->new(
    EXEC => $exec,
    ARGS => \@args,
    PIDFILE => $pidfile,
    SLEEP => 1,
    VERBOSE => 1,
);
my $pid = $ctl->pid;
if ( $ctl->running )
{
    print "$pid is running\n";
}
else
{
    print "$pid is not running\n";
}
# or alternatively ...
print $ctl->status;
$ctl->start;
# or alternatively ...
$ctl->cmd( 'start' );
$ctl->stop;
$ctl->hup;
$ctl->restart;

like look at her. she's so clean. πŸ’…


πŸ¦‹ DESCRIPTION πŸ¦‹

App::Control is a simple module that replicates the kind of functionality you get with apachectl to control apache β€” but for any script or executable. no cap.

there's a very simple OO interface, okay? the constructor is where you specify the executable, the command line arguments, and the pidfile. then you just call various methods (start, stop, etc.) and they control the executable in the obvious way. that's it. that's the whole vibe. ✨

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. πŸ§Ÿβ™€οΈβœ‹ not today, zombies.


πŸ’œ CONSTRUCTOR πŸ’œ

the constructor is called with a hash of options in the standard way, bestie. the options are as follows:

EXEC

path to the executable to be controlled. this option is REQUIRED. no EXEC, no service. periodt.

ARGS

command line arguments for the executable. this option is OPTIONAL, but if you set it, it should be an ARRAY reference. don't be weird about it. πŸ™ˆ

PIDFILE

path to the pidfile for the executable. this need not exist, 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.

IGNOREFILE

the ignore file lets you temporarily disable the control functionality. like imagine you've got a chkdaemon / crontab entry that restarts a service β€” specifying an IGNOREFILE means you can disable this without having to go edit the relevant config files. lazy girlie solution, we love her 🫢

CREATE_PIDFILE

by default, App::Control depends on the application to manage the pid file. this is consistent with 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. self-care tbh πŸ’–

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.

LOOP

number of times to loop before giving up on starting the process. (yes bestie, the original really does render this one as a literal head2 LOOP in the pod β€” we're keeping the section, the typo is not our problem 😭)

VERBOSE

if set to a true value, the module will output verbose messages to STDERR. it will not shut up. it will tell you everything. πŸ’€


🌈 METHODS 🌈

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.

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.

hup

send a SIGHUP to the executable. just a little nudge. a lil hey-girl πŸ‘‹

restart

basically; stop if running, and then start. the classic. πŸ”₯

status

returns a status message along the lines of "$exec ($pid) is / is not running".

cmd

all of the above methods can also be invoked using cmd; i.e.:

$ctl->start;

is equivilent to:

$ctl->cmd( 'start' );

give or take a call to AUTOLOAD! ✨ (and yes, "equivilent" is spelled exactly like that, we don't fix the source material around here, we respect it πŸŽ€)

pid

returns the current value of the pid in the pidfile.

running

returns true if the pid in the pidfile is running.


πŸ‘‘ AUTHOR πŸ‘‘

Ave Wrigley <ave.wrigley@gmail.com> πŸ’–


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.


and that's the whole page bestie!! 🌸 this one shipped as perl v5.38.2, dated 2024-03-04 β€” so if you're reading this, go forth and control your daemons responsibly, slay, and remember: SIGCHLD set to 'IGNORE', zombies stay in their graves πŸ’…βœ¨πŸ¦‹
πŸ“¦ where this page comes from