• Welcome to TalkativeTurtles - a community for developers & tech enthusiasts.
  • Share projects, get code reviewed, and talk tech without the noise.
  • New here? Introduce yourself in the Introductions forum!
Hello There, Guest! Login Register


Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Title: systemd services - writing and managing your own .service files
Threaded Mode
#1
systemd is everywhere on modern Linux and understanding how to write service files means you can run any process reliably as a system service with auto-restart, logging, and dependency management.

A minimal service file
Code:
[Unit]
Description=My Application
After=network.target

[Service]
Type=simple
User=myapp
WorkingDirectory=/opt/myapp
ExecStart=/opt/myapp/myapp --config /etc/myapp/config.yml
Restart=always
RestartSec=5

[Install]
WantedBy=multi-user.target

Save to /etc/systemd/system/myapp.service

Essential commands
Code:
sudo systemctl daemon-reload          # reload after editing a .service file
sudo systemctl enable myapp            # start on boot
sudo systemctl start myapp             # start now
sudo systemctl restart myapp           # restart
sudo systemctl status myapp            # check status + recent logs
sudo journalctl -u myapp -f            # follow live logs
sudo journalctl -u myapp --since today # logs from today

Useful Service options
Code:
Environment=NODE_ENV=production        # set env vars
EnvironmentFile=/etc/myapp/.env        # load from file
StandardOutput=journal                 # send stdout to journald
StandardError=journal
LimitNOFILE=65535                      # raise file descriptor limit
PrivateTmp=yes                         # isolated /tmp
NoNewPrivileges=yes                    # security hardening

Type values that matter:
  • simple - process started by ExecStart IS the service
  • forking - process forks and parent exits (old daemon style)
  • notify - process signals systemd when ready (more reliable than simple for slow-starting services)

Restart policies:
  • always - always restart, regardless of exit code
  • on-failure - restart only on non-zero exit
  • on-abnormal - restart on signal/timeout/watchdog, not clean exit
Reply
  


Possibly Related Threads…
Thread Author Replies Views Last Post
  Self-hosting at home - what services are you running? Zero Two 1 197 06-22-2026, 06:25 AM
Last Post: Zero Two

Forum Jump:


Browsing: 1 Guest(s)