This repository was archived by the owner on Nov 27, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathenrunerate
More file actions
executable file
·69 lines (59 loc) · 1.73 KB
/
enrunerate
File metadata and controls
executable file
·69 lines (59 loc) · 1.73 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
#!/bin/bash
PARAM=$1
REGEXP="./code/scraper"
# Parameters:
# "run" to actually launch scraper if not already
# Otherwise just return status
# Disable buffering of stdout/stderr
# XXX can we do this in other languages?
export PYTHONUNBUFFERED=1
# Make output encode as UTF-8, as that is what the browser is expecting
export PYTHONIOENCODING=utf_8
# Check already running
# XXX this won't work on multiple servers without affinity of some kind
# perhaps instead can rely on the flock?
if pgrep -f "$REGEXP" >/dev/null
then
if [ "$PARAM" == "stop" ]
then
# Try and kill it kindly, so SQLite will close up properly
pkill -f "$REGEXP"
if pgrep -f "$REGEXP" >/dev/null
then
sleep 1
pkill -f "$REGEXP"
if pgrep -f "$REGEXP" >/dev/null
then
# Wait a while to give it time
sleep 10
if pgrep -f "$REGEXP" >/dev/null
then
# Give up
pkill -9 -f "$REGEXP"
if pgrep -f "$REGEXP" >/dev/null
then
echo -n "failed to kill"
fi
fi
fi
fi
echo -n "nothing"
exit 0
else
echo -n "running"
exit 0
fi
fi
# Run in background, redirecting to logfile
if [ "$PARAM" == "run" ]
then
mkdir -p logs/
# Use flock to lock the launch, to be sure we only run one copy
# (we can ignore errors - it is already running and we only want one at a time!)
flock -n ./running.flock bash -c "tool/actually-run" >logs/out 2>&1 &
# Say it is now running
echo -n "running"
exit 0
fi
# Say whether it is running
echo -n "nothing"