diff options
author | Eric Hameleers <alien@slackware.com> | 2021-03-08 10:19:24 +0000 |
---|---|---|
committer | Eric Hameleers <alien@slackware.com> | 2021-03-08 10:19:24 +0000 |
commit | fd92a3b02428b8c542feadba6568aa38566f2595 (patch) | |
tree | a951a887866e427a4001ab1785b713d109cd9b70 /mongodb/build/rc.mongodb | |
parent | ecc209676905a5db87a20dfaab7813947004bbfc (diff) | |
download | asb-fd92a3b02428b8c542feadba6568aa38566f2595.tar.gz asb-fd92a3b02428b8c542feadba6568aa38566f2595.tar.xz |
mongodb: improved rc script using a config file instead of commandline parameters
Diffstat (limited to 'mongodb/build/rc.mongodb')
-rw-r--r-- | mongodb/build/rc.mongodb | 44 |
1 files changed, 25 insertions, 19 deletions
diff --git a/mongodb/build/rc.mongodb b/mongodb/build/rc.mongodb index 8f77680d..b82e0790 100644 --- a/mongodb/build/rc.mongodb +++ b/mongodb/build/rc.mongodb @@ -6,35 +6,41 @@ USR="mongo" GRP="mongo" - -DBPATH="/var/lib/mongo" -LOGFILE="/var/log/mongodb/mongod.log" -PID="/var/state/mongod.pid" SHELL="/bin/bash" -mongo_start() { - touch $LOGFILE - chown $USR:$GRP $LOGFILE - touch $PID - chown $USR:$GRP $PID +CONFIG="/etc/mongod.conf" +MONGOD_OPTS="" + +if [ ! -f ${CONFIG} ]; then + echo "MongoDB server can not start - ${CONFIG} not found!" + exit 1 +fi - su -l $USR -s $SHELL -c "/usr/bin/mongod \ - --dbpath=$DBPATH \ - --fork \ - --pidfilepath=$PID \ - --logpath=$LOGFILE \ - --logappend" \ - --noauth +PID=$(cat $CONFIG |grep pidFilePath: |cut -d: -f2- |tr -d '\t "') +if [ -z "$PID" ]; then + echo "MongoDB server configuration '${CONFIG}' incomplete!" + echo ">>Add 'pidfilepath: /path/to/pidfile' to 'processManagement:' section." + exit 1 +fi + +mongo_start() { + su -l ${USR} -s ${SHELL} \ + -c "/usr/bin/mongod --config=${CONFIG}" if [ $? -eq 0 ]; then echo "MongoDB server started successfully." else echo "MongoDB server failed to start, exiting now..." + rm -f ${PID} exit 1 fi } mongo_stop() { - kill -TERM $(cat $PID) + if [ ! -f "$PID" ]; then + echo "MongoDB server is not running." + exit 0 + fi + kill -TERM $(cat ${PID}) if [ $? -eq 0 ]; then echo "MongoDB server stopped successfully." rm -f $PID @@ -52,10 +58,10 @@ mongo_restart() { mongo_status() { PIDS=$(pidof mongod) - if [ "x$PIDS" = "x" ]; then + if ! echo ${PIDS} |grep -q $(cat ${PID}) ; then echo "MongoDB is not running!" else - echo "MongoDB is running at pid(s) ${PIDS}." + echo "MongoDB is running at pid $(cat ${PID})." fi } |