Created
June 9, 2013 23:48
-
-
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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')); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[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