Compare commits

...

2 commits

Author SHA1 Message Date
Simon Vieille 0d1f1e29b5
replace stop action in messenger
Some checks failed
ci/woodpecker/push/build Pipeline failed
2023-10-18 22:38:22 +02:00
Simon Vieille 28f8e5c583
replace stop action in messenger 2023-10-18 22:33:33 +02:00

View file

@ -22,7 +22,7 @@ help() {
-l debug|info|notice|warning|error -l debug|info|notice|warning|error
Debug level Debug level
-a start|stop|restart -a start|stop|restart|status
EOH EOH
} }
@ -34,52 +34,23 @@ on_interrupt() {
} }
start_messenger() { start_messenger() {
started=0 nohup php8.1 bin/console messenger:consume 2>/dev/null >/dev/null &
pid= log -t -l notice "Started"
if [ -f "$pid_file" ]; then
pid="$(cat "$pid_file")"
fi
if [ -n "$pid" ]; then
if [ -d "/proc/$pid" ]; then
log -t -l warning "Already running"
started=1
fi
fi
if [ "$started" -eq 0 ]; then
nohup php8.1 bin/console messenger:consume 2>/dev/null >/dev/null &
echo -n $! > "$pid_file"
log -t -l notice "Started"
fi
} }
stop_messenger() { stop_messenger() {
pid= php8.1 bin/console messenger:stop-workers
log -t -l notice "Stopped"
}
if [ -f "$pid_file" ]; then get_pid() {
pid="$(cat "$pid_file")" pgrep -f messenger:consume
fi
if [ -n "$pid" ]; then
if [ ! -d "/proc/$pid" ]; then
log -t -l warning "Not started"
else
kill -9 "$pid"
log -t -l notice "Stopped"
fi
rm "$pid_file"
else
log -t -l warning "Not started"
fi
} }
main() { main() {
cd "$(dirname "0")" cd "$(dirname "0")"
pid_file=var/messenger.pid ACTION=
while getopts "l:ha:" option; do while getopts "l:ha:" option; do
case "${option}" in case "${option}" in
@ -97,10 +68,12 @@ main() {
elif [ "$ACTION" = "restart" ]; then elif [ "$ACTION" = "restart" ]; then
stop_messenger stop_messenger
start_messenger start_messenger
elif [ "$ACTION" = "status" ]; then
get_pid
else
log -l error "Action is required."
fi fi
# log [-t] [-l debug|info|notice|warning|error] message
exit 0 exit 0
} }