You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
-["I need sudo to run commands"](#i-need-sudo-to-run-commands)
16
+
-[How do I start/stop/restart a unit?](#how-do-i-startstoprestart-a-unit)
17
+
-[Managing units](#managing-units)
18
+
-[Supported units](#supported-units)
19
+
-[Handling unit commands](#handling-unit-commands)
20
+
-[Install new units](#install-new-units)
21
+
-[UnitSection](#unitsection)
22
+
-[InstallSection](#installsection)
23
+
-[TypeSpecificSection](#typespecificsection)
24
+
-[How to Contribute](#how-to-contribute)
25
+
26
+
# Static Methods
27
+
### ::setBinary(string $binary)
28
+
Change the binary executable of `SystemCtl`
29
+
30
+
```php
31
+
SystemCtl::setBinary('/bin/systemctl');
32
+
```
33
+
34
+
### ::setTimeout(int $timeout)
35
+
Change the timeout for each command like `start()` on units and `SystemCtl`
36
+
37
+
```php
38
+
SystemCtl::setTimeout(3);
39
+
```
40
+
41
+
### ::setInstallPath(string $installPath)
42
+
Change the install path for new units
43
+
44
+
```php
45
+
SystemCtl::setInstallPath('/etc/systemd/system');
46
+
```
47
+
48
+
### ::setAssetPath(string $assetPath)
49
+
Change the asset path to look for unit file templates.
50
+
The `default` path is relative to the `SystemCtl` vendor package
51
+
52
+
```php
53
+
SystemCtl::setAssetPath('assets');
54
+
```
55
+
56
+
## "I need sudo to run commands"
57
+
If you need sudo, you should execute the bin executable with sudo.
58
+
The incode support was dropped due to security reason.
59
+
60
+
## How do I start/stop/restart a unit?
61
+
Simply is that. First we instantiate a `SystemCtl` instance an load a unit from a specific type.
62
+
Here we use a `Service`. You will always get back `true` if the command succeeded.
63
+
Otherwise the method will throw a `CommandFailedException`.
64
+
65
+
```php
66
+
$systemCtl = new SystemCtl();
67
+
68
+
// start/stop/enable/disable/reload/restart
69
+
$systemCtl->getService('nginx')->start();
70
+
$systemCtl->getService('nginx')->stop();
71
+
```
72
+
73
+
# Managing units
74
+
To manage any unit u want simply use the proper getter to receive an `Unit` object from `SystemCtl`
75
+
76
+
## Supported units
9
77
- service
10
78
- timer
11
79
12
-
> If you like to add support for more units, feel free to contribute.
80
+
> If you like to see more units feel free to contribute. Other units will be added in the future.
81
+
82
+
## Handling unit commands
83
+
Each unit comes with a range of methods you can invoke on them (like `start()`).
84
+
These methods will be dispatched to the `SystemCtl::$binary` you set before hand (or default).
13
85
14
-
## Current supported commands
86
+
Available unit commands are:
15
87
- start
16
88
- stop
17
89
- enable
@@ -21,35 +93,50 @@ PHP wrapper for systemctl (PHP7.1)
21
93
- isEnabled
22
94
- isActive
23
95
24
-
> If you like to add support for more commands, feel free to contribute.
96
+
# Install new units
25
97
26
-
## How to change the binary
98
+
> To see a full documentation on how unit files are structure see [Redhat Systemd Documentation](https://access.redhat.com/documentation/en-US/Red_Hat_Enterprise_Linux/7/html/System_Administrators_Guide/sect-Managing_Services_with_systemd-Unit_Files.html)
99
+
100
+
To install new units you will first need to create a specific `UnitTemplate` (like `ServiceUnitTemplate`).
101
+
After you have created a template with a `$name`. You need to define needed values inside the
102
+
`Sections` of a unit.
27
103
28
104
```php
29
-
SystemCtl::setBinary('/bin/systemctl');
105
+
$unitTemplate = new ServiceTemplate('myService');
30
106
```
31
107
32
-
## How to change command timeout
33
-
To change command tmeout simply call the static method `setTimeout`.
108
+
Each unit consists of three sections: The `UnitSection`, `InstallSection` and a `TypeSpecificSection`
109
+
110
+
## UnitSection
111
+
To change the values needed fore the `UnitSection` simple get the section from the template
112
+
and set needed values.
113
+
114
+
**Beware that only set values will be rendered into the template**
115
+
116
+
> For a full documentation on available methods see [UnitSection](src/Template/Section/UnitSection.php)
34
117
```php
35
-
SystemCtl::setTimeout(10);
118
+
$unitTemplate->getUnitSection()->setDescription('My test service');
36
119
```
37
120
38
-
> The default timeout is set to `3` seconds
121
+
## InstallSection
122
+
To change the value needed for the `InstallSection` get the section from the template and set
123
+
the needed values.
39
124
40
-
## "I need sudo to run commands"
41
-
If you need sudo, you should execute the bin executable with sudo.
42
-
The incode support was dropped due to security reason.
43
-
44
-
## How do I start/stop/restart a unit?
45
-
Simply is that. First we instantiate a `SystemCtl` instance an load a unit from a specific type. Here we use a `Service`. You will always get back `true` if the command succeeded. Otherwise the method will throw a `CommandFailedException`.
125
+
> For a full documentation on available methods see [InstallSection](src/Template/Section/InstallSection.php)
0 commit comments