summaryrefslogtreecommitdiff
blob: d297966af1c00851e80eabe11721b455d72a63c0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
#!/sbin/openrc-run
# Copyright 1999-2012 Gentoo Foundation
# Distributed under the terms of the GNU General Public License v2
# $Id$

FCRON_INSTANCE=${SVCNAME##*.}

configfile() {
    if [ -n "${FCRON_INSTANCE}" -a "${SVCNAME}" != "fcron" ]; then
	echo /etc/fcron/fcron.${FCRON_INSTANCE}.conf
    else
	echo /etc/fcron/fcron.conf
    fi
}

getconfig() {
    # if there is no configuration file return the default value
    if ! [ -f $(configfile) ]; then
	echo $2
	return 0
    fi

    sed -n -e 's:^$1[ \t]*=[ \t]*::p' $(configfile)
}

depend() {
    config $(configfile)

    use logger
    need clock hostname
    # provide the cron service if we are the main instance
    [ "${SVCNAME}" = "fcron" ] && provide cron
}

command="/usr/libexec/fcron"
command_args="-c $(configfile)"
pidfile=$(getconfig pidfile /var/run/fcron.pid)
fcrontabs=$(getconfig fcrontabs /var/spool/fcron)

extra_started_commands="reload"

start_pre() {
    if [ ! -e $(configfile) ]; then
	eerror "You will need to create $(configfile) first"
	eerror "There is a sample in /etc/fcron"
	return 1
    fi

    if [ ! -d ${fcrontabs} ]; then
	ebegin "Creating missing spooldir ${fcrontabs}"
	${command} --newspooldir ${fcrontabs}
	eend $?
    fi
}

reload() {
    kill -HUP `cat ${pidfile}`
}