How to use the Systemd Service File Generator
- 1. Name the serviceGive it a name and a short description.
- 2. Say how it startsThe full ExecStart path, working folder, user and environment.
- 3. InstallCopy the file, reload systemd and enable it with the commands shown.
The default unit file
The example runs a Node.js API as myapp.service. The [Unit] section waits for network-online.target. The [Service] section uses Type=simple, runs as user and group myapp in /opt/myapp, sets NODE_ENV and PORT, starts /usr/bin/node /opt/myapp/server.js, and restarts it five seconds after a crash with Restart=on-failure. The [Install] section links it to multi-user.target so it starts at boot.
Underneath, the tool lists the five commands to copy the file to /etc/systemd/system, run daemon-reload, enable and start it, check its status and follow its log with journalctl.
Options worth knowing
- Type: simple for most apps, notify for apps that tell systemd when they are ready, forking for old daemons, oneshot for scripts that run and exit.
- Restart: on-failure restarts after crashes; always also restarts after a clean exit.
- Hardening: NoNewPrivileges, PrivateTmp, ProtectSystem=full and ProtectHome reduce what a compromised app can touch. Turn them off if your app writes to /home or system folders.
- EnvironmentFile loads settings from a file, which keeps secrets out of the unit.
ExecStart must use an absolute path; find it with which node or which python3. Put Nginx in front with the Nginx config generator, and automate the install with the Ansible playbook generator.
Frequently asked questions
Why does my service fail with status 203/EXEC?
systemd could not run the ExecStart program. Check the path is absolute, the file exists and it is executable by the service user.
Is pm2 or systemd better for Node.js?
Both work. systemd is already on most Linux servers and handles logs and restarts without extra software.
Is the Systemd Service File Generator free?
Yes, the Systemd Service File Generator is free. The first time you generate your first unit file, you are asked for your name and WhatsApp number once. After that, this and every other Uncodemy tool opens straight away without the form.