2
0
mirror of https://github.com/koreader/koreader synced 2024-11-10 01:10:34 +00:00
koreader/plugins/backgroundrunner.koplugin/wrapper.sh
Hzj_jie c9a997f42c BackgroundRunner (#3008)
* Use getCapacityHW() to ensure latest battery capacity can be retrieved

* BackgroundRunner

* Start background_runner_spec.lua

* AutofrontLight plugin now uses BackgroundRunner plugin
2017-07-28 16:48:19 +02:00

40 lines
962 B
Bash
Executable File

#!/bin/sh
# Starts the arguments as a bash command in background with low priorty. The
# command will be killed if it executes for over 1 hour. If the command failed
# to start, this script returns 127. If the command is timed out, this script
# returns 255. Otherwise the return value of the command will be returned.
echo "TIMEOUT in environment: $TIMEOUT"
if [ -z "$TIMEOUT" ]; then
TIMEOUT=3600
fi
echo "Timeout has been set to $TIMEOUT seconds"
echo "Will start command $*"
echo "$@" | nice -n 19 sh &
JOB_ID=$!
echo "Job id: $JOB_ID"
for i in $(seq 1 1 $TIMEOUT); do
if ps -p $JOB_ID >/dev/null 2>&1; then
# Job is still running.
sleep 1
ROUND=$(printf "%s" "$i" | tail -c 1)
if [ "$ROUND" -eq "0" ]; then
echo "Job $JOB_ID is still running ... waited for $i seconds."
fi
else
wait $JOB_ID
exit $?
fi
done
echo "Command $* has timed out"
kill -9 $JOB_ID
exit 255