1
1
# Systemd.js
2
2
3
+ ![ Publish] ( https://github.com/systemd-js/systemd/actions/workflows/publish.yaml/badge.svg )
4
+
3
5
Collection of packages useful when interfacing with systemd.
4
6
5
7
## @systemd-js/conf
@@ -19,7 +21,8 @@ yarn add @systemd-js/conf
19
21
20
22
Parse systemd ini file into object.
21
23
22
- Note: Ini parser is not fully implemented, lacks support for escaping and quoting.
24
+ Note: Ini parser is not fully implemented, lacks support for escaping and
25
+ quoting.
23
26
24
27
``` ts
25
28
import {INI } from " @systemd-js/conf" ;
@@ -64,7 +67,6 @@ const ini = INI.fromString(unit).toObject();
64
67
User : " root" ,
65
68
},
66
69
};
67
-
68
70
```
69
71
70
72
Create service unit for ini string and modify service user definition.
@@ -88,46 +90,46 @@ PrivateTmp=yes
88
90
User=root
89
91
` ;
90
92
91
- const ini = INI .fromString (unit )
92
- const service = Service .fromINI (ini )
93
+ const ini = INI .fromString (unit );
94
+ const service = Service .fromINI (ini );
93
95
94
96
service
95
97
.getServiceSection ()
96
- .setUser (" test" )
98
+ .setUser (" test" );
97
99
98
100
service .toINIString ();
99
101
```
100
102
101
103
Create service unit using fluent builder
102
104
103
105
``` ts
104
- import {Service } from " @systemd-js/config" ;
106
+ import { Service } from " @systemd-js/config" ;
105
107
106
108
const service = new Service ();
107
109
108
110
service
109
111
.getUnitSection ()
110
- .setDescription (" This is a example unit" )
112
+ .setDescription (" This is a example unit" );
111
113
112
114
service
113
115
.getInstallSection ()
114
- .setWantedBy (" multi-user.target" )
115
-
116
+ .setWantedBy (" multi-user.target" );
117
+
116
118
service
117
- .getServiceSection ()
118
- .setType (" simple" )
119
- .setWorkingDirectory (" /tmp" )
120
- .setRestart (" always" )
121
- .setExecStartPre (" /usr/bin/echo 'Before'" )
122
- .setExecStart (" /usr/bin/echo 'Hello World'" )
123
- .setExecStartPost (" /usr/bin/echo 'After'" )
119
+ .getServiceSection ()
120
+ .setType (" simple" )
121
+ .setWorkingDirectory (" /tmp" )
122
+ .setRestart (" always" )
123
+ .setExecStartPre (" /usr/bin/echo 'Before'" )
124
+ .setExecStart (" /usr/bin/echo 'Hello World'" )
125
+ .setExecStartPost (" /usr/bin/echo 'After'" );
124
126
```
125
127
126
128
Create timer unit using fluent builder
127
129
128
130
``` ts
129
- import {Timer } from " @systemd-js/config" ;
130
- const timer = new Timer ()
131
+ import { Timer } from " @systemd-js/config" ;
132
+ const timer = new Timer ();
131
133
132
134
timer
133
135
.getUnitSection ()
@@ -136,7 +138,7 @@ timer
136
138
137
139
timer
138
140
.getInstallSection ()
139
- .setWantedBy (" multi-user.target" );
141
+ .setWantedBy (" multi-user.target" );
140
142
141
143
timer
142
144
.getTimerSection ()
@@ -146,8 +148,8 @@ timer
146
148
147
149
## @systemd-js/ctl
148
150
149
- Control over units. Interface to systemctl.
150
- At the moment this lack proper error handling.
151
+ Control over units. Interface to systemctl. At the moment this lack proper error
152
+ handling.
151
153
152
154
### Installation
153
155
@@ -160,57 +162,54 @@ yarn add @systemd-js/ctl
160
162
State manipulation of existing service.
161
163
162
164
``` ts
163
- import {Ctl } from " @systemd-js/ctl" ;
164
-
165
- const ctl = new Ctl (" test.service" )
165
+ import { Ctl } from " @systemd-js/ctl" ;
166
166
167
- ctl .disable ()
168
- ctl .enable ()
169
- ctl .stop ()
170
- ctl .start ()
171
- ctl .restart ()
167
+ const ctl = new Ctl (" test.service" );
172
168
169
+ ctl .disable ();
170
+ ctl .enable ();
171
+ ctl .stop ();
172
+ ctl .start ();
173
+ ctl .restart ();
173
174
```
174
175
175
176
Creation of new service "example.service"
176
177
177
178
``` ts
178
- import {Service } from " @systemd-js/config" ;
179
- import {Ctl } from " @systemd-js/ctl" ;
179
+ import { Service } from " @systemd-js/config" ;
180
+ import { Ctl } from " @systemd-js/ctl" ;
180
181
181
182
const service = new Service ();
182
183
183
184
service
184
185
.getUnitSection ()
185
- .setDescription (" This is a example unit" )
186
+ .setDescription (" This is a example unit" );
186
187
187
188
service
188
189
.getInstallSection ()
189
- .setWantedBy (" multi-user.target" )
190
-
191
- service
192
- .getServiceSection ()
193
- .setType (" simple" )
194
- .setExecStart (" /usr/bin/echo 'Hello World'" )
190
+ .setWantedBy (" multi-user.target" );
195
191
196
- const ctl = new Ctl (" example" , service )
192
+ service
193
+ .getServiceSection ()
194
+ .setType (" simple" )
195
+ .setExecStart (" /usr/bin/echo 'Hello World'" );
197
196
198
- ctl .create ()
199
- ctl .enable ()
200
- ctl .start ()
197
+ const ctl = new Ctl (" example" , service );
201
198
199
+ ctl .create ();
200
+ ctl .enable ();
201
+ ctl .start ();
202
202
```
203
203
204
204
In addition to ` Ctl ` class, package expose functions to call systemctl directly.
205
205
206
206
``` ts
207
- import {restart , start , stop } from " @systemd-js/ctl" ;
208
-
209
- stop (" example.service" )
210
- start (" example.service" )
211
- enable (" example.service" )
212
- disable (" example.service" )
213
- reload (" example.service" )
214
- restart (" example.service" )
215
-
207
+ import { restart , start , stop } from " @systemd-js/ctl" ;
208
+
209
+ stop (" example.service" );
210
+ start (" example.service" );
211
+ enable (" example.service" );
212
+ disable (" example.service" );
213
+ reload (" example.service" );
214
+ restart (" example.service" );
216
215
```
0 commit comments