.\" Automatically generated by Pod::Man 4.14 (Pod::Simple 3.40) .\" .\" Standard preamble: .\" ======================================================================== .de Sp \" Vertical space (when we can't use .PP) .if t .sp .5v .if n .sp .. .de Vb \" Begin verbatim text .ft CW .nf .ne \\$1 .. .de Ve \" End verbatim text .ft R .fi .. .\" Set up some character translations and predefined strings. \*(-- will .\" give an unbreakable dash, \*(PI will give pi, \*(L" will give a left .\" double quote, and \*(R" will give a right double quote. \*(C+ will .\" give a nicer C++. Capital omega is used to do unbreakable dashes and .\" therefore won't be available. \*(C` and \*(C' expand to `' in nroff, .\" nothing in troff, for use with C<>. .tr \(*W- .ds C+ C\v'-.1v'\h'-1p'\s-2+\h'-1p'+\s0\v'.1v'\h'-1p' .ie n \{\ . ds -- \(*W- . ds PI pi . if (\n(.H=4u)&(1m=24u) .ds -- \(*W\h'-12u'\(*W\h'-12u'-\" diablo 10 pitch . if (\n(.H=4u)&(1m=20u) .ds -- \(*W\h'-12u'\(*W\h'-8u'-\" diablo 12 pitch . ds L" "" . ds R" "" . ds C` "" . ds C' "" 'br\} .el\{\ . ds -- \|\(em\| . ds PI \(*p . ds L" `` . ds R" '' . ds C` . ds C' 'br\} .\" .\" Escape single quotes in literal strings from groff's Unicode transform. .ie \n(.g .ds Aq \(aq .el .ds Aq ' .\" .\" If the F register is >0, we'll generate index entries on stderr for .\" titles (.TH), headers (.SH), subsections (.SS), items (.Ip), and index .\" entries marked with X<> in POD. Of course, you'll have to process the .\" output yourself in some meaningful fashion. .\" .\" Avoid warning from groff about undefined register 'F'. .de IX .. .nr rF 0 .if \n(.g .if rF .nr rF 1 .if (\n(rF:(\n(.g==0)) \{\ . if \nF \{\ . de IX . tm Index:\\$1\t\\n%\t"\\$2" .. . if !\nF==2 \{\ . nr % 0 . nr F 2 . \} . \} .\} .rr rF .\" ======================================================================== .\" .IX Title "Rex::Commands::Service 3pm" .TH Rex::Commands::Service 3pm "2021-03-05" "perl v5.32.1" "User Contributed Perl Documentation" .\" For nroff, turn off justification. Always turn off hyphenation; it makes .\" way too many mistakes in technical documents. .if n .ad l .nh .SH "NAME" Rex::Commands::Service \- Manage System Services .SH "DESCRIPTION" .IX Header "DESCRIPTION" With this module you can manage Linux services. .SH "SYNOPSIS" .IX Header "SYNOPSIS" .Vb 1 \& 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"; .Ve .SH "EXPORTED FUNCTIONS" .IX Header "EXPORTED FUNCTIONS" .ie n .SS "service($service, $action, [$option])" .el .SS "service($service, \f(CW$action\fP, [$option])" .IX Subsection "service($service, $action, [$option])" The service function accepts 2 parameters. The first is the service name and the second the action you want to perform. .IP "starting a service" 4 .IX Item "starting a service" .Vb 3 \& task "start\-service", "server01", sub { \& service apache2 => "start"; \& }; .Ve .IP "stopping a service" 4 .IX Item "stopping a service" .Vb 3 \& task "stop\-service", "server01", sub { \& service apache2 => "stop"; \& }; .Ve .IP "restarting a service" 4 .IX Item "restarting a service" .Vb 3 \& task "restart\-service", "server01", sub { \& service apache2 => "restart"; \& }; .Ve .IP "checking status of a service" 4 .IX Item "checking status of a service" .Vb 8 \& task "status\-service", "server01", sub { \& if( service apache2 => "status" ) { \& say "Apache2 is running"; \& } \& else { \& say "Apache2 is not running"; \& } \& }; .Ve .IP "reloading a service" 4 .IX Item "reloading a service" .Vb 3 \& task "reload\-service", "server01", sub { \& service apache2 => "reload"; \& }; .Ve .IP "ensure that a service will started at boot time" 4 .IX Item "ensure that a service will started at boot time" .Vb 4 \& task "prepare", sub { \& service "apache2", \& ensure => "started"; \& }; .Ve .IP "ensure that a service will \s-1NOT\s0 be started." 4 .IX Item "ensure that a service will NOT be started." .Vb 4 \& task "prepare", sub { \& service "apache2", \& ensure => "stopped"; \& }; .Ve .Sp If you need to define a custom command for start, stop, restart, reload or status you can do this with the corresponding options. .Sp .Vb 9 \& 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"; \& }; .Ve .Sp This function supports the following hooks: .RS 4 .IP "before_${action}" 4 .IX Item "before_${action}" For example: \f(CW\*(C`before_start\*(C'\fR, \f(CW\*(C`before_stop\*(C'\fR, \f(CW\*(C`before_restart\*(C'\fR .Sp This gets executed right before the given service action. All original parameters are passed to it. .IP "after_${action}" 4 .IX Item "after_${action}" For example: \f(CW\*(C`after_start\*(C'\fR, \f(CW\*(C`after_stop\*(C'\fR, \f(CW\*(C`after_restart\*(C'\fR .Sp This gets executed right after the given service action. All original parameters, and any returned results are passed to it. .RE .RS 4 .RE .ie n .SS "service_provider_for $os => $type;" .el .SS "service_provider_for \f(CW$os\fP => \f(CW$type\fP;" .IX Subsection "service_provider_for $os => $type;" To set another service provider as the default, use this function. .PP .Vb 1 \& user "root"; \& \& group "db" => "db[01..10]"; \& service_provider_for SunOS => "svcadm"; \& \& task "start", group => "db", sub { \& service ssh => "restart"; \& }; .Ve .PP This example will restart the \fIssh\fR service via svcadm (but only on SunOS, on other operating systems it will use the default).