radio.service.example 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. # systemd unit for the daveo-radio node app — /etc/systemd/system/radio.service
  2. # ============================================================================
  3. #
  4. # An alternative to pm2 (ecosystem.config.cjs). Use ONE of the two, not both.
  5. #
  6. # Runs the app as a long-lived service behind Apache (see
  7. # apache-radio.conf.example). Adjust User/Group and WorkingDirectory to match
  8. # where the repo is checked out on the server.
  9. #
  10. # BUILD FIRST — this app serves the built bundle in app/, which is gitignored,
  11. # and systemd does NOT build. Before enabling the service, and after every pull:
  12. #
  13. # npm install && npm run build # devDeps needed to build; app/ is output
  14. #
  15. # Then:
  16. # sudo cp deploy/radio.service.example /etc/systemd/system/radio.service
  17. # sudo systemctl daemon-reload
  18. # sudo systemctl enable --now radio
  19. # systemctl status radio
  20. # journalctl -u radio -f # logs (startup + connection events)
  21. #
  22. # On deploy of new code:
  23. # git pull && npm install && npm run build && sudo systemctl restart radio
  24. [Unit]
  25. Description=daveo-radio (Icecast player + socket.io chat, node)
  26. After=network.target
  27. [Service]
  28. Type=simple
  29. User=www-data
  30. Group=www-data
  31. WorkingDirectory=/var/www/radio
  32. ExecStart=/usr/bin/node app.js
  33. Restart=on-failure
  34. RestartSec=2
  35. # Config. Mirrors .env.example. DAW_ORIGIN is intentionally absent — it is a
  36. # local-dev-only shim for the shared chrome and must NOT be set in production.
  37. Environment=NODE_ENV=production
  38. Environment=PORT=3000
  39. Environment=BASE_PATH=/radio
  40. Environment=TRUST_PROXY=1
  41. Environment=STREAM_URL=https://stream.davidawindham.com/stream
  42. Environment=STREAM_STATUS_URL=https://stream.davidawindham.com/status-json.xsl
  43. Environment=STREAM_MOUNT=/stream
  44. Environment=LASTFM_USER=windhamdavid
  45. # The Last.fm key is the one secret. Keep it out of this world-readable unit:
  46. # put it in a drop-in that root owns, chmod 600 --
  47. # sudo systemctl edit radio
  48. # and add:
  49. # [Service]
  50. # Environment=LASTFM_API_KEY=xxxxxxxx
  51. # Unset => the sidebar lists stay empty; the app still runs.
  52. [Install]
  53. WantedBy=multi-user.target