Rex::Co...Service(3)
πΈ NAME πΈ
okay bestie, welcome to Rex::Co...Service(3) β the User Contributed Perl Documentation page for Rex::Commands::Service, aka Manage System Services β¨. This is your little group chat for wrangling Linux services.
π DESCRIPTION π
With this module you can manage Linux services. That's the whole vibe. π«Ά
β¨ SYNOPSIS β¨
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";
π EXPORTED FUNCTIONS π
π service($service, $action, [$option]) π
The service function accepts 2 parameters. The first is the service name, and the second is the action you want to perform. (The signature also shows [$option], bestie β no cap, it's right there.) π
π 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
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
task "prepare", sub {
service "apache2",
ensure => "started";
};
π ensure that a service will NOT be started.
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. π οΈ
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.
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). π₯
and that's the whole page, bestie π«Ά. tiny sign-off: this came from perl v5.42.3, dated 2023-08-05, with the footer name Rex::Co...Service(3). periodt π
π¦ where this page comes from
- nixos 26.05: perl5.42.3-Rex 1.14.3
- nixpkgs unstable: perl5.42.3-Rex 1.14.3
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms