-
-
05 Jul 2021 21:04:56 UTC
- Distribution: Rex
- Module version: v1.13.4
- Source (raw)
- Browse (raw)
- Changes
- Homepage
- How to Contribute
- Repository
- Issues
- Testers (710 / 4 / 2)
- Kwalitee
Bus factor: 2- 49.25% Coverage
- License: apache_2_0
- Perl: v5.10.1
- Activity
24 month- Tools
- Download (342.78KB)
- MetaCPAN Explorer
- Permissions
- Subscribe to distribution
- Permalinks
- This version
- Latest version
and 118 contributors-
Jan Gehring
-
A Happy User
-
Alexander Romanenko
-
Alexandr Ciornii
-
Alex Mestiashvili
-
Ali Polatel
-
alx542
-
Anders Ossowicki
-
Andrej Zverev
-
Andrew Solomon
-
Andy Beverley
-
Arnold Bechtoldt
-
Boris Däppen
-
Brian Manning
-
Cameron Daniel
-
Chris Steigmeier
-
Christophe Wolfhugel
-
Crimson Thompson
-
Daniel Bäurer
-
Daniel Cesario
-
Daniel Dico
-
Denis Silakov
-
Dmitry Kopytov
-
Dominik Schulz
-
E. Choroba
-
Eduardo J
-
Eivin Giske Skaaren
-
elisdg
-
Elmer Quintanilla
-
Eric Johnson
-
Erik Huelsmann
-
Ferenc Erki
-
Franky Van Liedekerke
-
Fran Rodriguez
-
Gabor Szabo
-
Graham Todd
-
Harm Müller
-
Hayato Imai
-
Hiroaki Nakamura
-
Hiroki Matsuo
-
iblinder
-
Ilya Pavlov
-
James D Bearden
-
jdelgado7
-
Jean Charles Passard
-
Jean-Marie Renouard
-
Jeen Lee
-
Jens Berthold
-
Joachim Bargsten
-
John Karr
-
Jon Gentle
-
Joris DE POOTER
-
Jose Luis Martinez
-
Jose Luis Perez Diez
-
Kasim Tuman
-
Keedi Kim
-
Ken Crowell
-
Kent Fredric
-
Kirill Babikhin
-
labbeduddel
-
Leah Neukirchen
-
LeMerP
-
Mario Domgoergen
-
Max E. Aubrey
-
Mitch Broadhead
-
Nathan Abu
-
Naveed Massjouni
-
necrophcodr
-
Nicolas Leclercq
-
Nigel Gregoire
-
Nikolay A. Fetisov
-
Nils Domrose
-
okaoka
-
Oleg Hardt
-
Olivier Cherrier
-
Orange
-
Paco Esteban
-
Patrick Lauer
-
Pavel Timofeev
-
perlancar
-
Peter H. Ezetta
-
Peter Manthey
-
petersonchen
-
Pierrick DINTRAT
-
Piotr Karbowski
-
Prajithp
-
Randy Lauen
-
Renée Bäcker
-
Robert Abraham
-
Roy Storey
-
Samuele Tognini
-
Sascha Askani
-
Sascha Guenther
-
Simon Bertrang
-
Solène Rapenne
-
Stephane Benoit
-
Steve Dondley
-
Sven Dowideit
-
Tamas Molnar
-
Tianon Gravi
-
Tokuhiro Matsuno
-
Tomohiro Hosaka
-
Volker Kroll
-
Walery Wysotsky
-
Yanick Champoux
-
Yegor Korablev
-
Zane C. Bowers-Hadley
-
Сергей Романов
-
范野人
-
饶琛琳
-
Cuong Manh Le
-
David Golovan
-
Dominik Danter
-
Ilya Evseev
-
Niklas Larsson
-
Qiao Liu
-
Renato CRON
-
Peter Jankovics
- Dependencies
- AWS::Signature4
- Carp
- Cwd
- Data::Dumper
- Data::Validate::IP
- Devel::Caller
- Digest::HMAC_SHA1
- Digest::MD5
- English
- Exporter
- Fcntl
- File::Basename
- File::Spec
- File::Spec::Unix
- File::Spec::Win32
- FindBin
- HTTP::Request
- HTTP::Request::Common
- Hash::Merge
- IO::File
- IO::Select
- IO::Socket
- IO::String
- IPC::Open3
- JSON::MaybeXS
- LWP::UserAgent
- List::Util
- MIME::Base64
- Net::OpenSSH::ShellQuoter
- POSIX
- Scalar::Util
- Sort::Naturally
- Storable
- Symbol
- Term::ReadKey
- Test::Builder::Module
- Text::Glob
- Text::Wrap
- Time::HiRes
- UNIVERSAL
- URI
- URI::QueryParam
- XML::Simple
- YAML
- attributes
- base
- constant
- lib
- overload
- strict
- vars
- version
- warnings
- and possibly others
- Reverse dependencies
- CPAN Testers List
- Dependency graph
NAME
Rex::Commands::Service - Manage System Services
DESCRIPTION
With this module you can manage Linux services.
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 the action you want to perform.
- 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).
Module Install Instructions
To install Rex, copy and paste the appropriate command in to your terminal.
cpanm Rex
perl -MCPAN -e shell install Rex
For more information on module installation, please visit the detailed CPAN module installation guide.