Update README.md

This commit is contained in:
chiu 2020-09-28 15:03:48 +08:00
parent 72962672b9
commit e236815388
1 changed files with 63 additions and 8 deletions

View File

@ -593,34 +593,89 @@ start)
fi fi
done done
if [ $COUNTER == 0 ]; then if [ $COUNTER == 0 ]; then
echo "starting mongo."
sudo mongod --config /etc/mongod.conf & sudo mongod --config /etc/mongod.conf &
exit 0 exit 0
else
echo "mongo is already running."
fi fi
fi fi
;; ;;
stop) stop)
echo "stoping mongo."
if [ -f "/var/lib/mongodb/mongod.lock" ]; then if [ -f "/var/lib/mongodb/mongod.lock" ]; then
sudo kill -s TERM `cat /var/lib/mongodb/mongod.lock` sudo kill -s TERM `cat /var/lib/mongodb/mongod.lock`
fi
sudo rm -f /var/lib/mongodb/mongod.lock sudo rm -f /var/lib/mongodb/mongod.lock
else
pid=`ps aux | grep mongod | grep -v 'service' | grep -v 'grep' | grep -v '/etc/init.d' | awk '{print $2}'`;
for i in $pid
do
kill -s TERM $i
done
fi
;; ;;
restart|reload) restart|reload)
echo "stoping mongo."
if [ -f "/var/lib/mongodb/mongod.lock" ]; then if [ -f "/var/lib/mongodb/mongod.lock" ]; then
sudo kill -s TERM `cat /var/lib/mongodb/mongod.lock` sudo kill -s TERM `cat /var/lib/mongodb/mongod.lock`
fi
sudo rm -f /var/lib/mongodb/mongod.lock sudo rm -f /var/lib/mongodb/mongod.lock
else
pid=`ps aux | grep mongod | grep -v 'service' | grep -v 'grep' | grep -v '/etc/init.d' | awk '{print $2}'`;
for i in $pid
do
kill -s TERM $i
done
fi
sudo mongod --config /etc/mongod.conf & sudo mongod --config /etc/mongod.conf &
exit 0 exit 0
;; ;;
status) status)
if [ -f "/var/lib/mongodb/mongod.lock" ]; then if [ -f "/var/lib/mongodb/mongod.lock" ]; then
if [ -f "/proc/$(cat /var/lib/mongodb/mongod.lock)/status" ]; then pid=`cat /var/lib/mongodb/mongod.lock`
COUNTER=0
ERRORPID=0
for i in $pid
do
if [ -f "/proc/$i/status" ]; then
COUNTER=$((COUNTER+1))
else
ERRORPID=1
fi
done
if [ $ERRORPID == 0 ] && [ $COUNTER != 0 ]; then
echo "mongo is already running" echo "mongo is already running"
else else
echo "mongo is not running" COUNTER=0
pid=`ps aux | grep mongod | grep -v 'service' | grep -v 'grep' | grep -v '/etc/init.d' | awk '{print $2}'`;
cat /dev/null > /var/lib/mongodb/mongod.lock;
for i in $pid
do
if [ -f "/proc/$i/status" ]; then
echo "$i" >> /var/lib/mongodb/mongod.lock;
COUNTER=$((COUNTER+1))
fi
done
if [ $COUNTER == 0 ]; then
echo "mongo is not running."
else
echo "mongo is already running."
fi
fi fi
else else
echo "mongo is not running" COUNTER=0
pid=`ps aux | grep mongod | grep -v 'service' | grep -v 'grep' | grep -v '/etc/init.d' | awk '{print $2}'`;
for i in $pid
do
if [ -f "/proc/$i/status" ]; then
echo "$i" >> /var/lib/mongodb/mongod.lock;
COUNTER=$((COUNTER+1))
fi
done
if [ $COUNTER == 0 ]; then
echo "mongo is not running."
else
echo "mongo is already running."
fi
fi fi
esac esac
``` ```