简体   繁体   中英

How to create a start/stop/restart Linux service for Sails.js

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.

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

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();

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM