NodeJS + systemd
NodeJS + systemd
or
There's more to life than nodemon
systemd - process #1
systemd
- modeled on macos launchd
- runs services
- handles mountpoints
- process management via cgroups
- replaces syslog with journald
- recently adding basic network managment
Why systemd
because it's THERE
Why systemd
prod != dev
systemd
configured via UNITS
- .service, .socket
- .network, .link, .netdev
- .device, .mount, automount, .swap
- .target
- .path
- .timer
- .scope, .slice
Ephemeral Jobs
systemd-run --description="ls as a systemd.service" --unit="ls.service" ls -la /usr/lib/systemd
journalctl -u "ls.service"
Socket Activation
[Unit]
Description=Rsync Socket
Conflicts=rsyncd.service
[Socket]
ListenStream=873
Accept=true
[Install]
WantedBy=sockets.target
Socket Activation
[Unit]
Description=A file transfer program to keep remote files in sync
After=network.target
[Service]
ExecStart=/usr/bin/rsync --daemon --no-detach
RestartSec=1
[Install]
WantedBy=multi-user.target
Your First Service
[Unit]
Description=hello_env.js - making your environment variables rad
Documentation=https://example.com
After=network.target
[Service]
Environment=NODE_PORT=3001
Type=simple
User=ubuntu
ExecStart=/usr/bin/node /home/ubuntu/hello_env.js
Restart=on-failure
[Install]
WantedBy=multi-user.target
Your First Service
(better)
[Unit]
Description=hello_env.js - making your environment variables rad
Documentation=https://example.com
After=network.target
[Service]
Environment=NODE_PORT=3001
Type=simple
User=ubuntu
ExecStart=/usr/bin/node /srv/node/ubuntu/hello_env.js
Restart=on-failure
[Install]
WantedBy=multi-user.target
That's All
That's All
lodolabs@gmail.com
deck
By Matt Sprague
deck
- 1,485