1Rex::Commands::Service(U3s)er Contributed Perl DocumentatRieoxn::Commands::Service(3)
2
3
4
6 Rex::Commands::Service - Manage System Services
7
9 With this module you can manage Linux services.
10
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
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 service action.
94
95 after_action
96 For example: after_start, after_stop, after_restart
97
98 This gets executed right after the service action.
99
100 service_provider_for $os => $type;
101 To set another service provider as the default, use this function.
102
103 user "root";
104
105 group "db" => "db[01..10]";
106 service_provider_for SunOS => "svcadm";
107
108 task "start", group => "db", sub {
109 service ssh => "restart";
110 };
111
112 This example will restart the ssh service via svcadm (but only on
113 SunOS, on other operating systems it will use the default).
114
115
116
117perl v5.28.1 2017-03-01 Rex::Commands::Service(3)