a pocket reference
Getting to know your system daemon
Create your user-created service files in:
/etc/systemd/system
The machine-created service files will go in:
/lib/systemd/system
more in-depth:
where do i put my systemd service file
what is the difference between systemd system and user services
Example
a sample .service
file, at /etc/systemd/system/hello.service
:
[Unit]
Description=hello_env.js - making your environment variables rad
Documentation=https://example.com
After=network.target
[Service]
Type=simple
User=ubuntu
ExecStart=/usr/bin/node /home/ubuntu/hello_env.js
Restart=on-failure
[Install]
WantedBy=multi-user.target
*common mistake - make sure to reference the same node
or executable that your user has access to
( which node
in this case )
Digital Ocean in-depth article
Admin with systemctl
refresh service files:
sudo systemctl daemon-reload
start app:
sudo systemctl start hello_env
status:
sudo systemctl status hello_env
start at boot / don't start at boot:
sudo systemctl enable hello_env # / disable
list all services:
sudo systemctl list-unit-files
Debugging systemd:
Logging with journalctl
Common commands:
journalctl -u [app name] # -u for "unit"
journalctl -f # -f for "follow" - show logs in real time
journalctl -n [number] # - specify number of lines to start
journalctl --disk-usage # total disk usage
journalctl --vacuum-size=1G # shrink oldest logs until specified size
see the DO guide for permanent settings:
Digital Ocean - comprehensive overview of journalctl
adjust to your timezone
sudo timedatectl list-timezones | grep [your region]
sudo timedatectl set-timezone [your region]