Skip to content

Commit 10f2f9d

Browse files
committed
Initial commit
0 parents  commit 10f2f9d

File tree

4 files changed

+79
-0
lines changed

4 files changed

+79
-0
lines changed

LICENSE.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
Copyright (c) 2014, Wes Todd <[email protected]>
2+
3+
Permission to use, copy, modify, and/or distribute this software for any purpose with or without fee is hereby granted, provided that the above copyright notice and this permission notice appear in all copies.
4+
5+
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.

README.md

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
# Init.d wrapper for Node.js
2+
3+
```
4+
$ npm install initd
5+
```
6+
7+
A nod wrapper for running init.d scripts in debian systems. The supported actions are:
8+
9+
- `start`
10+
- `start`
11+
- `restart`
12+
- `reload`
13+
- `status`
14+
15+
The all take a single argument, the service, and return the child process. Here is an example of restarting a service:
16+
17+
```javascript
18+
var initd = require('initd');
19+
initd.restart('nginx').on('close', function(code) {
20+
if (code !== 0) return console.error('Nginx faild to restart');
21+
console.log('Nginx restarted!!');
22+
});
23+
```
24+
25+
See `man service` for more info about supported commands and options.
26+
27+
## Spawn Options
28+
29+
You can also overide the default behavior of inheriting the stdio for your child processes with the `initd.spawnOptions` object.

index.js

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
var spawn = require('child_process').spawn,
2+
path = require('path'),
3+
initd = module.exports = {};
4+
5+
// The init script path
6+
initd.path = path.join('/', 'etc', 'init.d');
7+
8+
initd.spawnOptions = {
9+
stdio: 'inherit'
10+
};
11+
12+
// Commands
13+
[
14+
'start',
15+
'stop',
16+
'restart',
17+
'status',
18+
'reload'
19+
].forEach(function(command) {
20+
initd[command] = function(service) {
21+
return spawn(path.join(initd.path, service), [command], initd.spawnOptions);
22+
};
23+
});
24+

package.json

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
{
2+
"name": "initd",
3+
"version": "0.1.0",
4+
"description": "Run init scripts on Debian systems",
5+
"main": "index.js",
6+
"scripts": {
7+
"test": "echo \"Error: no test specified\" && exit 1"
8+
},
9+
"keywords": [
10+
"init.d",
11+
"debian",
12+
"ubuntu",
13+
"service"
14+
],
15+
"repository": {
16+
"type": "git",
17+
"url": "[email protected]:Node-Ops/initd.git"
18+
},
19+
"author": "Wes Todd",
20+
"license": "ISC"
21+
}

0 commit comments

Comments
 (0)