forked from MemesRandomland/telegraph_export_bot
-
Notifications
You must be signed in to change notification settings - Fork 3
/
telegram-cn-archive-bot.bash
54 lines (50 loc) · 975 Bytes
/
telegram-cn-archive-bot.bash
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
#!/bin/bash
# Python 3 launcher with stdout and stderr to file
cd "$(dirname "${BASH_SOURCE[0]}")" || exit
name=$(basename "${BASH_SOURCE[0]}")
name=${name%.*}
command="python3 -u archive.py"
function doStart() {
pid=$(pidof "$name")
if [ ! "$pid" ]; then
rm "$name.out" "$name.err"
bash -c "exec -a $name $command &" 1>>"$name.out" 2>>"$name.err"
fi
sleep 1
pid=$(pidof "$name")
if [ "$pid" ]; then
echo "$pid started"
else
cat "$name.out" "$name.err"
exit 10
fi
}
function doStop() {
pid=$(pidof "$name")
# shellcheck disable=SC2086
if [ "$pid" ]; then
kill $pid
while kill -0 $pid 2>/dev/null; do
sleep 1
done
echo "$pid stopped"
fi
}
trap 'onCtrlC' INT
function onCtrlC() {
doStop
}
if [ "$1" == "stop" ]; then
doStop
exit
elif [ "$1" == "start" ]; then
doStart
exit
elif [ "$1" == "restart" ]; then
doStop
doStart
exit
else
doStart
tail --pid="$pid" -qf "$name.out" "$name.err"
fi