Skip to content

Instantly share code, notes, and snippets.

@hostsamurai
Created June 9, 2013 23:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hostsamurai/5745763 to your computer and use it in GitHub Desktop.
Save hostsamurai/5745763 to your computer and use it in GitHub Desktop.
This solves two gotchas I came across when deploying a node site running express through systemd: 1) Remove the callback in `listen` or the requests will hang, and 2) tell systemd what the working directory for your app is.
var express = require('express')
, http = require('http')
, path = require('path');
require('systemd');
var app = express();
// configuration and routes go here...
http.createServer(app).listen(app.get('port'));
[Service]
ExecStart=/usr/bin/node /srv/http/mysite/app.js
StandardOutput=journal+console
StandardError=journal+console
SyslogIdentifier=mysite
User=http
Group=http
WorkingDirectory=/srv/http/mysite/
Environment=PATH=/usr/bin:/usr/lib/
Environment=NODE_ENV=production
[Socket]
ListenStream=/run/systemd/system/node-mysite.sock
[Install]
WantedBy=sockets.target
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment