3 ms·
Rad list - I'm going to use your 1.2 automatic browser restarts via SSE trick! Re: 1.1 automatic server restarts (for crashes etc) there's no need for forever
by nailer 12y ago
Rad list - I'm going to use your 1.2 automatic browser restarts via SSE trick!
Re: 1.1 automatic server restarts (for crashes etc) there's no need for forever / supervisord / nodemon on current Linux: make a .service file for your app and it will automatically restart if it crashes, on all major distros.
[Unit]
Description=My app
[Service]
ExecStart=/var/www/myapp/app.js
Restart=always
User=nobody
Group=nobody
Environment=PATH=/usr/bin:/usr/local/bin
Environment=NODE_ENV=production
[Install]
WantedBy=multi-user.target
From: http://medium.com/@mikemaccana/how-i-deploy-node-apps-on-linux-2014-edition-309d606219ca http://medium.com/@mikemaccana/how-i-deploy-node-apps-on-lin...
- silverwind 12y agoI'd add something like After=network.target in the [Unit] section, or you could be in for a bad surprise after a reboot, when your service tries to start before network comes up. Also, I doubt that systemd is available on 'all major' distros.
- nailer 12y agoCheers will do. Re major, Red Hat, Ubuntu, Debian and SuSE current stable releases all have systemd. That said AWS Linux doesn't have it.
- babby 12y agoOr better yet, use PM2 instead of forever. As someone who has spent years with forever, I was ultimately happy to drop it into the trash after discovering PM2. https://github.com/Unitech/pm2 https://github.com/Unitech/pm2 It's significantly more advanced. Create a "process.json" file in your project directory (As you would a nodemon.json), like so: { "name" : "someApp" , "script" : "./index.js" , "node_args" : "--harmony" , "log_file" : true , "merge_logs" : true , "exec_mode" : "fork_mode" , "ignoreWatch" : [ "\\.(css|styl|log)$" , "static/.*" , "views/.*" ] } This will show logs intertwined just like forever, merge logs from seperate forked processes and you can even throw in watch rules like nodemon. pm2 start process.json Then to make all of your processes always restart do this: pm2 save pm2 startup centos Replacing centos with your distro. Couldn't be easier. There are a lot of other features I don't use (such as deployment, which I suspect will be significant for some big websites), but definitely consider dropping forever/supervisord and even nodemon in favor of PM2. They merge pull requests quickly it seems, too. The only issue I've had is that for some reason using the "watch" functionality on a lot of files causes massive CPU overload, or at least it did, it may be fixed by now. If you're going to use the watch functionality (to reload stuff like nodemon), consider whitelisting and not blacklisting files.