Skip to content

Commit 0abcfc8

Browse files
committed
FreeBSD Startup Support
1 parent 58369a5 commit 0abcfc8

File tree

2 files changed

+41
-50
lines changed

2 files changed

+41
-50
lines changed

lib/API/Startup.js

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,8 @@ module.exports = function(CLI) {
4141
'update-rc.d': 'upstart',
4242
'chkconfig' : 'systemv',
4343
'rc-update' : 'openrc',
44-
'launchctl' : 'launchd'
44+
'launchctl' : 'launchd',
45+
'sysrc' : 'rcd'
4546
};
4647
var init_systems = Object.keys(hash_map);
4748

@@ -139,6 +140,14 @@ module.exports = function(CLI) {
139140
'launchctl remove com.' + launchd_service_name,
140141
'rm ' + destination
141142
];
143+
break;
144+
case 'rcd':
145+
service_name = (opts.serviceName || 'pm2_' + user);
146+
commands = [
147+
'/usr/local/etc/rc.d/' + service_name + ' stop',
148+
'sysrc -x ' + service_name + '_enable',
149+
'rm /usr/local/etc/rc.d/' + service_name
150+
];
142151
};
143152

144153
shelljs.exec(commands.join('&& '), function(code, stdout, stderr) {
@@ -256,10 +265,11 @@ module.exports = function(CLI) {
256265
case 'freebsd':
257266
case 'rcd':
258267
template = getTemplate('rcd');
259-
destination = '/etc/rc.d/' + service_name;
268+
service_name = (opts.serviceName || 'pm2_' + user);
269+
destination = '/usr/local/etc/rc.d/' + service_name;
260270
commands = [
261-
'chmod +x ' + destination,
262-
'echo "pm2_enable=YES" >> /etc/rc.conf'
271+
'chmod 755 ' + destination,
272+
'sysrc ' + service_name + '_enable=YES'
263273
];
264274
break;
265275
case 'openrc':
@@ -281,7 +291,8 @@ module.exports = function(CLI) {
281291
template = template.replace(/%PM2_PATH%/g, process.mainModule.filename)
282292
.replace(/%NODE_PATH%/g, path.dirname(process.execPath))
283293
.replace(/%USER%/g, user)
284-
.replace(/%HOME_PATH%/g, opts.hp ? path.resolve(opts.hp, '.pm2') : cst.PM2_ROOT_PATH);
294+
.replace(/%HOME_PATH%/g, opts.hp ? path.resolve(opts.hp) : cst.PM2_ROOT_PATH)
295+
.replace(/%SERVICE_NAME%/g, service_name);
285296

286297
Common.printOut(chalk.bold('Platform'), platform);
287298
Common.printOut(chalk.bold('Template'));

lib/templates/init-scripts/rcd.tpl

Lines changed: 25 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -6,59 +6,39 @@
66

77
. /etc/rc.subr
88

9-
name=pm2
10-
rcvar=${name}_enable
11-
12-
load_rc_config $name
13-
14-
: ${pm2_user="%USER%"}
15-
16-
command="%PM2_PATH%"
17-
pidfile="/home/${pm2_user}/.pm2/${name}.pid"
18-
start_cmd="${name}_start"
19-
stop_cmd="${name}_stop"
20-
reload_cmd="${name}_reload"
21-
status_cmd="${name}_status"
22-
23-
extra_commands="reload"
24-
25-
super() {
26-
su - "${pm2_user}" -c "$*"
27-
}
28-
29-
pm2_start() {
30-
unset "${rc_flags}_cmd"
31-
if pm2_running; then
32-
echo "Pm2 is already running, 'pm2 list' to see running processes"
33-
else
34-
echo "Starting pm2."
35-
super $command resurrect
36-
fi
9+
name="%SERVICE_NAME%"
10+
rcvar="%SERVICE_NAME%_enable"
11+
12+
start_cmd="pm2_start"
13+
stop_cmd="pm2_stop"
14+
reload_cmd="pm2_reload"
15+
status_cmd="pm2_status"
16+
extra_commands="reload status"
17+
18+
pm2()
19+
{
20+
env PATH="$PATH:%NODE_PATH%" PM2_HOME="%HOME_PATH%" su -m "%USER%" -c "%PM2_PATH% $*"
3721
}
3822

39-
pm2_stop() {
40-
echo "Stopping ${name}..."
41-
#super $command dump
42-
super $command delete all
43-
super $command kill
23+
pm2_start()
24+
{
25+
pm2 resurrect
4426
}
4527

46-
pm2_reload() {
47-
echo "Reloading ${name}"
48-
super $command reload all
28+
pm2_stop()
29+
{
30+
pm2 kill
4931
}
5032

51-
pm2_status() {
52-
super $command list
33+
pm2_reload()
34+
{
35+
pm2 reload all
5336
}
5437

55-
pm2_running() {
56-
process_id=$(pgrep -F ${pidfile})
57-
if [ "${process_id}" -gt 0 ]; then
58-
return 0
59-
else
60-
return 1
61-
fi
38+
pm2_status()
39+
{
40+
pm2 list
6241
}
6342

43+
load_rc_config $name
6444
run_rc_command "$1"

0 commit comments

Comments
 (0)