-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcron.sh
executable file
·47 lines (41 loc) · 1.23 KB
/
cron.sh
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
#!/usr/bin/env bash
if [[ $# == 2 && $1 == '--interval' ]]; then
i=$2
else
echo 'Usage: ./cron.sh --interval <minutes>'
exit 1
fi
set -e
((i * 60))
log_file='./conf/log.txt'
touch "${log_file}"
discord_webhook_url="$(jq --raw-output '.triggers | .discord | .webhook_url' './conf/config.json')"
[[ "${discord_webhook_url}" == 'https://discord.com/'* ]]
set +e
cargo build --release
echo "Hereafter, all outputs to stdout and stderr are redirected to the log file [ ${log_file} ]."
exec >> "${log_file}" 2>&1
while true; do
echo "--------------- $(date) ---------------"
./target/release/rsst
if [[ $? != 0 ]]; then
sleep 60
./target/release/rsst #retry
if [[ $? != 0 ]]; then
curl --silent \
-X POST \
"${discord_webhook_url}" \
-H 'Content-Type: application/json' \
-d "$(echo '{"wait": true, "content": "rsst: Failed. See the log."}' | jq --rawfile log <(tail "${log_file}") '.content += "\n\n" + $log')"
fi
fi
echo
for ((j = 0; j < i; ++j)); do
restart='./conf/.restart'
if [[ -f "${restart}" ]]; then
rm "${restart}"
break
fi
sleep 60
done
done