Hacker News new | ask | show | jobs
by msimpson 3446 days ago
Personally, I love Systemd for Web development as it makes the job of managing Node.js projects a breeze. I simply pack a Systemd unit file into a project's repository as part of its multi-environment configuration and construct deployment tasks to copy, enable, then start the unit file.

1. Copy <unit.service> to the sever, which looks like:

  [Unit]
  Description=<name> Service
  After=network.target

  [Service]
  Restart=always
  StandardOutput=syslog
  StandardError=syslog
  SyslogIdentifier=node-<name>
  User=<user>
  Group=<group>
  WorkingDirectory=/srv/node/<name>/current/
  Environment="NODE_ENV=production"
  Environment="PORT=2580"
  ExecStart=/usr/bin/node server.js

  [Install]
  WantedBy=multi-user.target
2. Enable the unit file in place:

  sudo systemctl enable /srv/node/<name>/config/<unit.service>
3. Start the unit file:

  sudo systemctl start <unit.service>
And, of course, destroying that deployment is just as easy.