3 . ${CIRROS_LIB:=/lib/cirros/shlib_cirros} ||
4 { echo "failed to read ${CIRROS_LIB}" 1>&2; exit 1; }
8 Usage: ${0##*/} [ options ] frequency name cmd [args]
10 run cmd with given arguments for the given frequency.
12 always: run every time
13 always-ds: run every time, but only if there is a datasource
14 boot: run only once per boot
15 instance: run once per instance (first boot)
16 once: run once ever (first boot with or without datasource)
17 name is the name of this thing. subsequent runs of will be
18 run with the given frequency based on state kept in 'name'
21 --dry-run : only report, do not update results
22 -v | --verbose : be more verbose
28 local long_opts="help,dry-run,verbose"
30 getopt_out=$(getopt --name "${0##*/}" \
31 --options "${short_opts}" --long "${long_opts}" -- "$@") &&
32 eval set -- "${getopt_out}" ||
33 { bad_Usage; return; }
35 local dryrun=false cur="" next="" VERBOSITY="$VERBOSITY"
36 local freq="" name="" state_d="" marker=""
38 while [ $# -ne 0 ]; do
41 -h|--help) Usage ; exit 0;;
42 -v|--verbose) VERBOSITY=$((${VERBOSITY}+1));;
43 --dry-run) dryrun=true;;
48 [ $# -ge 3 ] || { bad_Usage "must provide frequency, name, cmd"; return; }
54 [ ! -r "$CONFIG" ] || . "$CONFIG" ||
55 fail "failed to read $CONFIG"
60 marker="always.always.${name}"
64 marker="always-ds.always.${name}"
66 { error "no datasource found"; return 1; }
70 ds_get_item "instance-id" ||
71 { error "failed to get instance-id of datasource"; return 1; }
73 marker="instance.${iid}.${name}"
77 marker="once.once.${name}"
80 state_d="${BOOT_STATE_D}"
81 marker="boot.boot.${name}"
83 *) fail "bad frequency $freq";;
86 debug 2 "using state_dir=${state_d}, marker=${marker}"
88 [ -d "$state_d" ] || mkdir -p "$state_d" ||
89 { error "failed to create state_dir ${state_d}"; return 1; }
91 if [ "${freq#always}" = "$freq" -a -f "${state_d}/${marker}" ]; then
92 { error "${name} already run per ${freq}"; return 0; }
100 local ret=0 uptime="" idle=""
101 debug 2 "[$freq]" "$@"
106 echo "[${_RET}]" "$@" > "${state_d}/${marker}"
113 # vi: ts=4 noexpandtab