From 606083ea568e41bcb986925b4475cd1802286475 Mon Sep 17 00:00:00 2001 From: Shuqian Ying Date: Tue, 2 Jan 2018 22:31:36 -0800 Subject: [PATCH 1/3] add working directory option to systemd script --- lib/daemon.js | 1 + lib/systemd.js | 1 + lib/templates/systemd/service | 1 + lib/templates/systemd/service-wrapper | 1 + 4 files changed, 4 insertions(+) diff --git a/lib/daemon.js b/lib/daemon.js index 7844257..344c041 100644 --- a/lib/daemon.js +++ b/lib/daemon.js @@ -676,6 +676,7 @@ var daemon = function(config) { opts.name = this.label; opts.description = this.description; + opts.cwd = this.cwd; opts.author = this.author; opts.env = this.EnvironmentVariables; opts.usewrapper = config.usewrapper; diff --git a/lib/systemd.js b/lib/systemd.js index e194518..aa93b46 100644 --- a/lib/systemd.js +++ b/lib/systemd.js @@ -130,6 +130,7 @@ var init = function(config){ script: p.join(__dirname,'wrapper.js'), nodescript: config.script || '', wrappercode: (config.wrappercode || ''), + cwd: config.cwd, description: config.description, user: config.user || 'root', group: config.group || 'root', diff --git a/lib/templates/systemd/service b/lib/templates/systemd/service index 270df83..30a4ebf 100644 --- a/lib/templates/systemd/service +++ b/lib/templates/systemd/service @@ -2,6 +2,7 @@ Description={{description}} [Service] +WorkingDirectory={{cwd}} ExecStart={{execpath}} {{nodescript}} Restart=always SyslogIdentifier={{label}} diff --git a/lib/templates/systemd/service-wrapper b/lib/templates/systemd/service-wrapper index a16d830..8f80d7f 100644 --- a/lib/templates/systemd/service-wrapper +++ b/lib/templates/systemd/service-wrapper @@ -2,6 +2,7 @@ Description={{description}} [Service] +WorkingDirectory={{cwd}} ExecStart={{execpath}} {{script}} {{{wrappercode}}} Restart=always SyslogIdentifier={{label}} From 26348bb8c3ad9006543d1597c84878dec9b30587 Mon Sep 17 00:00:00 2001 From: Shuqian Ying Date: Wed, 3 Jan 2018 23:34:21 -0800 Subject: [PATCH 2/3] assign recommended file attributes to the generated systemd script --- lib/systemd.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/systemd.js b/lib/systemd.js index aa93b46..acb6825 100644 --- a/lib/systemd.js +++ b/lib/systemd.js @@ -197,7 +197,7 @@ var init = function(config){ me.generate(function(script){ fs.writeFile(filepath,script,function(err){ if (err) return me.emit('error', err); - fs.chmod(filepath,'755',function(_err){ + fs.chmod(filepath,'644',function(_err){ if (_err) return me.emit('error', _err); var cmd = 'systemctl daemon-reload'; From 87df627b638f97a4d432d5bcaf4b464ba6ac1bf2 Mon Sep 17 00:00:00 2001 From: Shuqian Ying Date: Sat, 31 Aug 2019 16:21:34 +0800 Subject: [PATCH 3/3] use original name as the service name instead --- lib/daemon.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/daemon.js b/lib/daemon.js index 344c041..d60401b 100644 --- a/lib/daemon.js +++ b/lib/daemon.js @@ -156,7 +156,7 @@ var daemon = function(config) { label: { enumerable: false, get: function(){ - return this.name.replace(/[^a-zA-Z0-9\_]+/gi,'').toLowerCase() + return this.name //this.name.replace(/[^a-zA-Z0-9\_]+/gi,'').toLowerCase() } },