Skip to content

Instantly share code, notes, and snippets.

@yijia2413
Created November 26, 2018 03:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save yijia2413/b4570a0fbd2e51c72546862da4832119 to your computer and use it in GitHub Desktop.
Save yijia2413/b4570a0fbd2e51c72546862da4832119 to your computer and use it in GitHub Desktop.
Docker 内部程序crash自动重启,轻量级脚本
#!/bin/bash
set -ex
sleep_time=5
regex_name='server1.py'
cmd="python ${regex_name} &>> logs/test.log &"
bash -c "${cmd}"
# you can delete the following 5 lines
status=$?
if [ $status -ne 0 ]; then
echo "Failed to start my_first_process: $status"
exit $status
fi
while sleep ${sleep_time}; do
proc_exists=$(ps aux |grep ${regex_name} |grep -v grep | wc -l)
echo "inspecting server.py...${proc_exists}"
if [[ ${proc_exists} == '0' ]]; then
echo "server.py exited, restart now..."
bash -c "${cmd}"
fi
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment