0

I want to create a start/stop/restart service on Linux for Sails.js.


Will start Sails (similar to sails lift command):

sudo service myapp start

Will stop Sails:

sudo service myapp stop

Will restart Sails:

sudo service myapp restart


I found this link, but it doesn't work as expected.

Badacadabra
  • 8,043
  • 7
  • 28
  • 49
JJC
  • 493
  • 1
  • 6
  • 10

2 Answers2

1

You could use PM2:

$ npm install -g pm2

Then you can use pm2 to start your app with:

$ pm2 start app.js

And then you can manage your process with:

$ pm2 stop     id
$ pm2 restart  id
$ pm2 delete   id
Osukaa
  • 708
  • 3
  • 10
  • 22
  • it doesn't do the Linux Service itself but this is helpful – JJC Feb 26 '15 at 02:02
  • @JJC I know :s but it helps and has other functions like auto restart and you can start multiple copies of the app at the same time and it automatically does the balancing and stuff like that. :) – Osukaa Feb 27 '15 at 15:51
  • you're right. I'm just pointing it now. I also know how to create the service so I'll be using your suggested pm2 for it. :) – JJC Mar 03 '15 at 04:35
1

You need node-linux , configuration guidelines are given on the github page

Following is an example config you can use

 var Service = require('node-linux').Service;

  // Create a new service object
  var svc = new Service({
    name:'sails app',
    description: 'sails application',
    script: '/path/to/app.js'
  });

  // Listen for the "install" event, which indicates the
  // process is available as a service.
  svc.on('install',function(){
    svc.start();
  });

  svc.install();
arkoak
  • 2,437
  • 21
  • 35