Last active
April 16, 2018 07:41
-
-
Save chernjie/6234c95466f8ec1f09f2e180d0a8617c to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
rundir=/var/run/parallelLimit | |
pause_file="$rundir/paused" | |
harakiri_file="$rundir/good-day-to-die" | |
is-paused() { | |
[ -f "$pause_file" ] | |
} | |
is-time-to-die() { | |
[ -f "$harakiri_file" ] | |
} | |
run() { | |
for i in $(seq 1 16); do | |
( | |
while true; do | |
is-time-to-die && exit | |
if is-paused; then | |
sleep 60 | |
else | |
/path/to/do-job | |
fi | |
done | |
) & | |
done | |
wait | |
} | |
pause() { | |
touch "$pause_file" | |
} | |
unpause() { | |
rm -f "$pause_file" | |
} | |
stop() { | |
touch "$harakiri_file" | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment