Deployment

Systemd

Manage the GO Shortener background service, auto-restarts, and logs using systemd.

Systemd

GO Shortener runs as a native Linux service managed by systemd, ensuring automatic recovery in the event of crashes, system reboots, or server maintenance.


Service Unit Definition

The unit file is located at /etc/systemd/system/go-shortener.service:

/etc/systemd/system/go-shortener.service
[Unit]
Description=GO Shortener - Minimal High-Performance URL Shortener
After=network.target

[Service]
Type=simple
User=root
WorkingDirectory=/root/Go-shortner
ExecStart=/root/Go-shortner/go-shortener
Restart=always
RestartSec=3
LimitNOFILE=65535

# Security Hardening
PrivateTmp=true

[Install]
WantedBy=multi-user.target

Directive Breakdown

  • After=network.target: Delays service startup until server networking interfaces are fully initialized.
  • WorkingDirectory=/root/Go-shortner: Sets the root execution context so the binary correctly discovers .env and ./data/go.sqlite.
  • Restart=always & RestartSec=3: Ensures the service is immediately restarted within 3 seconds if an unexpected panic or termination occurs.
  • LimitNOFILE=65535: Increases the maximum file descriptor limit, ensuring high concurrent HTTP connection handling.
  • PrivateTmp=true: Isolates the /tmp directory to protect temporary files from other system processes.

Managing the Service

Use standard systemctl commands to control the application:

Terminal
# Start the service
systemctl start go-shortener

# Stop the service
systemctl stop go-shortener

# Restart the service (after updating .env or the binary)
systemctl restart go-shortener

# Check current runtime status
systemctl status go-shortener

# Enable service to start automatically on system boot
systemctl enable go-shortener

# Disable auto-start on boot
systemctl disable go-shortener

Inspecting Application Logs

All standard output (stdout) and standard error (stderr) streams from the Go binary are captured by the systemd journal:

Terminal
# Stream live logs in real time
journalctl -u go-shortener -f

# View the last 100 log entries
journalctl -u go-shortener -n 100 --no-pager

# View logs generated today
journalctl -u go-shortener --since today
Copyright © 2026