igorklopov / enclose

Compile your Node.js project into an executable
http://enclosejs.com
Other
936 stars 43 forks source link

Restart automatically #134

Closed brunobg closed 7 years ago

brunobg commented 7 years ago

What would be the best way to restart an enclose compiled software automatically? Something like forever.

serkanp commented 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..

czjs2 commented 7 years ago

@brunobg pm2 http://pm2.keymetrics.io/

brunobg commented 7 years ago

@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?

czjs2 commented 7 years ago

@brunobg i using pm2 with enclosejs on many project. pm2 is Production process manager for Node.JS applications with a built-in load balancer .

BrstDev123 commented 7 years ago

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!

igorklopov commented 7 years ago

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.

alex-controlx commented 7 years ago

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

igorklopov commented 7 years ago

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