Skip to content

Commit fb8fbe1

Browse files
danezvmarchaud
authored andcommitted
feat(startup): Allow custom service names for startup scripts
Especially when running mutliple instances of pm2 on one machine with the same user this helps to create multiple startup scripts for each of the instance.
1 parent 7e099e7 commit fb8fbe1

File tree

3 files changed

+13
-4
lines changed

3 files changed

+13
-4
lines changed

bin/pm2

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ commander.version(pkg.version)
4444
.option('--gid <gid>', 'run target script with <gid> rights')
4545
.option('--cwd <path>', 'run target script as <username>')
4646
.option('--hp <home path>', 'define home path when generating startup script')
47+
.option('--service-name <name>', 'define service name when generating startup script')
4748
.option('-c --cron <cron_pattern>', 'restart a running process based on a cron pattern')
4849
.option('-w --write', 'write configuration in local folder')
4950
.option('--interpreter <interpreter>', 'the interpreter pm2 should use for executing app (bash, python...)')

lib/API/Startup.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -64,9 +64,9 @@ module.exports = function(CLI) {
6464
var that = this;
6565
var actual_platform = detectInitSystem();
6666
var user = opts.user || process.env.USER;
67-
var service_name = 'pm2-' + user;
67+
var service_name = (opts.serviceName || 'pm2-' + user);
6868
var openrc_service_name = 'pm2';
69-
var launchd_service_name = 'pm2.' + user;
69+
var launchd_service_name = (opts.serviceName || 'pm2.' + user);
7070

7171
if (!platform)
7272
platform = actual_platform;
@@ -166,9 +166,9 @@ module.exports = function(CLI) {
166166
var that = this;
167167
var actual_platform = detectInitSystem();
168168
var user = (opts.user || process.env.USER);
169-
var service_name = 'pm2-' + user;
169+
var service_name = (opts.serviceName || 'pm2-' + user);
170170
var openrc_service_name = 'pm2';
171-
var launchd_service_name = 'pm2.' + user;
171+
var launchd_service_name = (opts.serviceName || 'pm2.' + user);
172172

173173
if (!platform)
174174
platform = actual_platform;

test/bash/startup.sh

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,14 @@ SRC=$(cd $(dirname "$0"); pwd)
1010
source "${SRC}/include.sh"
1111

1212
cd $file_path
13+
$pm2 startup upstart -u $USER --hp $HOME --service-name abcdef
14+
spec "should startup command generation exited succesfully with custom service-name"
15+
test -e /etc/init.d/abcdef
16+
spec "should have generated upstart file with custom service-name"
17+
$pm2 unstartup upstart --service-name abcdef
18+
spec "should have disabled startup with custom service-name"
19+
! test -e /etc/init.d/abcdef
20+
spec "should have deleted upstart file with custom service-name"
1321

1422
$pm2 startup upstart -u $USER --hp $HOME
1523
spec "should startup command generation exited succesfully"

0 commit comments

Comments
 (0)