Skip to content

Commit

Permalink
leader_file check
Browse files Browse the repository at this point in the history
  • Loading branch information
ddeguglielmo committed Aug 24, 2023
1 parent 7a96d51 commit 606c7c2
Show file tree
Hide file tree
Showing 3 changed files with 73 additions and 1 deletion.
5 changes: 4 additions & 1 deletion docker/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ RUN pip install --no-cache-dir -r /requirements.txt

ADD main.py /

ENTRYPOINT ["/usr/local/bin/python3", "/main.py"]
ADD run_manager.sh /
ADD launch_light_manager.sh /

ENTRYPOINT ["/run_manager.sh"]


2 changes: 2 additions & 0 deletions launch_light_manager.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
#!/bin/sh
/usr/local/bin/python3 /main.py
67 changes: 67 additions & 0 deletions run_manager.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
#!/bin/sh
FILE=/services/leader_file.txt

function start_light_manager() {
echo "Starting Light Manager"
/launch_light_manager.sh &

}


function stop_light_manager() {

cont=0
while pgrep -f /launch_light_manager.sh > /dev/null 2>&1; do

force=""

if [ $cont -gt 9 ]; then
echo "Forcing kill /launch_light_manager.sh"
force="-9"
fi

ppid=$(ps | grep /launch_light_manager.sh | awk '{print $1}' | head -n 1)

pkill $force -P $ppid


if [ $? -eq 0 ]; then # il processo esisteva ed è stato killato
echo "Killed /launch_light_manager.sh "
fi

echo "Waiting for /launch_light_manager.sh death ..."

sleep 1
cont=$((cont+1))
done

}


function check() {

if [[ -f $FILE ]] ; then

# il file esiste

if ! pgrep -f /launch_light_manager.sh > /dev/null 2>&1 ; then
start_light_manager
fi

else

# il file non esiste
stop_light_manager

fi

}

trap "echo 'Ricevuto Signal SIGUSR1'; check" SIGUSR1

while true;
do
check
sleep 5 &
wait $!
done

0 comments on commit 606c7c2

Please sign in to comment.