[packages/mongodb] Multiple instances support added
jajcus
jajcus at pld-linux.org
Tue Aug 14 13:54:37 CEST 2012
commit 1a2080c03d42241a9ef4f1ad225d50aee2c020ba
Author: Jacek Konieczny <j.konieczny at eggsoft.pl>
Date: Tue Aug 14 13:46:21 2012 +0200
Multiple instances support added
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 | 47 ++++++++++++++++++++++++++++++++++++-----------
mongodb.spec | 16 ++++++++++++----
2 files changed, 48 insertions(+), 15 deletions(-)
---
diff --git a/mongodb.spec b/mongodb.spec
index 1b6324c..e5bb6af 100644
--- a/mongodb.spec
+++ b/mongodb.spec
@@ -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
diff --git a/mongodb.init b/mongodb.init
index a790a41..f9b8d53 100644
--- a/mongodb.init
+++ b/mongodb.init
@@ -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
More information about the pld-cvs-commit
mailing list