Systemd User Units as a Cronjob Alternative
Systemd user units are only available on our Managed Hosting plans. On Shared Hosting (Starter and Business plans), set up recurring tasks instead as cronjobs in LiveConfig.
Many applications, shop and CMS systems in particular, need tasks that run on a recurring schedule: processing queues, clearing caches, sending emails, updating exchange rates. Classically, a cronjob handles this. On our Managed Hosting systems, we recommend setting up your own systemd user units instead wherever possible, which you manage yourself, with no root privileges required.
Advantages over classic cronjobs
- No overlapping runs: A cronjob starts strictly on schedule, regardless of whether a previous run is still active. If a task ever takes longer than expected, multiple runs can overlap and interfere with each other. systemd reliably prevents this: a new run only starts once the previous one has finished.
- Centralized logging: Output automatically lands in the systemd journal and can be inspected with
journalctl --user, including retroactively, without a separate log file or email sent by the cron daemon. - Automatic restart: If a service crashes, systemd can restart it on its own, depending on configuration.
- Clear status:
systemctl --user statusshows at a glance whether a task last ran successfully.
Prerequisites
Carry out the following steps via SSH access on your hosting account. There is no separate root login, all commands run in your own user context via systemctl --user.
For user units to keep running without an active SSH session, loginctl enable-linger is normally required. In our Managed Hosting environment, this so-called lingering is already enabled and managed by us, so no additional step is needed here.
First create the directory for your user units, if it doesn’t exist yet:
Two basic patterns
Depending on how the task behaves, one of two patterns fits best.
Pattern A: recurring single run (service + timer)
Equivalent to a classic cronjob: a script is invoked once on a fixed schedule, runs to completion, and exits. For this, you create two matching units.
~/.config/systemd/user/example.service:
~/.config/systemd/user/example.timer:
OnCalendar replaces the five fields of a classic cron schedule:
| Cron syntax | OnCalendar equivalent |
Meaning |
|---|---|---|
* * * * * |
OnCalendar=minutely |
every minute |
*/5 * * * * |
OnCalendar=*-*-* *:0/5:00 |
every 5 minutes |
*/15 * * * * |
OnCalendar=*-*-* *:0/15:00 |
every 15 minutes |
*/30 * * * * |
OnCalendar=*-*-* *:0/30:00 |
every 30 minutes |
0 * * * * |
OnCalendar=hourly |
hourly |
30 2 * * * |
OnCalendar=*-*-* 02:30:00 |
daily at 02:30 |
Only the timer unit is activated, not the service unit directly, since activating the service directly would run it once immediately instead of waiting for its schedule:
Pattern B: a long-running service with its own internal scheduling
Some applications bring their own task management and should therefore not be restarted at short intervals, but instead be kept running continuously. The program itself exits after a defined run time, and systemd automatically restarts it afterwards. A single unit without a timer is enough here:
~/.config/systemd/user/example-loop.service:
Here the service unit itself is activated, not a timer:
The leading hyphen before the program path in ExecStart tells systemd not to treat an exit code caused by the application itself as a start failure. StartLimitBurst=10000 prevents systemd from giving up after a few quick restarts in a row, for instance if the run time is occasionally very short.
Examples for common CMS and shop systems
The following examples show how the recurring tasks of well-known systems map onto one of the two patterns. Adjust USERNAME and the paths to match your own installation.
| System | Task | Pattern | ExecStart |
|---|---|---|---|
| Shopware | scheduled-task:run |
B (long-running, Restart=always) |
/usr/bin/php8.2 .../bin/console scheduled-task:run --time-limit=900 --memory-limit=512M |
| Magento | cron.sh every 5 minutes |
A (service + timer, OnCalendar=*-*-* *:0/5:00) |
/bin/bash .../cron.sh |
| WordPress | wp cron event run --due-now every 30 minutes |
A (service + timer, OnCalendar=*-*-* *:0/30:00) |
cd .../wp-installation && wp cron event run --due-now |
| PrestaShop | currency rate update, hourly | A (service + timer, OnCalendar=hourly) |
/usr/bin/wget -O /dev/null -q "https://yourdomain.com/adminXXX/cron_currency_rates.php?secure_key=..." |
A fully worked-out setup for several parallel tasks with individual schedules is also available in our article on cronjobs for your own Sendy installation.
Verify the setup
Overview of all active timers, including the next scheduled run:
Status of a single unit:
Follow a unit’s log in real time:
Further commands
If you need assistance, feel free to contact our Support.