3 # Suspend script for fcron.
4 # Designed to work under systemd and pm-utils.
7 # - systemd: /usr/lib/systemd/system-sleep/fcron.sh
8 # - pm-utils: /etc/pm/sleep.d/74_fcron
11 PID_FILE=/usr/local/var/run/fcron.pid
12 SUSPEND_FILE=/usr/local/var/run/fcron.suspend
13 PATH=/bin:/usr/bin:/sbin:/usr/sbin
14 LOGGER="logger -p cron.info"
16 FCRONPID=`cat $PID_FILE`
18 # pm-utils: first argument will be hibernate|suspend|resume|thaw
19 # systemd: two arguments: 1st one is pre|post, second one is suspend|hibernate|hybrid-sleep
22 pre|suspend|suspend_hybrid|hibernate)
23 # We will use the modify time of SUSPEND_FILE to know when we went into suspend:
24 kill -STOP "$FCRONPID" || $LOGGER "$0 $*: could not stop fcron pid '$FCRONPID'"
25 touch $SUSPEND_FILE || $LOGGER "$0 $*: could not touch fcron suspend file '$SUSPEND_FILE'"
26 $LOGGER "$0 $*: stopped pid `cat $PID_FILE` (from $PID_FILE), and touched $SUSPEND_FILE"
29 SLEEP_FROM=`stat -c %Y $SUSPEND_FILE`
30 if test $? -eq 0; then
32 SLEEP_DURATION=`expr $NOW - $SLEEP_FROM`
33 if test $? -lt 2; then
34 $LOGGER "$0 $*: SLEEP_DURATION=$SLEEP_DURATION"
35 echo $SLEEP_DURATION > $SUSPEND_FILE
37 # something went wrong -- resume fcron without specifying
38 # a suspend duration as it may be wrong
39 $LOGGER "$0 $*: could not compute sleep duration"
43 # something went wrong -- resume fcron without specifying
44 # a suspend duration as it may be wrong
45 $LOGGER "$0 $*: could not stat $SUSPEND_FILE"
48 $LOGGER "$0 $*: resuming pid `cat $PID_FILE` (from $PID_FILE)"
49 kill -CONT `cat $PID_FILE` || $LOGGER "$0 $*: could not resume fcron pid '$FCRONPID'"
52 $LOGGER "$0 $*: invalid argument."