12345678910111213141516171819202122232425262728293031323334353637383940414243 |
- # vim: ft=sh
- # env config:
- # * SLEEP: time in seconds to sleep after main action
- # default: 1080
- #
- # * SERVICE: service name to be displayed as sleep argv0
- # default: "${PWD##*/}"
- #
- # * STATE_FILE: path to file that indicate that main action completed
- # default: "${TMPDIR:-/tmp}/.${SERVICE}_cron"
- #
- # example:
- # file: /etc/sv/mlocate/run
- # ```sh
- # #!/bin/sh --
- #
- # updatedb_service() {
- # exec updatedb
- # }
- # . /etc/runit/functions/runit_cron
- # SERVICE=locate-db STATE_FILE=/run/mlocate/.state SLEEP="$(( 60 * 60 ))" \
- # runit_cron updatedb_service
- # ```
- #
- runit_cron() {
- set -ue
- : "${1:?}"
- : "${SERVICE:=${PWD##*/}}"
- : "${STATE_FILE:=${TMPDIR:-/tmp}/.${SERVICE}_cron}"
- if [ -f "${STATE_FILE}" ]; then
- rm -f -- "${STATE_FILE}"
- exec chpst -b "${SERVICE}: sleep" \
- sleep "${SLEEP:-$(( 30 * 60 ))}"
- else
- ( umask 777 && :> "${STATE_FILE}" )
- "${@}"
- fi
- }
|