简体   繁体   English

如何为Sails.js创建启动/停止/重启Linux服务

[英]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 . 我想在Linux上为Sails.js创建启动/停止/重启服务。


Will start Sails (similar to sails lift command): 将启动帆(类似于sails lift命令):

sudo service myapp start

Will stop Sails: 将停止航行:

sudo service myapp stop

Will restart Sails: 将重新启动Sails:

sudo service myapp restart


I found this link , but it doesn't work as expected. 我找到了此链接 ,但无法正常工作。

You could use PM2 : 您可以使用PM2

$ npm install -g pm2

Then you can use pm2 to start your app with: 然后,您可以使用pm2来启动您的应用程序:

$ 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 您需要node-linux,配置指南在github页面上给出

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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