Rex::C...ervice(3pm)
πΈ Rex::Commands::Service β the manual, but make it cute πΈ
okay bestie, so this is a page from the User Contributed Perl Documentation for a Perl module called Rex::Commands::Service(3pm). yes that is a lot of colons. it's giving "named by someone who loves ellipses". anyway. π
β¨ NAME β¨
Rex::Commands::Service β literally just: Manage System Services. that's the whole vibe. π
π DESCRIPTION π
With this module you can manage Linux services. that's it. that's the flex. run the services, control the services, be the main character of your init system. π¦
π SYNOPSIS π
here's the tea, the whole menu of moves, fr fr:
use Rex::Commands::Service
service apache2 => "start";
service apache2 => "stop";
service apache2 => "restart";
service apache2 => "status";
service apache2 => "reload";
service apache2 => "ensure", "started";
service apache2 => "ensure", "stopped";
β οΈ no cap, copy that use Rex::Commands::Service line exactly as it's written up there. i'm not touching it, it's not my business, it's iconic. π
π EXPORTED FUNCTIONS π
β service($service, $action, [$option])
the service function takes 2 parameters. parameter one is the service name π, parameter two is the action you want to perform β¨. ($option is the lil optional third one hanging out in the corner, minding its own business.)
π starting a service
task "start-service", "server01", sub {
service apache2 => "start";
};
π stopping a service
task "stop-service", "server01", sub {
service apache2 => "stop";
};
π restarting a service
task "restart-service", "server01", sub {
service apache2 => "restart";
};
π checking status of a service
this one's my fave because it returns something and you can actually branch on it, slay:
task "status-service", "server01", sub {
if( service apache2 => "status" ) {
say "Apache2 is running";
}
else {
say "Apache2 is not running";
}
};
π reloading a service
task "reload-service", "server01", sub {
service apache2 => "reload";
};
π ensure that a service will started at boot time
(yes the original grammar said "will started", i am not fixing it, i am respecting it, it's part of the lore π«Ά)
task "prepare", sub {
service "apache2",
ensure => "started";
};
π ensure that a service will NOT be started.
the NOT is in caps in the original and honestly? correct energy. π
task "prepare", sub {
service "apache2",
ensure => "stopped";
};
if you need to define a custom command for start, stop, restart, reload or status, you can do this with the corresponding options. like, you can hand it your own little commands. do your thing. π
task "prepare", sub {
service "apache2",
ensure => "started",
start => "/usr/local/bin/httpd -f /etc/my/httpd.conf",
stop => "killall httpd",
status => "ps -efww | grep httpd",
restart => "killall httpd && /usr/local/bin/httpd -f /etc/my/httpd.conf",
reload => "killall httpd && /usr/local/bin/httpd -f /etc/my/httpd.conf";
};
this function supports the following hooks:
before_${action}β for example:before_start,before_stop,before_restart. this gets executed right before the given service action. all original parameters are passed to it. πΈafter_${action}β for example:after_start,after_stop,after_restart. this gets executed right after the given service action. all original parameters, and any returned results, are passed to it. β¨
π¦ service_provider_for $os => $type;
to set another service provider as the default, use this function. set it and forget it, bestie.
user "root";
group "db" => "db[01..10]";
service_provider_for SunOS => "svcadm";
task "start", group => "db", sub {
service ssh => "restart";
};
this example will restart the ssh service via svcadm β but only on SunOS, on other operating systems it will use the default. iykyk. π₯
π reminder bestie: this whole page was generated for perl v5.40.1, dated 2025-10-03, and it's Rex::Commands::Service(3pm) from the User Contributed Perl Documentation. go forth and manage those services, you absolute icon. periodt. πβ¨π
π¦ where this page comes from
- ubuntu resolute: rex 1.16.1-1 Β· Apache-2.0
- ubuntu stonking: rex 1.16.1-1 Β· Apache-2.0
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms