Skip to content

Instantly share code, notes, and snippets.

@xmasotto
Created July 25, 2014 18:04
Show Gist options
  • Save xmasotto/1ed02114502b3f752b9e to your computer and use it in GitHub Desktop.
Save xmasotto/1ed02114502b3f752b9e to your computer and use it in GitHub Desktop.
Mongo Connector init script (tested on debian, centos, fedora)
#!/bin/bash
#
# mongo-connector Start Mongo Connector
#
# chkconfig: 345 90 25
# description: Mongo Connector replicates data from MongoDB to external
# database systems.
### BEGIN INIT INFO
# Provides: mongo-connector
# Default-Start: 3 4 5
# Default-Stop: 0 1 6
# Required-Start:
# Required-Stop:
# Short-Description: Start up Mongo Connector
# Description: Mongo Connector replicates data from MongoDB to external
# database systems.
### END INIT INFO
# source function library
DEBIAN=
if [ -f /lib/lsb/init-functions ]; then
DEBIAN=1
. /lib/lsb/init-functions
else
. /etc/rc.d/init.d/functions
fi
RETVAL=0
pidfile=/var/run/mongo-connector.pid
config=/etc/mongo-connector.json
stdout=/var/log/mongo-connector/stdout
stderr=/var/log/mongo-connector/stderr
mc="/usr/bin/python -m mongo_connector.connector \
-c $config 1> $stdout 2> $stderr & \
echo "'$!'" > $pidfile"
start()
{
echo "starting mongo-connector "
if [ "$DEBIAN" ]; then
/sbin/start-stop-daemon --start --exec /bin/sh -p $pidfile -- -c "$mc"
else
daemon --pidfile $pidfile "$mc"
fi
RETVAL=$?
if [ $RETVAL -eq 0 ]; then
echo "done."
else
echo "failed. Please check exit code and logs for more information"
fi
return $RETVAL
}
stop()
{
echo "stopping mongo-connector: "
killproc -p $pidfile
RETVAL=$?
if [ $RETVAL -eq 0 ]; then
echo "done."
rm -f $lockfile
else
echo "failed. Please check exit code and logs for more information"
fi
return $RETVAL
}
restart() {
$0 stop
$0 start
}
check_status() {
if [ "$DEBIAN" ]; then
echo -n "mongo-connector "
status_of_proc -p $pidfile mongo-connector
else
status -p $pidfile mongo-connector
fi
}
case "$1" in
start)
start
;;
stop)
stop
;;
restart)
restart
;;
status)
check_status
;;
*)
echo $"Usage: $0 {start|stop|restart|status}"
RETVAL=2
esac
exit $RETVAL
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment