Docs / Linux Basics / Managing System Services with systemctl

Managing System Services with systemctl

By Admin · Feb 25, 2026 · Updated Apr 23, 2026 · 219 views · 2 min read

What Is systemd?

systemd is the init system and service manager used by most modern Linux distributions. It manages service startup, dependencies, and lifecycle.

Basic Service Commands

# Start a service
sudo systemctl start nginx

# Stop a service
sudo systemctl stop nginx

# Restart a service
sudo systemctl restart nginx

# Reload configuration without restart
sudo systemctl reload nginx

# Check status
systemctl status nginx

Enable and Disable Services

# Start automatically on boot
sudo systemctl enable nginx

# Enable and start immediately
sudo systemctl enable --now nginx

# Disable auto-start
sudo systemctl disable nginx

# Check if enabled
systemctl is-enabled nginx

Viewing Service Information

# List all running services
systemctl list-units --type=service --state=running

# List all services (including inactive)
systemctl list-units --type=service --all

# List failed services
systemctl --failed

# Show service dependencies
systemctl list-dependencies nginx

Service Logs

# View logs for a service
journalctl -u nginx

# Follow logs in real-time
journalctl -u nginx -f

# Show last 50 lines
journalctl -u nginx -n 50

Creating a Custom Service

Create /etc/systemd/system/myapp.service:

[Unit]
Description=My Application
After=network.target

[Service]
Type=simple
User=www-data
WorkingDirectory=/opt/myapp
ExecStart=/opt/myapp/start.sh
Restart=on-failure
RestartSec=5
Environment=NODE_ENV=production

[Install]
WantedBy=multi-user.target
sudo systemctl daemon-reload
sudo systemctl enable --now myapp

Useful Tips

  • systemctl daemon-reload — run after editing any .service file
  • systemctl mask — completely prevent a service from starting
  • systemctl cat nginx — view the service file contents
  • systemctl edit nginx — create an override file

Was this article helpful?