meta-digi-dey: dey-examples: fix start/stop script of "connectcore-demo-example" service

The start/stop script of the service was using "killproc" and "pidofproc" functions from
"/etc/init.d/functions" to find the process PID. These functions rely on "pidof", which does
not work very well with Python scripts. Instead, use "pkill" and "pgrep" which allow to
search the executable in the full command line to retrieve the correct PID with the -f modifier.

Signed-off-by: David Escalona <david.escalona@digi.com>
This commit is contained in:
David Escalona 2022-09-28 13:01:12 +02:00
parent dda302ef77
commit bd0eadc16e
1 changed files with 2 additions and 5 deletions

View File

@ -13,17 +13,14 @@
#
#===============================================================================
# Source function library
. /etc/init.d/functions
readonly DEMOSERVER_BINARY="/srv/www/demoserver.py"
readonly STOP_TIMEOUT="5"
stop_process() {
# try to stop gracefully
killproc "${1}" >/dev/null 2>&1
pkill -f "${1}" >/dev/null 2>&1
for i in $(seq ${STOP_TIMEOUT}); do
pid=$(pidofproc "${1}") || break
pid=$(pgrep -f "${1}") || break
if [ "${i}" -eq ${STOP_TIMEOUT} ]; then
kill -KILL "${pid}" >/dev/null 2>&1
fi