How to use
- Enter the service name, the command (ExecStart), the working directory, and the user and group. The command must be an absolute path such as
/usr/bin/node. - Set the restart policy, environment, environment file, hardening and memory or file limits as needed.
- For a recurring job, turn on the timer. The service becomes
oneshotand a.timerfile is generated too. A cron expression can be converted into theOnCalendarvalue. - Save the files under
/etc/systemd/system/and run thesystemd-analyze verify,daemon-reloadandenable --nowcommands shown at the bottom in order.
Main settings
| Setting | Directive | Notes |
|---|---|---|
| Service type | Type= |
simple treats the ExecStart process as the service. Use oneshot for run-and-exit jobs and forking for programs that daemonize themselves |
| Restart | Restart=, RestartSec= |
on-failure restarts only after an abnormal exit; always restarts even after a clean exit |
| Wait for network | After=, Wants=network-online.target |
Starts once the network is up |
| Environment file | EnvironmentFile= |
Keeps secrets out of the unit file. A leading - lets the service start without the file |
| Hardening | NoNewPrivileges, PrivateTmp, ProtectSystem, ProtectHome |
Blocks privilege gain, gives a private /tmp, makes system and home directories read-only or hidden |
| Writable paths | ReadWritePaths= |
Paths the app may write to under ProtectSystem=strict |
| Resources | MemoryMax=, LimitNOFILE= |
Memory ceiling and open file limit |
Cron expression to OnCalendar
With the timer on, a field converts a cron expression into OnCalendar. This tool gives:
| Cron | OnCalendar |
|---|---|
0 3 * * * |
*-*-* 03:00:00 |
0 9 * * 1-5 |
Mon..Fri *-*-* 09:00:00 |
30 2 * * 0 |
Sun *-*-* 02:30:00 |
*/15 * * * * |
*-*-* *:00/15:00 |
0 0 1 * * |
*-*-01 00:00:00 |
0,30 9-17 * * * |
*-*-* 09..17:00,30:00 |
A cron expression with both day-of-month and weekday (0 0 13 * 5) runs when either one matches, but systemd needs both to match, so a warning is shown. For @reboot, use the timer’s OnBootSec instead of OnCalendar. To build or check the cron expression itself, use the Cron Expression Generator and the Cron Expression Parser.
Things to watch
ProtectHome=truehides everything under/homefrom the app. If the working directory is under/home, turn hardening off or move it.ProtectSystem=strictblocks writes everywhere except the paths inReadWritePaths.- Do not write passwords or tokens in
Environment=; move them toEnvironmentFile=and give the file mode 600. Unit files andsystemctl showoutput are visible to other users. The chmod Calculator helps with the permission digits. - A
%in anEnvironmentvalue starts a systemd specifier, so this tool writes it as%%. Quotes and backslashes are escaped too. - Line breaks in input are replaced with spaces so nobody can slip extra directives into a field.
- Review the generated unit before using it on a production server. Your app may also need
TimeoutStopSec,ExecReloador logging settings. - Convert the environment file between formats with the Env Converter. If you run containers, the Dockerfile Generator and the Nginx Config Generator are the next steps.
Frequently asked questions
Where do I save the service file?
Put your own units at /etc/systemd/system/name.service. After saving, run sudo systemctl daemon-reload so systemd reads the new file.
Where do I look when the service will not start?
systemctl status name.service shows the state and the last log lines, and journalctl -u name.service -n 100 shows more. status=203/EXEC often means a wrong ExecStart path or missing execute permission.
Why use a timer instead of cron?
Logs go to the journal, Persistent=true runs missed jobs when the machine is back on, and the execution environment is managed as a service unit.
Type=simple or forking?
If the program stays in the foreground (most Node, Python and Go apps), use simple. For a traditional daemon that forks and lets the parent exit, use forking.
Is my input sent to a server?
No. The files are generated in your browser.
Your input is processed in this browser and never sent to a server.