Closed brunobg closed 7 years ago
If you are using Linux, then write 2 scripts. First script will loop your application if exit. Second one will be service in /etc/init.d that will start your application on startup.(I can provide you example scripts) Also I use process.exit(number) to detect why exit. For example I use process.exit(3) to understand that there is a software update. My looping script gets the exit code, before restarting app again, it unzips update.zip file and put the contents to main folder, then starts the app again. If process.exit(9) it means user wanted to close the app.. Etc etc use your exit logics on your own..
If you are using Windows, use nssm to make your executable app as Windows service.. So windows will take care of successful restarts on exits..
On macos it's different :) you have to write daemon script in a different way. So depending on os, you will get os.platform and write your update process
To exit your app use process.exit()
Forever and other systems runs before your app.js, it detects exit and starts your app.. I could not find a better way to restart app on compiled app..
@brunobg pm2 http://pm2.keymetrics.io/
@serkanp thanks for the detailed answer. I was trying to avoid writing my own solution, since it should take care of infinite loops and so on and have something more easily portable but it's a solution nevertheless.
@czjs2 awesome suggestion, I didn't know pm2. Did you use pm2 with enclosejs? Any tips?
@brunobg i using pm2 with enclosejs on many project. pm2 is Production process manager for Node.JS applications with a built-in load balancer .
I have installed module PM2 and enclose module both in my application and after that I have run command enclose index.js it created a exe file. So would that file restart automatically when that will crash or stop? Do I need to run another command here? Please Suggest!
Probably no. AFAIK PM2 is run outside your application and it controls only Node.js scripts. You should make your exe file run as a service/daemon.
EncloseJS executable works fine with pm2 on Debian. I use:
enclose server.js
that generates server
and on production machine:
pm2 server
Here the docs http://pm2.keymetrics.io/docs/usage/process-management/#binary-code-execution
Dear users of EncloseJS. I highly encourage you to switch to https://github.com/zeit/pkg It is rewritten successor of EncloseJS. It is open source, and all improvements will go there. Please check if pkg has your issue unresolved, and if it is true, reopen your issue there: https://github.com/zeit/pkg/issues
What would be the best way to restart an enclose compiled software automatically? Something like
forever
.