pixl-boot 2.0.0 → 2.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +17 -39
- package/boot.js +21 -15
- package/cli.js +0 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# Overview
|
|
2
2
|
|
|
3
|
-
`pixl-boot` will automatically register a startup service for your module on Linux and
|
|
3
|
+
`pixl-boot` will automatically register a startup service for your module on Linux and macOS, so your daemon will be started on a server reboot. It is configured entirely out of your [package.json](https://docs.npmjs.com/files/package.json) file, and will handle all the details of registering a [systemd service](https://en.wikipedia.org/wiki/Systemd) on Linux, or a [LaunchAgent/LaunchDaemon](https://developer.apple.com/library/content/documentation/MacOSX/Conceptual/BPSystemStartup/Chapters/CreatingLaunchdJobs.html) on macOS.
|
|
4
4
|
|
|
5
5
|
This is only designed for packages that are installed as the root user.
|
|
6
6
|
|
|
@@ -22,18 +22,7 @@ Once you have your control script ready, link to it in the `bin` property in you
|
|
|
22
22
|
"bin": "bin/control.sh",
|
|
23
23
|
```
|
|
24
24
|
|
|
25
|
-
Finally, you need to have npm run `pixl-boot` on install and uninstall of your package, so that it has a chance to register and unregister your startup service. Do this by adding `
|
|
26
|
-
|
|
27
|
-
```js
|
|
28
|
-
"scripts": {
|
|
29
|
-
"postinstall": "pixl-boot install",
|
|
30
|
-
"preuninstall": "pixl-boot uninstall"
|
|
31
|
-
}
|
|
32
|
-
```
|
|
33
|
-
|
|
34
|
-
That's it!
|
|
35
|
-
|
|
36
|
-
Alternatively, if you would rather the startup service not be installed automatically, and instead require additional user commands, change the `scripts` property names to something custom, like `boot` and `unboot`:
|
|
25
|
+
Finally, you need to have npm run `pixl-boot` on install and uninstall of your package, so that it has a chance to register and unregister your startup service. Do this by adding `boot` and `unboot` properties in the `scripts` section of your `package.json` file:
|
|
37
26
|
|
|
38
27
|
```js
|
|
39
28
|
"scripts": {
|
|
@@ -42,9 +31,9 @@ Alternatively, if you would rather the startup service not be installed automati
|
|
|
42
31
|
}
|
|
43
32
|
```
|
|
44
33
|
|
|
45
|
-
Then your users
|
|
34
|
+
Then your users need to be instructed to type:
|
|
46
35
|
|
|
47
|
-
```
|
|
36
|
+
```sh
|
|
48
37
|
npm run boot
|
|
49
38
|
npm run unboot
|
|
50
39
|
```
|
|
@@ -61,8 +50,8 @@ Add `--name` if you want to customize the startup service name. This defaults t
|
|
|
61
50
|
|
|
62
51
|
```js
|
|
63
52
|
"scripts": {
|
|
64
|
-
"
|
|
65
|
-
"
|
|
53
|
+
"boot": "pixl-boot install --name mycustomservice",
|
|
54
|
+
"unboot": "pixl-boot uninstall --name mycustomservice"
|
|
66
55
|
}
|
|
67
56
|
```
|
|
68
57
|
|
|
@@ -72,8 +61,8 @@ Add `--company` if you want to customize the "company" (organization) name that
|
|
|
72
61
|
|
|
73
62
|
```js
|
|
74
63
|
"scripts": {
|
|
75
|
-
"
|
|
76
|
-
"
|
|
64
|
+
"boot": "pixl-boot install --company MyCompany",
|
|
65
|
+
"unboot": "pixl-boot uninstall --company MyCompany"
|
|
77
66
|
}
|
|
78
67
|
```
|
|
79
68
|
|
|
@@ -83,7 +72,7 @@ Add `--script` to specify a custom location of your shell control script, relati
|
|
|
83
72
|
|
|
84
73
|
```js
|
|
85
74
|
"scripts": {
|
|
86
|
-
"
|
|
75
|
+
"boot": "pixl-boot install --script bin/my-control-script.sh"
|
|
87
76
|
}
|
|
88
77
|
```
|
|
89
78
|
|
|
@@ -93,7 +82,7 @@ Add `--linux_type` if you want to customize the Linux systemd service type. It
|
|
|
93
82
|
|
|
94
83
|
```js
|
|
95
84
|
"scripts": {
|
|
96
|
-
"
|
|
85
|
+
"boot": "pixl-boot install --linux_type forking"
|
|
97
86
|
}
|
|
98
87
|
```
|
|
99
88
|
|
|
@@ -103,7 +92,7 @@ Add `--linux_after` if you want to specify a service that we must start *after*.
|
|
|
103
92
|
|
|
104
93
|
```js
|
|
105
94
|
"scripts": {
|
|
106
|
-
"
|
|
95
|
+
"boot": "pixl-boot install --linux_after network.target"
|
|
107
96
|
}
|
|
108
97
|
```
|
|
109
98
|
|
|
@@ -113,17 +102,7 @@ Add `--linux_wanted_by` if you want to customize the `WantedBy` property in the
|
|
|
113
102
|
|
|
114
103
|
```js
|
|
115
104
|
"scripts": {
|
|
116
|
-
"
|
|
117
|
-
}
|
|
118
|
-
```
|
|
119
|
-
|
|
120
|
-
### darwin_type
|
|
121
|
-
|
|
122
|
-
Add `--darwin_type` to customize the type of startup service you want on Darwin (OS X) systems. Darwin supports two different types of startup services, [LaunchAgents and LaunchDaemons](https://developer.apple.com/library/content/documentation/MacOSX/Conceptual/BPSystemStartup/Chapters/CreatingLaunchdJobs.html). In short, a `LaunchAgent` only starts up when a user log in, while a `LaunchDaemon` starts up earlier, before any user logs in. The default type is `LaunchAgent`, but beware of changing this to `LaunchDaemon`, because this may start your service before things like network are available. You only need to add this to the `pixl-boot install` command. Example:
|
|
123
|
-
|
|
124
|
-
```js
|
|
125
|
-
"scripts": {
|
|
126
|
-
"postinstall": "pixl-boot install --darwin_type LaunchAgent"
|
|
105
|
+
"boot": "pixl-boot install --linux_wanted_by multi-user.target"
|
|
127
106
|
}
|
|
128
107
|
```
|
|
129
108
|
|
|
@@ -158,15 +137,14 @@ require('fs').writeFileSync( "logs/pid.txt", process.pid );
|
|
|
158
137
|
In addition to the command-line interface for `pixl-boot` there is also a JavaScript API you can use in your Node.js code, to install and/or uninstall startup services. To use this, first call `require('pixl-boot)` to load the module, and the returned object exposes `install()` and `uninstall()` functions. Both functions accept an options object, and a callback. The options object accepts all the named command-line arguments, sans the hyphens. Example use:
|
|
159
138
|
|
|
160
139
|
```js
|
|
161
|
-
|
|
162
|
-
|
|
140
|
+
const boot = require('pixl-boot');
|
|
141
|
+
let opts = {
|
|
163
142
|
name: "MyService",
|
|
164
143
|
company: "Node",
|
|
165
144
|
script: "bin/control.sh",
|
|
166
145
|
linux_type: "forking",
|
|
167
146
|
linux_after: "network.target",
|
|
168
|
-
linux_wanted_by: "multi-user.target"
|
|
169
|
-
darwin_type: "agent"
|
|
147
|
+
linux_wanted_by: "multi-user.target"
|
|
170
148
|
};
|
|
171
149
|
|
|
172
150
|
// install startup service
|
|
@@ -182,9 +160,9 @@ boot.uninstall(opts, function(err) {
|
|
|
182
160
|
|
|
183
161
|
# Licenses
|
|
184
162
|
|
|
185
|
-
The MIT License
|
|
163
|
+
**The MIT License**
|
|
186
164
|
|
|
187
|
-
Copyright (c) 2016 -
|
|
165
|
+
Copyright (c) 2016 - 2026 Joseph Huckaby.
|
|
188
166
|
|
|
189
167
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
190
168
|
of this software and associated documentation files (the "Software"), to deal
|
package/boot.js
CHANGED
|
@@ -24,10 +24,7 @@ module.exports = {
|
|
|
24
24
|
redhat_start_priority: "99",
|
|
25
25
|
redhat_stop_priority: "01",
|
|
26
26
|
debian_requires: "local_fs remote_fs network syslog named",
|
|
27
|
-
debian_stoplevels: "0,1,6"
|
|
28
|
-
|
|
29
|
-
// mac stuff
|
|
30
|
-
darwin_type: "agent"
|
|
27
|
+
debian_stoplevels: "0,1,6"
|
|
31
28
|
},
|
|
32
29
|
|
|
33
30
|
install: function(args, callback) {
|
|
@@ -107,6 +104,7 @@ module.exports = {
|
|
|
107
104
|
"Type=" + service_type,
|
|
108
105
|
"ExecStart=" + args.script + " start",
|
|
109
106
|
"ExecStop=" + args.script + " stop",
|
|
107
|
+
"KillMode=none",
|
|
110
108
|
"",
|
|
111
109
|
"[Install]",
|
|
112
110
|
"WantedBy=" + wanted_by
|
|
@@ -208,7 +206,15 @@ module.exports = {
|
|
|
208
206
|
// install service as Darwin (OS X) agent or daemon
|
|
209
207
|
args.service_name = args.name.toLowerCase().replace(/\W+/g, '');
|
|
210
208
|
args.company_name = args.company.toLowerCase().replace(/\W+/g, '');
|
|
211
|
-
|
|
209
|
+
|
|
210
|
+
if (process.getuid() == 0) {
|
|
211
|
+
// we're root, so install a LaunchDaemon
|
|
212
|
+
args.plist_file = "/Library/LaunchDaemons/com." + args.company_name + "." + args.service_name + ".plist";
|
|
213
|
+
}
|
|
214
|
+
else {
|
|
215
|
+
// we're a standard user, so install a user-level LaunchAgent
|
|
216
|
+
args.plist_file = process.env.HOME + "/Library/LaunchAgents/com." + args.company_name + "." + args.service_name + ".plist";
|
|
217
|
+
}
|
|
212
218
|
|
|
213
219
|
var plist_contents = [
|
|
214
220
|
'<?xml version="1.0" encoding="UTF-8"?>',
|
|
@@ -233,14 +239,7 @@ module.exports = {
|
|
|
233
239
|
// write plist config file
|
|
234
240
|
fs.writeFile( args.plist_file, plist_contents, { mode: '644' }, function(err) {
|
|
235
241
|
if (err) return callback( new Error("Failed to write file: " + args.plist_file + ": " + err.message) );
|
|
236
|
-
|
|
237
|
-
// must be root/wheel
|
|
238
|
-
cp.exec( "chown root:wheel " + args.plist_file, function(err) {
|
|
239
|
-
if (err) return callback( new Error("Failed to chmod plist file: " + args.plist_file + ": " + err.message) );
|
|
240
|
-
|
|
241
|
-
// success
|
|
242
|
-
callback();
|
|
243
|
-
});
|
|
242
|
+
callback();
|
|
244
243
|
});
|
|
245
244
|
},
|
|
246
245
|
|
|
@@ -276,14 +275,21 @@ module.exports = {
|
|
|
276
275
|
}
|
|
277
276
|
|
|
278
277
|
// looks like we have a systemd service
|
|
279
|
-
cp.exec( "systemctl disable " + args.service_name + ".service", function() {
|
|
278
|
+
cp.exec( "systemctl disable " + args.service_name + ".service && systemctl daemon-reload", function() {
|
|
280
279
|
fs.unlink( args.service_file, callback );
|
|
281
280
|
} );
|
|
282
281
|
}); // fs.access
|
|
283
282
|
}
|
|
284
283
|
else {
|
|
285
284
|
// non-linux (darwin)
|
|
286
|
-
|
|
285
|
+
if (process.getuid() == 0) {
|
|
286
|
+
// we're root, so uninstall the LaunchDaemon
|
|
287
|
+
args.plist_file = "/Library/LaunchDaemons/com." + args.company_name + "." + args.service_name + ".plist";
|
|
288
|
+
}
|
|
289
|
+
else {
|
|
290
|
+
// we're a standard user, so uninstall the user-level LaunchAgent
|
|
291
|
+
args.plist_file = process.env.HOME + "/Library/LaunchAgents/com." + args.company_name + "." + args.service_name + ".plist";
|
|
292
|
+
}
|
|
287
293
|
|
|
288
294
|
fs.unlink( args.plist_file, callback );
|
|
289
295
|
}
|
package/cli.js
CHANGED
|
File without changes
|
package/package.json
CHANGED