Skip to content

Add systemctl mask/unmask #4

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 8 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
# systemctl
# systemctl-cmd

This simple node module allows you to control system services using the systemctl command easily and asynchronously.

This is a fork of VolantisDev's systemctl, because he isn't accepting pull requests.

## Requirements

- Archlinux or another OS which uses the systemctl command
Expand All @@ -13,13 +15,16 @@ There are two ways to use systemctl depending on your needs:
### 1. Utilize the helper functions
```
// For ES6:
import systemctl from 'systemctl'
import systemctl from 'systemctl-cmd'
// For ES5:
var systemctl = require('systemctl')
var systemctl = require('systemctl-cmd')

// Start a service
systemctl.start('service-name').then(output => console.log)

// Start a service with sudo
systemctl.start('service-name', true).then(output => console.log)

// Check if a service is enabled
systemctl.isEnabled('service-name').then(enabled => {
console.log((enabled ? 'Enabled' : 'Not enabled'));
Expand Down
63 changes: 44 additions & 19 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,46 +2,71 @@ var Promise = require('bluebird')
var run = require('./run')

function daemonReload() {
return run("daemon-reload")
return run("daemon-reload");
}

function disable(serviceName) {
return run("disable", serviceName)
return run("disable", serviceName);
}

function enable(serviceName) {
return run("enable", serviceName)
return run("enable", serviceName);
}

function isEnabled(serviceName) {
return new Promise((resolve, reject) => {
run('is-enabled', serviceName)
.then((result) => {
resolve(result.stdout.indexOf('enabled') != -1)
resolve(result.stdout.indexOf('enabled') != -1);
})
.catch(function (err) {
resolve(false)
resolve(false);
})
})
}

function restart(serviceName) {
return run("restart", serviceName)
function isActive(serviceName) {
return new Promise((resolve, reject) => {
run('is-active', serviceName)
.then((result) => {
if(result.stdout.indexOf('active') != -1 && result.stdout.indexOf('inactive')==-1)
resolve(true);
else
resolve(false);
})
.catch(function (err) {
resolve(false);
})
})
}

function restart(serviceName, sudo=false) {
return run("restart", serviceName, sudo);
}

function start(serviceName, sudo=false) {
return run("start", serviceName, sudo);
}

function stop(serviceName, sudo=false) {
return run("stop", serviceName, sudo);
}

function start(serviceName) {
return run("start", serviceName)
function mask(serviceName, sudo=false) {
return run("mask", serviceName, sudo);
}

function stop(serviceName) {
return run("stop", serviceName)
function unmask(serviceName, sudo=false) {
return run("unmask", serviceName, sudo);
}

module.exports.run = run
module.exports.daemonReload = daemonReload
module.exports.disable = disable
module.exports.enable = enable
module.exports.isEnabled = isEnabled
module.exports.restart = restart
module.exports.start = start
module.exports.stop = stop
module.exports.run = run;
module.exports.daemonReload = daemonReload;
module.exports.disable = disable;
module.exports.enable = enable;
module.exports.isEnabled = isEnabled;
module.exports.restart = restart;
module.exports.start = start;
module.exports.stop = stop;
module.exports.mask = mask;
module.exports.unmask = unmask;
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

19 changes: 14 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
{
"name": "systemctl",
"version": "0.2.2",
"name": "systemctl-cmd",
"version": "0.2.4",
"description": "Allows you to control system services using the systemctl command easily and asynchronously",
"repository": "bmcclure/node-systemctl",
"repository": {
"type": "git",
"url": "[email protected]:justinschw/systemctl-cmd.git"
},
"keywords": [
"Systemctl",
"Systemd",
Expand All @@ -11,17 +14,23 @@
],
"author": "Ben McClure <[email protected]> (volantisdev.com)",
"license": "MIT",

"homepage": "https://github.com/bmcclure/node-systemctl",
"bugs": {
"url": "https://github.com/bmcclure/node-systemctl/issues"
},
"contributors": [
"Ben McClure <[email protected]> (volantisdev.com)",
"Frank Lemanschik"
"Frank Lemanschik",
"Justin Schwartzbeck <[email protected]>",
"chaojinn"
],
"dependencies": {
"bluebird": "^3.5.0",
"child-process-promise": "^2.2.1"
},
"main": "index.js",
"devDependencies": {},
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
}
}
10 changes: 3 additions & 7 deletions run.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
var exec = require("child-process-promise").exec

module.exports = function run(cmd, service_name) {
var command = 'systemctl ' + cmd
module.exports = function run(cmd, service_name, sudo = false) {
var command = `${(sudo) ? 'sudo ' : ''}systemctl ${cmd} ${service_name}`;

if (service_name) {
command = command + ' ' + service_name
}

return exec(command)
return exec(command);
}