@@ -6,15 +6,13 @@ With jsctl you can generate and manage service files like the following:
6
6
7
7
```
8
8
[Unit]
9
- Description=Your description
10
- Wants=network-online.target
9
+ Description=example-app
11
10
12
11
[Service]
13
12
ExecStart=/path/to/node /path/to/project/index.js
14
13
WorkingDirectory=/path/to/project/
15
14
User=nobody
16
15
Restart=always
17
- RestartSec=0
18
16
StandardOutput=syslog+console
19
17
StandardError=syslog+console
20
18
Environment=NODE_ENV=production NODE_PORT=3000
@@ -23,6 +21,11 @@ Environment=NODE_ENV=production NODE_PORT=3000
23
21
WantedBy=multi-user.target
24
22
```
25
23
24
+ ## Defaults
25
+
26
+ jsctl can use the name and main entries in your package.json and looks for your local Node.js installation.
27
+ By default the resulting service will automatically restart your application on failure and has NODE_ENV=production set as an environment variable. Of course these defaults can be overridden.
28
+
26
29
## Installation
27
30
``` bash
28
31
$ yarn global add jsctl
@@ -35,97 +38,225 @@ $ npm i -g jsctl
35
38
36
39
``` bash
37
40
$ cd path/to/example-app
38
- $ sudo jsctl generate -user $USER -env ' NODE_ENV=production NODE_PORT=3000'
39
- /etc/systemd/system/ example-app.jsctl.service created
41
+ $ sudo jsctl add -u $USER -e ' NODE_ENV=production NODE_PORT=3000'
42
+ created example-app
40
43
$ jsctl status
41
44
● example-app.jsctl.service - example-app
42
45
Loaded: loaded (/etc/systemd/system/example-app.jsctl.service; disabled; vendor preset: enabled)
43
46
Active: inactive (dead)
44
47
$ sudo jsctl start
48
+ $ sudo jsctl enable
45
49
Created symlink from /etc/systemd/system/multi-user.target.wants/example-app.jsctl.service to /etc/systemd/system/example-app.jsctl.service.
46
50
$ cd /some/random/path
47
51
$ jsctl list
48
52
example-app
49
- $ sudo jsctl stop -n example-app
50
- Removed symlink /etc/systemd/system/multi-user.target.wants/example-app.jsctl.service.
51
- ```
53
+ $ jsctl cat example-app
54
+ # /etc/systemd/system/example-app.jsctl.service
55
+ [Unit]
56
+ ; After=
57
+ ; AllowIsolate=
58
+ ; Before=
59
+ ; BindsTo=
60
+ ; Conflicts=
61
+ DefaultDependencies=true
62
+ ; Description=
63
+ ; Documentation=
64
+ ; IgnoreOnIsolate=
65
+ ; JobTimeoutAction=
66
+ ; JobTimeoutRebootArgument=
67
+ JobTimeoutSec=infinity
68
+ ; JoinsNamespaceOf=
69
+ ; OnFailure=
70
+ OnFailureJobMode=replace
71
+ ; PartOf=
72
+ ; PropagatesReloadFrom=
73
+ ; PropagatesReloadTo=
74
+ ; RebootArgument=
75
+ ; RefuseManualStart=
76
+ ; RefuseManualStop=
77
+ ; Requires=
78
+ ; RequiresMountsFor=
79
+ ; Requisite=
80
+ StartLimitAction=none
81
+ ; StartLimitBurst=
82
+ ; StartLimitIntervalSec=
83
+ ; StopWhenUnneeded=
84
+ ; Wants=
85
+
86
+ [Service]
87
+ ; BusName=
88
+ Environment=NODE_ENV=production NODE_PORT=3000
89
+ ; ExecReload=
90
+ ExecStart=/usr/local/bin/node /home/user/path/to/example-app/index.js
91
+ ; ExecStartPre=
92
+ ; ExecStartPost=
93
+ ; ExecStop=
94
+ ; ExecStopPost=
95
+ ; FailureAction=
96
+ ; FileDescriptorStoreMax=
97
+ GuessMainPID=yes
98
+ ; NonBlocking=
99
+ ; NotifyAccess=
100
+ ; PermissionsStartOnly=
101
+ ; PIDFile=
102
+ ; RemainAfterExit=
103
+ Restart=always
104
+ ; RestartForceExitStatus=
105
+ ; RestartPreventExitStatus=
106
+ RestartSec=100ms
107
+ ; RootDirectoryStartOnly=
108
+ ; RuntimeMaxSec=
109
+ ; Sockets=
110
+ StandardOutput=syslog
111
+ StandardError=syslog
112
+ ; SuccessExitStatus=
113
+ TimeoutStartSec=90s
114
+ TimeoutStopSec=90s
115
+ Type=simple
116
+ ; USBFunctionDescriptors=
117
+ ; USBFunctionStrings=
118
+ User=user
119
+ ; WatchdogSec=
120
+ WorkingDirectory=/home/user/path/to/example-app
121
+
122
+ [Install]
123
+ ; Alias=
124
+ ; Also=
125
+ ; DefaultInstance=
126
+ ; RequiredBy=
127
+ WantedBy=multi-user.target
52
128
53
- ``` bash
54
129
$ jsctl --help
55
- Usage: jsctl < command> [options]
130
+ Usage: jsctl < command> [name] [ options]
56
131
57
132
Commands:
133
+ add Generate a service file
134
+ list List services
135
+ remove Remove a service file
58
136
cat Display a service file
59
137
daemon-reload Reload the daemon
60
138
disable Disable a service
61
139
enable Enable a service
62
- generate Generate a service file
63
140
is-active See if active
64
141
is-enabled See if enabled
65
142
is-failed See if failed
66
- list List services
67
143
list-dependencies List service dependencies
68
144
reload Reload a service
69
145
reload-or-restart Reload or restart service
70
- remove Remove a service file
71
146
restart Restart a service
72
147
show Show service properties
73
148
start Start a service
74
149
status See the status of a service
75
150
stop Stop a service
76
151
77
152
Options:
78
- --custom Custom [Service] options, e.g. --custom
79
- ' SuccessExitStatus=1\nType=simple' [default: " " ]
80
- -d, --directory Path to project folder with package.json (default:
81
- process.cwd ()) [default: " /current/working/directory" ]
82
- -e, --env Evironment [default: " NODE_ENV=production" ]
83
- -n, --name Name of a generated service
84
- --nodepath Path to node binary (default: process.argv[0])
85
- [default: " /usr/local/bin/node" ]
86
- -s, --scriptpath Path to your JavaScript file (default: main entry in
87
- package.json)
88
- --stdout StandardOut
153
+ --help, -h Show help [boolean]
154
+ --version, -v Show version number [boolean]
155
+ --after After
156
+ --alias Alias
157
+ --allowisolate AllowIsolate
158
+ --also Also
159
+ --before Before
160
+ --bindsto BindsTo
161
+ --busname BusName
162
+ --conflicts Conflicts
163
+ --defaultdependencies DefaultDependencies [default: true]
164
+ --defaultinstance DefaultInstance
165
+ --description Description
166
+ --documentation Documentation
167
+ --environment, -e Environment [default: " NODE_ENV=production" ]
168
+ --execreload ExecReload
169
+ --execstart, -s [default: /path/to/node
170
+ /path/to/package/json/main/script.js]
171
+ --execstartpost ExecStartPost
172
+ --execstartpre ExecStartPre
173
+ --execstop ExecStop
174
+ --execstoppost ExecStopPost
175
+ --failureaction FailureAction
176
+ --filedescriptorstoremax FileDescriptorStoreMax
177
+ --guessmainpid GuessMainPID [default: " yes" ]
178
+ --ignoreonisolate IgnoreOnIsolate
179
+ --jobtimeoutaction JobTimeoutAction
180
+ --jobtimeoutrebootargument JobTimeoutRebootArgument
181
+ --jobtimeoutsec JobTimeoutSec [default: " infinity" ]
182
+ --joinsnamespaceof JoinsNamespaceOf
183
+ --nonblocking NonBlocking
184
+ --notifyaccess NotifyAccess
185
+ --onfailure OnFailure
186
+ --onfailurejobmode OnFailureJobMode
187
+ [choices: " fail" , " replace" , " replace-irreversibly" , " isolate" , " flush" ,
188
+ " ignore-dependencies" , " ignore-requirements" ] [default: " replace" ]
189
+ --pidfile PIDFile
190
+ --partof PartOf
191
+ --permissionsstartonly PermissionsStartOnly
192
+ --propagatesreloadfrom PropagatesReloadFrom
193
+ --propagatesreloadto PropagatesReloadTo
194
+ --rebootargument RebootArgument
195
+ --refusemanualstart RefuseManualStart
196
+ --refusemanualstop RefuseManualStop
197
+ --remainafterexit RemainAfterExit
198
+ --requiredby RequiredBy
199
+ --requires Requires
200
+ --requiresmountsfor RequiresMountsFor
201
+ --requisite Requisite
202
+ --restart Restart
203
+ [choices: " always" , " no" , " on-success" , " on-failure" , " on-abnormal" ,
204
+ " on-abort" , " on-watchdog" ] [default: " always" ]
205
+ --restartforceexitstatus RestartForceExitStatus
206
+ --restartpreventexitstatus RestartPreventExitStatus
207
+ --restartsec RestartSec [default: " 100ms" ]
208
+ --rootdirectorystartonly RootDirectoryStartOnly
209
+ --runtimemaxsec RuntimeMaxSec
210
+ --sockets Sockets
211
+ --standarderror StandardError
89
212
[choices: " inherit" , " null" , " tty" , " journal" , " syslog" , " kmsg" ,
90
213
" journal+console" , " syslog+console" , " kmsg+console" , " socket" ] [default:
91
214
" syslog" ]
92
- --stderr StandardError
215
+ --standardoutput StandardOutput
93
216
[choices: " inherit" , " null" , " tty" , " journal" , " syslog" , " kmsg" ,
94
217
" journal+console" , " syslog+console" , " kmsg+console" , " socket" ] [default:
95
218
" syslog" ]
96
- -t, --timeout Timeout in seconds before process restarts [default: 0]
97
- -u, --user User who runs the process [default: " root" ]
98
- --wants [choices: see: systemctl list-units --type target --all]
99
- [default: " network-online.target" ]
100
- -h, --help Show help [boolean]
101
- --restart [choices: " no" , " always" , " on-success" , " on-failure" , " on-abnormal" ,
102
- " on-abort" , " on-watchdog" ] [default: " always" ]
103
- --wantedby [choices: " multi-user.target" , " graphical.target" , " rescue.target" ,
219
+ --startlimitaction StartLimitAction
220
+ [choices: " none" , " poweroff" , " poweroff-force" , " poweroff-immediate" ,
221
+ " reboot" , " reboot-force" , " reboot-immediate" ] [default: " none" ]
222
+ --startlimitburst StartLimitBurst
223
+ --startlimitintervalsec StartLimitIntervalSec
224
+ --stopwhenunneeded StopWhenUnneeded
225
+ --successexitstatus SuccessExitStatus
226
+ --timeoutstartsec TimeoutStartSec [default: " 90s" ]
227
+ --timeoutstopsec TimeoutStopSec [default: " 90s" ]
228
+ --type Type
229
+ [choices: " dbus" , " forking" , " idle" , " notify" , " oneshot" , " simple" ] [default:
230
+ " simple" ]
231
+ --usbfunctiondescriptors USBFunctionDescriptors
232
+ --usbfunctionstrings USBFunctionStrings
233
+ --user, -u User [default: " root" ]
234
+ --wantedby WantedBy
235
+ [choices: " multi-user.target" , " graphical.target" , " rescue.target" ,
104
236
" reboot.target" , " poweroff.target" ] [default: " multi-user.target" ]
237
+ --wants Wants
238
+ --watchdogsec WatchdogSec
239
+ --workingdirectory /current/working/directory
240
+ --assertions comma seperated list of assertions
241
+ --conditions comma seperated list of conditions
105
242
106
243
Examples:
107
- GENERATE
244
+ ADD
108
245
109
246
From your projects root directory:
110
- sudo jsctl generate
111
-
112
- By telling jsctl where to find your pacakge.json:
113
- sudo jsctl generate -d /path/to/project
114
-
115
- Br by providing name and scriptpath arguments:
116
- sudo jsctl generate -n example-app -s /path/to/script.js
247
+ sudo jsctl add
248
+ sudo jsctl add -u $USER -e ' NODE_ENV=development NODE_PORT=3000'
117
249
118
- A more customized example:
119
- sudo jsctl generate -u $USER -e ' NODE_ENV=development NODE_PORT=3000'
120
- --stdout journal+console
250
+ By providing a name and --execstart:
251
+ sudo jsctl add example-app -s ' /usr/local/bin/node /path/to/script.js'
121
252
122
253
GENERAL
123
254
124
255
If you want to manage a service and you are not in its projects root folder,
125
- you have to provide the name:
256
+ you have to provide its name:
126
257
127
- sudo jsctl stop -n example-app
128
- jsctl cat -n example-app
258
+ sudo jsctl stop example-app
259
+ jsctl cat example-app
129
260
` ` `
130
261
131
262
Local installation example:
@@ -139,13 +270,13 @@ $ npm i --save-dev jsctl
139
270
` ` ` js
140
271
// package.json
141
272
{
142
- " name" : " example-app" , // required
143
- " main" : " path/to/script.js" , // required
273
+ " name" : " example-app" ,
274
+ " main" : " path/to/script.js" ,
144
275
" scripts" : {
145
- " generate " : " sudo ./node_modules/.bin/jsctl generate -u $USER " ,
146
- " start" : " sudo ./node_modules/.bin/jsctl start" ,
147
- " status" : " jsctl status" ,
148
- " stop" : " sudo ./node_modules/.bin/jsctl stop"
276
+ " service:add " : " sudo ./node_modules/.bin/jsctl add -u $USER " ,
277
+ " service: start" : " sudo ./node_modules/.bin/jsctl start" ,
278
+ " service: status" : " jsctl status" ,
279
+ " service: stop" : " sudo ./node_modules/.bin/jsctl stop"
149
280
}
150
281
}
151
282
` ` `
0 commit comments