Robo System Service Tasks
, (*1)
Collection of tasks for interacting with system service managers., (*2)
Requirements
-
Robo ~0.5 (0.5.0 or higher)
Installation
Add the falc/robo-system-service
package to your composer.json
:, (*3)
composer require falc/robo-system-service
Add the Falc\Robo\Service\loadTasks
trait to your RoboFile
:, (*4)
class RoboFile extends \Robo\Tasks
{
use Falc\Robo\Service\loadTasks;
// ...
}
Tasks
Start
Starting a service:, (*5)
``` php
$this->taskServiceStart()
->serviceManager('systemd')
->service('service1')
->run();, (*6)
Compact form:
$this->taskServiceStart('systemd', 'service1')->run();, (*7)
You can combine it with `taskSshExec()` to start services in a remote server:
```php
$startTask = $this->taskServiceStart()
->serviceManager('systemd')
->service('service1');
$this->taskSshExec('remote.example.com')
->remoteDir('/home/user')
->printed(false) // Do not display output
->exec($startTask)
->run();
Stop
Stopping a service:, (*8)
``` php
$this->taskServiceStop()
->serviceManager('systemd')
->service('service1')
->run();, (*9)
Compact form:
$this->taskServiceStop('systemd', 'service1')->run();, (*10)
You can combine it with `taskSshExec()` to stop services in a remote server:
```php
$stopTask = $this->taskServiceStop()
->serviceManager('systemd')
->service('service1');
$this->taskSshExec('remote.example.com')
->remoteDir('/home/user')
->printed(false) // Do not display output
->exec($stopTask)
->run();
Restart
Restarting a service:, (*11)
``` php
$this->taskServiceRestart()
->serviceManager('systemd')
->service('service1')
->run();, (*12)
Compact form:
$this->taskServiceRestart('systemd', 'service1')->run();, (*13)
You can combine it with `taskSshExec()` to restart services in a remote server:
```php
$restartTask = $this->taskServiceRestart()
->serviceManager('systemd')
->service('service1');
$this->taskSshExec('remote.example.com')
->remoteDir('/home/user')
->printed(false) // Do not display output
->exec($restartTask)
->run();
Reload
Reloading a service:, (*14)
``` php
$this->taskServiceReload()
->serviceManager('systemd')
->service('service1')
->run();, (*15)
Compact form:
$this->taskServiceReload('systemd', 'service1')->run();, (*16)
You can combine it with `taskSshExec()` to reload services in a remote server:
```php
$reloadTask = $this->taskServiceReload()
->serviceManager('systemd')
->service('service1');
$this->taskSshExec('remote.example.com')
->remoteDir('/home/user')
->printed(false) // Do not display output
->exec($reloadTask)
->run();
Enable
Enabling a service:, (*17)
``` php
$this->taskServiceEnable()
->serviceManager('systemd')
->service('service1')
->run();, (*18)
Compact form:
$this->taskServiceEnable('systemd', 'service1')->run();, (*19)
You can combine it with `taskSshExec()` to enable services in a remote server:
```php
$enableTask = $this->taskServiceEnable()
->serviceManager('systemd')
->service('service1');
$this->taskSshExec('remote.example.com')
->remoteDir('/home/user')
->printed(false) // Do not display output
->exec($enableTask)
->run();
Disable
Disabling a service:, (*20)
``` php
$this->taskServiceDisable()
->serviceManager('systemd')
->service('service1')
->run();, (*21)
Compact form:
$this->taskServiceDisable('systemd', 'service1')->run();, (*22)
You can combine it with `taskSshExec()` to disable services in a remote server:
```php
$disableTask = $this->taskServiceDisable()
->serviceManager('systemd')
->service('service1');
$this->taskSshExec('remote.example.com')
->remoteDir('/home/user')
->printed(false) // Do not display output
->exec($disableTask)
->run();
Daemon reload
This task is supported only for systemd., (*23)
``` php
$this->taskServiceDaemonReload()
->serviceManager('systemd')
->run();, (*24)
Compact form:
$this->taskServiceDaemonReload('systemd')->run();, (*25)
You can combine it with `taskSshExec()` to reload systemd manager configuration in a remote server:
```php
$daemonReloadTask = $this->taskServiceDaemonReload()
->serviceManager('systemd');
$this->taskSshExec('remote.example.com')
->remoteDir('/home/user')
->printed(false) // Do not display output
->exec($daemonReloadTask)
->run();
Methods
All the tasks implement these methods:
* serviceManager($serviceManager)
: Sets the service manager to use.
* service()
: Sets the service to manage.
* verbose()
: Enables the verbose mode., (*26)
Service managers
Every task requires to set a service manager either in the constructor or using the serviceManager($serviceManager)
method., (*27)
At the moment these are the supported service managers:
* systemd
* SysVinit, (*28)