-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbot.sh
executable file
·62 lines (42 loc) · 980 Bytes
/
bot.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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
#!/bin/bash
# Script de gestion du bot (lancement, arrêt, etc.)
day=$(date +"%F")
timestamp=$(date +"%H_%M_%S")
start_bot() {
# Création du dossier du jour s'il n'existe pas encore
# (jour du lancement du bot)
mkdir -p logs/$day
echo "Lancement du bot..."
nohup python3 -u argobot/main.py &> "logs/$day/nohup_$timestamp.out" &
echo $! > pid
# Pour accéder facilement au log courant
rm logs/current.log > /tmp/trash
ln -s $day/nohup_$timestamp.out logs/current.log
}
stop_bot() {
kill -s 10 $(cat pid)
echo "Bot hors ligne"
sleep 0.1
while ps | grep $(cat pid);
do
kill $(cat pid)
done
}
if [ "$#" -lt "1" ]; then
echo "Utilisation: $0 [start|stop|restart]"
exit 1;
fi
if [ $1 = "start" ]; then
start_bot
fi
if [ $1 = "stop" ]; then
stop_bot
fi
if [ $1 = "restart" ]; then
stop_bot
sleep 0.25
start_bot
fi
if [[ $1 =~ ^log.* ]]; then
cat logs/current.log
fi