From 7d48c41f4280f4a7bff5b9a54272df540c7ee5e8 Mon Sep 17 00:00:00 2001 From: jin Date: Wed, 3 Oct 2018 03:33:47 +0000 Subject: [PATCH] add a method to check if service is avtively running --- index.js | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/index.js b/index.js index 901470d..71a10f3 100644 --- a/index.js +++ b/index.js @@ -25,6 +25,21 @@ function isEnabled(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) { return run("restart", serviceName) }