]> git.pld-linux.org Git - packages/mongodb.git/commitdiff
Multiple instances support added
authorJacek Konieczny <j.konieczny@eggsoft.pl>
Tue, 14 Aug 2012 11:46:21 +0000 (13:46 +0200)
committerJacek Konieczny <jajcus@jajcus.net>
Tue, 14 Aug 2012 11:46:21 +0000 (13:46 +0200)
Now multiple MongoDB instances may be started by our mongod init script.
Each instance is configured via /etc/mongod/${name}.conf.

Old configuration from /etc/mongod.conf is moved to
/etc/mongod/default.conf on upgrade. Database, pid file and log file
locations are not changed for the default instance.

Non-default instances have their pid file changed to
/var/run/mongod-${name}.pid. Database and log file locations are defined
in the /etc/mongod/*.conf files and it is the administrator
responsibility to set them right.

mongodb.init
mongodb.spec

index a790a41eb737f4e2cd78f03c8919e9571aac6005..f9b8d5393346fc6addb0ab7d4490aeaeb97b43e8 100644 (file)
@@ -4,7 +4,7 @@
 #
 # chkconfig:   345 60 40
 #
-# description: mongod is a cache daemon.
+# description: mongod is a NoSQL database daemon.
 #
 # processname: mongod
 # pidfile:      /var/run/mongod.pid
@@ -38,7 +38,6 @@ else
 fi
 
 MONGOD_BIN="/usr/bin/mongod"
-MONGOD_LOGFILE="/var/log/mongo/mongod.log"
 MONGOD_PIDFILE="/var/run/mongod.pid"
 MONGOD_CONFIG="/etc/sysconfig/mongod"
 
@@ -55,11 +54,21 @@ start() {
                return
        fi
 
-       msg_starting "mongod"
-       daemon --pidfile $MONGOD_PIDFILE --user $MONGOD_USER \
-               $MONGOD_BIN --config /etc/mongod.conf run
-       ret=$?
-       [ $ret = 0 ] || RETVAL=$?
+       started=0
+       for config in /etc/mongod/*.conf ; do
+               instance=$(basename "$config" .conf)
+               msg_starting "mongod '$instance' instance"
+               if [ "$instance" = "default" ] ; then
+                       pidfile="$MONGOD_PIDFILE"
+               else
+                       pidfile="${MONGOD_PIDFILE%.pid}-$instance.log"
+               fi
+               daemon --pidfile "$pidfile" --user $MONGOD_USER \
+                       $MONGOD_BIN --config "$config" run
+               [ $? -eq 0 ] && started=$(($started + 1))
+       done
+       # at least one started - the service is running
+       [ $started -eq 0 ] && RETVAL=1
        [ $RETVAL -eq 0 ] && touch /var/lock/subsys/mongod
 }
 
@@ -69,8 +78,16 @@ stop() {
                return
        fi
 
-       msg_stopping "mongod"
-       killproc --pidfile $MONGOD_PIDFILE mongod
+       for config in /etc/mongod/*.conf ; do
+               instance=$(basename "$config" .conf)
+               msg_stopping "mongod '$instance' instance"
+               if [ "$instance" = "default" ] ; then
+                       pidfile="$MONGOD_PIDFILE"
+               else
+                       pidfile="${MONGOD_PIDFILE%.pid}-$instance.log"
+               fi
+               killproc --pidfile "$pidfile" mongod
+       done
        rm -f /var/lock/subsys/mongod >/dev/null 2>&1
 }
 
@@ -92,8 +109,16 @@ reload() {
                return
        fi
 
-       msg_reloading "mongod"
-       killproc --pidfile $MONGOD_PIDFILE mongod -HUP
+       for config in /etc/mongod/*.conf ; do
+               instance=$(basename "$config" .conf)
+               msg_reloading "mongod '$instance' instance"
+               if [ "$instance" = "default" ] ; then
+                       pidfile="$MONGOD_PIDFILE"
+               else
+                       pidfile="${MONGOD_PIDFILE%.pid}-$instance.log"
+               fi
+               killproc --pidfile "$pidfile" mongod -HUP
+       done
 }
 
 RETVAL=0
index 1b6324ce88f81aa307fb4387e243cb83ea70fb85..e5bb6af36cc30ee8295f153fe9aa642c65360c1a 100644 (file)
@@ -3,7 +3,7 @@ Summary:        MongoDB client shell and tools
 Summary(pl.UTF-8):     Powłoka kliencka i narzędzia dla bazy danych MongoDB
 Name:          mongodb
 Version:       2.0.6
-Release:       2
+Release:       3
 License:       AGPL v3
 Group:         Applications/Databases
 Source0:       http://downloads.mongodb.org/src/%{name}-src-r%{version}.tar.gz
@@ -153,7 +153,7 @@ find -type f -executable | xargs chmod a-x
 %install
 rm -rf $RPM_BUILD_ROOT
 install -d $RPM_BUILD_ROOT{%{_sysconfdir},%{_mandir}/man1} \
-       $RPM_BUILD_ROOT/etc/{logrotate.d,rc.d/init.d,sysconfig} \
+       $RPM_BUILD_ROOT/etc/{logrotate.d,rc.d/init.d,sysconfig,mongod} \
        $RPM_BUILD_ROOT%{_var}/{lib,log}/mongo
 
 # XXX: scons is so great, recompiles everything here!
@@ -167,7 +167,7 @@ install -d $RPM_BUILD_ROOT{%{_sysconfdir},%{_mandir}/man1} \
 cp -p %{SOURCE1} $RPM_BUILD_ROOT/etc/logrotate.d/mongod
 install -p %{SOURCE2} $RPM_BUILD_ROOT/etc/rc.d/init.d/mongod
 cp -p rpm/mongod.sysconfig $RPM_BUILD_ROOT/etc/sysconfig/mongod
-cp -p rpm/mongod.conf $RPM_BUILD_ROOT%{_sysconfdir}/mongod.conf
+cp -p rpm/mongod.conf $RPM_BUILD_ROOT%{_sysconfdir}/mongod/default.conf
 cp -p debian/*.1 $RPM_BUILD_ROOT%{_mandir}/man1
 
 touch $RPM_BUILD_ROOT%{_var}/log/mongo/mongod.log
@@ -198,6 +198,13 @@ if [ "$1" = "0" ]; then
        %groupremove mongod
 fi
 
+%triggerpostun server -- %{name}-server < 2.0.6-3
+if [ -f %{_sysconfdir}/mongod.conf.rpmsave ] ; then
+       cp -f %{_sysconfdir}/mongod/default.conf{,.rpmnew} || :
+       echo "Moving %{_sysconfdir}/mongod.conf to %{_sysconfdir}/mongod/default.conf"
+       mv -f %{_sysconfdir}/mongod.conf.rpmsave %{_sysconfdir}/mongod/default.conf
+fi
+
 %files
 %defattr(644,root,root,755)
 %doc README GNU-AGPL-3.0.txt
@@ -236,7 +243,8 @@ fi
 %files server
 %defattr(644,root,root,755)
 #%dir %{_sysconfdir}
-%config(noreplace) %verify(not md5 mtime size) %{_sysconfdir}/mongod.conf
+%dir %{_sysconfdir}/mongod
+%config(noreplace) %verify(not md5 mtime size) %{_sysconfdir}/mongod/default.conf
 %attr(754,root,root) /etc/rc.d/init.d/mongod
 %config(noreplace) %verify(not md5 mtime size) /etc/sysconfig/mongod
 %config(noreplace) /etc/logrotate.d/mongod
This page took 0.087489 seconds and 4 git commands to generate.