Skip to content

Commit 9dbc775

Browse files
committed
docs(cron): recommend persistent .cron file + update_cron
Add recommended pattern using /boot/config/plugins/<plugin>/<plugin>.cron with /usr/local/sbin/update_cron instead of writing directly to /etc/cron.d/. Update rc.d script example to use the persistent approach. Thanks @Squidly271 in issue #2
1 parent b67b173 commit 9dbc775

1 file changed

Lines changed: 26 additions & 5 deletions

File tree

docs/core/cron-jobs.md

Lines changed: 26 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,18 +9,37 @@ nav_order: 7
99

1010
## Overview
1111

12-
Plugins can add scheduled tasks using cron. Unraid uses the standard cron daemon with files in `/etc/cron.d/`. Additionally, Unraid provides a built-in **Dynamix Scheduler** that offers a GUI-based interface for managing scheduled tasks.
12+
Plugins can add scheduled tasks using cron. Unraid uses the standard cron daemon with files in `/etc/cron.d/`. For plugin-managed cron entries, the simplest persistent pattern is storing a file like `/boot/config/plugins/yourplugin/yourplugin.cron` and calling `update_cron` after changes. Additionally, Unraid provides a built-in **Dynamix Scheduler** that offers a GUI-based interface for managing scheduled tasks.
1313

1414
## Methods for Scheduling Tasks
1515

1616
There are three primary ways to schedule tasks in Unraid:
1717

1818
| Method | Best For | Persistence |
1919
|--------|----------|-------------|
20+
| `/boot/config/plugins/<plugin>/<plugin>.cron` | Plugin-owned cron entries | Persistent on flash |
2021
| `/etc/cron.d/` files | System-level tasks | Recreate on boot |
2122
| Dynamix Scheduler | User-configurable tasks | Automatic via GUI |
2223
| User Scripts plugin | User-defined scripts | Via plugin settings |
2324

25+
## Recommended: Plugin Cron File + `update_cron`
26+
27+
Store your cron line in a plugin-owned file on flash and let `update_cron` sync it into active cron state.
28+
29+
```xml
30+
<FILE Name="/boot/config/plugins/yourplugin/yourplugin.cron">
31+
<INLINE>
32+
0 * * * * root /usr/local/emhttp/plugins/yourplugin/scripts/hourly.sh &gt;/dev/null 2&gt;&amp;1
33+
</INLINE>
34+
</FILE>
35+
36+
<FILE Run="/bin/bash">
37+
<INLINE>
38+
/usr/local/sbin/update_cron
39+
</INLINE>
40+
</FILE>
41+
```
42+
2443
## Adding a Cron Job via /etc/cron.d/
2544

2645
Cron files should be installed to `/etc/cron.d/` since this directory is in RAM and recreated on boot.
@@ -48,12 +67,14 @@ For dynamic schedules or conditional cron jobs, create/remove the cron file from
4867

4968
case "$1" in
5069
'start')
51-
# Create cron job
52-
echo "*/5 * * * * root /usr/local/emhttp/plugins/yourplugin/check.sh" > /etc/cron.d/yourplugin
70+
# Create/update persistent cron file
71+
echo "*/5 * * * * root /usr/local/emhttp/plugins/yourplugin/check.sh" > /boot/config/plugins/yourplugin/yourplugin.cron
72+
/usr/local/sbin/update_cron
5373
;;
5474
'stop')
55-
# Remove cron job
56-
rm -f /etc/cron.d/yourplugin
75+
# Remove persistent cron file and refresh cron
76+
rm -f /boot/config/plugins/yourplugin/yourplugin.cron
77+
/usr/local/sbin/update_cron
5778
;;
5879
esac
5980
```

0 commit comments

Comments
 (0)