Search code examples
node.jsexpresscentosforeversystemctl

Cannot launch forever process with systemctl


I have a simple Node/Express server running with forever

forever start forever_app_config.json

My config file looks like this

{
    "uid": "myapp",
    "append": true,
    "watch": true,
    "script": "app.js",
    "sourceDir": "/data/projects/myapp"
}

and everything works fine. But when trying to add a service (/usr/lib/systemd/system/mayapp.service)

[Unit]
Description = My Service

[Service]
User = centos
Group = centos
Environment = NODE_ENV=production
Environment = PORT=3333
ExecStart = /usr/bin/forever start /data/projects/myapp/forever_app_config.json
ExecStop = /usr/bin/forever stop myapp

[Install]
WantedBy = multi-user.target

it doesnt work for some reason: sudo systemctl start myapp -l

myapp.service - My Service
   Loaded: loaded (/usr/lib/systemd/system/myapp.service; enabled; vendor preset: disabled)
   Active: inactive (dead) since Mon 2018-02-19 11:43:08 UTC; 12min ago
  Process: 26685 ExecStop=/usr/bin/forever stop malcazar (code=exited, status=0/SUCCESS)
  Process: 26674 ExecStart=/usr/bin/forever start /data/projects/myapp/forever_app_config.json (code=exited, status=0/SUCCESS)
 Main PID: 26674 (code=exited, status=0/SUCCESS)

and forever logs (/home/centos/.forever/myapp.log) show such an error: error: Forever detected script was killed by signal: SIGKILL.

So, what is wrong with my configs?


Solution

  • I have resolved the issue by migrating to pm2 instead of using forever. http://pm2.keymetrics.io/docs/usage/quick-start/