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