1Rex::Commands::Service(U3s)er Contributed Perl DocumentatRieoxn::Commands::Service(3)
2
3
4

NAME

6       Rex::Commands::Service - Manage System Services
7

DESCRIPTION

9       With this module you can manage Linux services.
10

SYNOPSIS

12        use Rex::Commands::Service
13
14        service apache2 => "start";
15
16        service apache2 => "stop";
17
18        service apache2 => "restart";
19
20        service apache2 => "status";
21
22        service apache2 => "reload";
23
24        service apache2 => "ensure", "started";
25
26        service apache2 => "ensure", "stopped";
27

EXPORTED FUNCTIONS

29   service($service, $action, [$option])
30       The service function accepts 2 parameters. The first is the service
31       name and the second the action you want to perform.
32
33       starting a service
34            task "start-service", "server01", sub {
35              service apache2 => "start";
36            };
37
38       stopping a service
39            task "stop-service", "server01", sub {
40              service apache2 => "stop";
41            };
42
43       restarting a service
44            task "restart-service", "server01", sub {
45              service apache2 => "restart";
46            };
47
48       checking status of a service
49            task "status-service", "server01", sub {
50              if( service apache2 => "status" ) {
51                say "Apache2 is running";
52              }
53              else {
54                say "Apache2 is not running";
55              }
56            };
57
58       reloading a service
59            task "reload-service", "server01", sub {
60              service apache2 => "reload";
61            };
62
63       ensure that a service will started at boot time
64            task "prepare", sub {
65              service "apache2",
66                ensure => "started";
67            };
68
69       ensure that a service will NOT be started.
70            task "prepare", sub {
71              service "apache2",
72                ensure => "stopped";
73            };
74
75           If you need to define a custom command for start, stop, restart,
76           reload or status you can do this with the corresponding options.
77
78            task "prepare", sub {
79              service "apache2",
80                ensure  => "started",
81                start   => "/usr/local/bin/httpd -f /etc/my/httpd.conf",
82                stop    => "killall httpd",
83                status  => "ps -efww | grep httpd",
84                restart => "killall httpd && /usr/local/bin/httpd -f /etc/my/httpd.conf",
85                reload  => "killall httpd && /usr/local/bin/httpd -f /etc/my/httpd.conf";
86            };
87
88           This function supports the following hooks:
89
90           before_${action}
91               For example: "before_start", "before_stop", "before_restart"
92
93               This gets executed right before the given service action. All
94               original parameters are passed to it.
95
96           after_${action}
97               For example: "after_start", "after_stop", "after_restart"
98
99               This gets executed right after the given service action. All
100               original parameters, and any returned results are passed to it.
101
102   service_provider_for $os => $type;
103       To set another service provider as the default, use this function.
104
105        user "root";
106
107        group "db" => "db[01..10]";
108        service_provider_for SunOS => "svcadm";
109
110        task "start", group => "db", sub {
111           service ssh => "restart";
112        };
113
114       This example will restart the ssh service via svcadm (but only on
115       SunOS, on other operating systems it will use the default).
116
117
118
119perl v5.34.0                      2021-07-21         Rex::Commands::Service(3)
Impressum