cron: add procd listeners for crontabs
[openwrt/openwrt.git] / package / utils / busybox / files / cron
1 #!/bin/sh /etc/rc.common
2 # Copyright (C) 2006-2011 OpenWrt.org
3
4 START=50
5
6 USE_PROCD=1
7 PROG=/usr/sbin/crond
8
9 validate_cron_section() {
10 uci_validate_section system system "${1}" \
11 'cronloglevel:uinteger'
12 }
13
14 start_service() {
15 [ -z "$(ls /etc/crontabs/)" ] && return 1
16
17 loglevel="$(uci_get "system.@system[0].cronloglevel")"
18
19 [ -z "${loglevel}" ] || {
20 /sbin/validate_data uinteger "${loglevel}" 2>/dev/null
21 [ "$?" -eq 0 ] || {
22 echo "validation failed"
23 return 1
24 }
25 }
26
27 mkdir -p /var/spool/cron
28 ln -s /etc/crontabs /var/spool/cron/ 2>/dev/null
29
30 procd_open_instance
31 procd_set_param command "$PROG" -f -c /etc/crontabs -l "${loglevel:-5}"
32 for crontab in /etc/crontabs/*; do
33 procd_set_param file "$crontab"
34 done
35 procd_close_instance
36 }
37
38 service_triggers() {
39 procd_add_validation validate_cron_section
40 }