Repository navigation
Expand file tree
/
Copy pathstart.sh
More file actions
executable file
·126 lines (109 loc) · 2.64 KB
/
Copy pathstart.sh
File metadata and controls
executable file
·126 lines (109 loc) · 2.64 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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
#!/bin/bash
SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
# Script de gestion du bot IRC GLINE
# Usage: ./start.sh {start|stop|restart|status}
BOT_NAME="gline_bot"
BOT_SCRIPT="gline_bot.py"
PID_FILE="$SCRIPT_DIR/.gline_bot.pid"
LOG_FILE="$SCRIPT_DIR/gline_bot.log"
# Couleurs pour l'affichage
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
NC='\033[0m' # No Color
cd "$SCRIPT_DIR"
get_pid() {
if [ -f "$PID_FILE" ]; then
cat "$PID_FILE"
else
echo ""
fi
}
is_running() {
local pid=$(get_pid)
if [ -n "$pid" ] && kill -0 "$pid" 2>/dev/null; then
return 0
else
return 1
fi
}
start_bot() {
if is_running; then
echo -e "${YELLOW}Le bot est deja en cours d'execution (PID: $(get_pid))${NC}"
exit 1
fi
echo -e "${GREEN}Demarrage du bot $BOT_NAME...${NC}"
nohup python3 "$BOT_SCRIPT" >> "$LOG_FILE" 2>&1 &
echo $! > "$PID_FILE"
sleep 1
if is_running; then
echo -e "${GREEN}Bot demarre avec succes (PID: $(get_pid))${NC}"
else
echo -e "${RED}Echec du demarrage du bot${NC}"
rm -f "$PID_FILE"
exit 1
fi
}
stop_bot() {
if ! is_running; then
echo -e "${YELLOW}Le bot n'est pas en cours d'execution${NC}"
rm -f "$PID_FILE"
exit 0
fi
local pid=$(get_pid)
echo -e "${YELLOW}Arret du bot (PID: $pid)...${NC}"
kill "$pid"
# Attendre l'arret (max 10 secondes)
for i in {1..10}; do
if ! is_running; then
echo -e "${GREEN}Bot arrete avec succes${NC}"
rm -f "$PID_FILE"
return 0
fi
sleep 1
done
# Force kill si necessaire
echo -e "${RED}Le bot ne repond pas, arret force...${NC}"
kill -9 "$pid" 2>/dev/null
rm -f "$PID_FILE"
echo -e "${GREEN}Bot arrete${NC}"
}
restart_bot() {
echo -e "${YELLOW}Redemarrage du bot...${NC}"
stop_bot
sleep 2
start_bot
}
status_bot() {
if is_running; then
echo -e "${GREEN}Le bot est en cours d'execution (PID: $(get_pid))${NC}"
else
echo -e "${RED}Le bot n'est pas en cours d'execution${NC}"
rm -f "$PID_FILE" 2>/dev/null
fi
}
case "$1" in
start)
start_bot
;;
stop)
stop_bot
;;
restart)
restart_bot
;;
status)
status_bot
;;
*)
echo "Usage: $0 {start|stop|restart|status}"
echo ""
echo "Commandes:"
echo " start - Demarre le bot en arriere-plan"
echo " stop - Arrete le bot"
echo " restart - Redémarre le bot"
echo " status - Affiche l'etat du bot"
exit 1
;;
esac
exit 0