Skip to content

Instantly share code, notes, and snippets.

@marcellkiss
Last active January 10, 2016 19:45
Show Gist options
  • Save marcellkiss/0746cb8d4281eaccc337 to your computer and use it in GitHub Desktop.
Save marcellkiss/0746cb8d4281eaccc337 to your computer and use it in GitHub Desktop.

Create: cat /etc/systemd/system/budacode.com.service

[Unit]                                                                                                               │var config = require('./config/environment');
Description=Budacode                                                                                                 │
After=network.target                                                                                                 │// Connect to database
                                                                                                                     │mongoose.connect(config.mongo.uri, config.mongo.options);
[Service]                                                                                                            │
ExecStart=/var/www/budacode/domains/budacode.com/www/static/dist/server/app.js                                       │// Populate DB with sample data
Restart=always                                                                                                       │if(config.seedDB) { require('./config/seed'); }
Group=nobody                                                                                                         │
Environment=PATH=/usr/bin:/usr/local/bin                                                                             │// Setup server
Environment=NODE_ENV=production                                                                                      │var app = express();
WorkingDirectory=/var/www/budacode/domains/budacode.com/www/static/dist                                              │
                                                                                                                     │// Prerender.io
[Install]                                                                                                            │app.use(require('prerender-node').set('prerenderToken', 'VNGpU1r90YaroaFGEthz'));
WantedBy=multi-user.target 

Note: The app.js file should be executable

  • #!/usr/bin/env node
  • chmod +x app.js

Useful commands

  • systemctl daemon-reload - Restart daemon
  • systemctl start budacode.com - Start the service
  • journalctl --follow -u budacode.com - Check the logs
  • sudo chkconfig --levels 235 php-fpm on - Start a service on boot
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment