Created
November 29, 2018 07:14
-
-
Save tuantranf/00ef6719019fc7c0feca7115a04a6e9d to your computer and use it in GitHub Desktop.
Run a shell script with pid file
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
if [ ! -d "tmp" ]; then | |
echo "tmp not exist. Creating tmp" | |
mkdir -p tmp | |
fi | |
PIDFILE=tmp/run.pid | |
if [ -f $PIDFILE ] | |
then | |
PID=$(cat $PIDFILE) | |
ps -p $PID > /dev/null 2>&1 | |
if [ $? -eq 0 ] | |
then | |
echo "Process already running" | |
exit 1 | |
else | |
## Process not found assume not running | |
echo $$ > $PIDFILE | |
if [ $? -ne 0 ] | |
then | |
echo "Could not create PID file" | |
exit 1 | |
fi | |
fi | |
else | |
echo $$ > $PIDFILE | |
if [ $? -ne 0 ] | |
then | |
echo "Could not create PID file" | |
exit 1 | |
fi | |
fi | |
python3.6 test.py | |
rm $PIDFILE |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment