#!/usr/bin/env /lib/runit/invoke-run
set -e

NAME="cron"
DAEMON=/usr/sbin/cron

# Exit service if DAEMON is not installed
if [ ! -x $DAEMON ]; then
	exit 161
fi

# Load defaults
[ -r /etc/default/cron ] && . /etc/default/cron

# Parse the system's environment
if [ "$READ_ENV" = "yes" ] ; then
    for ENV_FILE in /etc/environment /etc/default/locale; do
        [ -r "$ENV_FILE" ] || continue
        [ -s "$ENV_FILE" ] || continue

         for var in LANG LANGUAGE LC_ALL LC_CTYPE; do
             value=$(egrep "^${var}=" "$ENV_FILE" | tail -n1 | cut -d= -f2)
             [ -n "$value" ] && eval export $var=$value
         done
     done

# Get the timezone set.
    if [ -z "$TZ" -a -e /etc/timezone ]; then
        TZ=$(cat /etc/timezone)
    fi
fi

exec 2>&1

exec $DAEMON -f ${EXTRA_OPTS}
