npm start and keep running

Joined
May 13, 2020
Messages
2
I have a jail setup on my FreeNAS server, and have gotten Mellow (https://github.com/v0idp/Mellow) to run. However I am stuck on how to get it to start automatically with the jail, and keep running in the background. As of right now it only runs when I manually input "npm start" and by keeping the shell window open. Any help would be appreciated, Ive googled different options however I cant seem to get anything to actually work. Thanks!
 

sretalla

Powered by Neutrality
Moderator
Joined
Jan 1, 2016
Messages
9,700
well, at very least you could try npm start & which should allow you to close the window.
 

sretalla

Powered by Neutrality
Moderator
Joined
Jan 1, 2016
Messages
9,700
I'm having a quick look at the homebridge plugin (also an NPM package) and will see if there's a clue in there.
 

sretalla

Powered by Neutrality
Moderator
Joined
Jan 1, 2016
Messages
9,700
Looks like they have placed a file in /usr/local/bin/

Called homebridge, with these contents:
Code:
#!/usr/bin/env node

//
// This executable sets up the environment and runs the HomeBridge CLI.
//

"use strict";

process.title = "homebridge";

// Find the HomeBridge lib
const path = require("path");
const fs = require("fs");
const lib = path.join(path.dirname(fs.realpathSync(__filename)), "../lib");

// Run HomeBridge
require(lib + '/cli')();


There is also a service configured (/usr/local/etc/rc.d/pm2_root):
Code:
#!/bin/sh

# PROVIDE: pm2
# REQUIRE: LOGIN
# KEYWORD: shutdown

. /etc/rc.subr

name="pm2_root"
rcvar="pm2_root_enable"

start_cmd="pm2_start"
stop_cmd="pm2_stop"
reload_cmd="pm2_reload"
status_cmd="pm2_status"
extra_commands="reload status"

pm2()
{
  env PATH="$PATH:/sbin:/bin:/usr/sbin:/usr/bin:/usr/local/sbin:/usr/local/bin:/root/bin" PM2_HOME="/root/.pm2" su -m "root" -c "/usr/local/lib/node_modules/pm2/bin/pm2 $*"
}

pm2_start()
{
  pm2 resurrect
}

pm2_stop()
{
  pm2 kill
}

pm2_reload()
{
  pm2 reload all
}

pm2_status()
{
  pm2 list
}

load_rc_config $name
run_rc_command "$1"


Seems that you might be able to get the same result if you did it with mellow?
 
Joined
May 13, 2020
Messages
2
That "npm start & " command is amazing! Helps to get me up and running for right now. I tried the pm2 option before, but im new to this and maybe didnt get my code right. I will see if I can get that Homebridge code to take. Thanks!
 

Patrick M. Hausen

Hall of Famer
Joined
Nov 25, 2013
Messages
7,776
The documentation for that is right here:

It might be easier to install and enable supervisord and use that to start your npm service.
Code:
pkg install py37-supervisor
sysrc supervisord_enable=YES


HTH,
Patrick
 
Top