Systemd Unit File Checklist for Custom Apps and Workers

halfbrain_logo512adminJune 16, 2026
1 lượt xem

Systemd Unit File Checklist for Custom Apps and Workers

Custom apps, Python scripts, Node.js services, queue workers and automation agents should not run only inside a terminal session. A systemd unit lets Linux manage startup, restart, logging and service lifecycle.

Core principle

A reliable background app needs a working directory, execution command, service user, restart policy, environment variables and logs. Without these, it may disappear after logout or reboot.

Checklist

  1. Define the exact command that starts the app.
  2. Define the working directory.
  3. Choose the service user.
  4. Set environment variables safely.
  5. Create a systemd unit file.
  6. Validate the unit configuration.
  7. Reload systemd.
  8. Start and enable the service.
  9. Check logs with journalctl.
  10. Test reboot survival if required.

Reusable lesson

This applies to API workers, crawlers, Telegram bots, AI agents, queue processors, monitoring scripts and internal automation tools.

Checklist Type Basic DevOps
Level Intermediate
Risk Level High Risk
Estimated Time 45–90 minutes

When to Use This Checklist

Use this checklist when turning a script, API worker, AI agent, crawler or automation service into a managed Linux service.

Required Tools

SSH access, app command, app folder, environment variables, service user, systemd, journalctl

Before You Start

Test the app command manually before creating a systemd unit. Systemd cannot fix a command that does not run.

Structured Checklist Steps

  1. Test start command.
  2. Define working directory.
  3. Choose service user.
  4. Prepare environment variables.
  5. Create unit file.
  6. Validate unit.
  7. Reload systemd.
  8. Start service.
  9. Enable service.
  10. Check logs.

Rollback Plan

If the unit fails, disable the service, restore the previous unit file and run the start command manually to isolate the error.

Common Mistakes

  • Using root when not needed.
  • Wrong working directory.
  • Missing environment variables.
  • Forgetting daemon-reload.
  • No restart policy for critical workers.

Related Commands

sudo nano /etc/systemd/system/my-worker.service
sudo systemctl daemon-reload
sudo systemctl start my-worker
sudo systemctl status my-worker
journalctl -u my-worker --since "30 minutes ago"
sudo systemctl enable my-worker

Share:

Disclaimer: The guides, checklists, commands, and examples on HalfBrain.net are provided for educational and operational reference only. Server environments, hosting providers, software versions, security settings, and WordPress configurations can vary, so you should always review commands before running them on your own system. We do our best to keep the content accurate and useful, but we cannot guarantee that every command, configuration, or recommendation will fit every environment. Always back up your website, database, and server configuration before making changes. HalfBrain.net is not responsible for data loss, downtime, security incidents, misconfiguration, or other issues that may result from applying the information on this website. Use the material at your own discretion.

Leave a Reply

Your email address will not be published. Required fields are marked *