[mongodb/f15] Fix mongodb startup with systemd
Chris Lalancette
clalance at fedoraproject.org
Wed Sep 14 19:56:25 UTC 2011
commit ad4d773f594394afb6be6f9f4c785c3e98856c12
Author: Chris Lalancette <clalance at redhat.com>
Date: Wed Sep 14 15:09:34 2011 -0400
Fix mongodb startup with systemd
Signed-off-by: Chris Lalancette <clalance at redhat.com>
mongodb-fix-fork.patch | 71 ++++++++++++++++++++++++++++++++++++++++++++++++
mongodb.init | 4 +-
mongodb.spec | 7 ++++-
3 files changed, 79 insertions(+), 3 deletions(-)
---
diff --git a/mongodb-fix-fork.patch b/mongodb-fix-fork.patch
new file mode 100644
index 0000000..d012693
--- /dev/null
+++ b/mongodb-fix-fork.patch
@@ -0,0 +1,71 @@
+diff -urp mongodb-src-r1.8.0.orig/db/cmdline.cpp mongodb-src-r1.8.0/db/cmdline.cpp
+--- mongodb-src-r1.8.0.orig/db/cmdline.cpp 2011-03-16 11:33:30.000000000 -0400
++++ mongodb-src-r1.8.0/db/cmdline.cpp 2011-09-14 15:10:20.102165127 -0400
+@@ -198,11 +198,34 @@ namespace mongo {
+ cout.flush();
+ cerr.flush();
+
++ int pipes[2];
++ if (pipe(pipes) < 0) {
++ cout << "Can't create pipe while forking server process: " << strerror(errno) << endl;
++ ::exit(-1);
++ }
++
+ pid_t c = fork();
+ if ( c ) {
++ char buf[1];
++ // parent; here, we close out the write side of the pipe and
++ // block on a single byte read from the final child to tell us
++ // when it is done
++ close(pipes[1]);
++ ssize_t bytes = read(pipes[0], buf, 1);
++ close(pipes[0]);
++ if (bytes != 1) {
++ // in this case, the child failed to start for some reason.
++ // we assume that the child wrote the error information, so
++ // all we have to do is exit with an error code
++ ::exit(-1);
++ }
++
+ _exit(0);
+ }
+
++ // in the child, close out the read end of the pipe
++ close(pipes[0]);
++
+ if ( chdir("/") < 0 ) {
+ cout << "Cant chdir() while forking server process: " << strerror(errno) << endl;
+ ::exit(-1);
+@@ -236,6 +259,21 @@ namespace mongo {
+
+ setupCoreSignals();
+ setupSignals( true );
++
++ if ( params.count("pidfilepath")) {
++ writePidFile( params["pidfilepath"].as<string>() );
++ }
++
++ ssize_t bytes = write(pipes[1], "a", 1);
++ close(pipes[1]);
++ if (bytes < 0) {
++ cout << "Can't write to the parent pipe: " << strerror(errno) << endl;
++ ::exit(-1);
++ }
++ else if (bytes != 1) {
++ cout << "Can't write to the parent pipe: unknown error" << endl;
++ ::exit(-1);
++ }
+ }
+ #endif
+ if (params.count("logpath")) {
+@@ -245,7 +283,9 @@ namespace mongo {
+ initLogging( logpath , params.count( "logappend" ) );
+ }
+
+- if ( params.count("pidfilepath")) {
++ // if this was a forking configuration, the pidfile was written above;
++ // if not, we have to write it here
++ if ( !params.count("fork") && params.count("pidfilepath")) {
+ writePidFile( params["pidfilepath"].as<string>() );
+ }
+
diff --git a/mongodb.init b/mongodb.init
index c8c1cda..52bd8f4 100644
--- a/mongodb.init
+++ b/mongodb.init
@@ -21,7 +21,7 @@ lockfile="/var/lock/subsys/mongod"
start() {
[ -x $exec ] || exit 5
echo -n $"Starting $prog: "
- daemon --user mongodb "$exec --quiet $options run >> $logfile 2>&1 &"
+ daemon --user mongodb "$exec --quiet $options run >> $logfile 2>&1"
retval=$?
echo
[ $retval -eq 0 ] && touch $lockfile
@@ -90,4 +90,4 @@ case "$1" in
echo $"Usage: $0 {start|stop|status|restart|condrestart|try-restart|reload|force-reload}"
exit 2
esac
-exit $?
+exit $retval
diff --git a/mongodb.spec b/mongodb.spec
index 026e3df..6039be6 100644
--- a/mongodb.spec
+++ b/mongodb.spec
@@ -4,7 +4,7 @@
%global daemon mongod
Name: mongodb
Version: 1.8.0
-Release: 4%{?dist}
+Release: 5%{?dist}
Summary: High-performance, schema-free document-oriented database
Group: Applications/Databases
License: AGPLv3 and zlib and ASL 2.0
@@ -21,6 +21,7 @@ BuildRoot: %{_tmppath}/%{name}-%{version}-%{release}-root-%(%{__id_u} -n)
Patch0: mongodb-src-r1.8.0-js.patch
Patch1: mongodb-no-term.patch
+Patch2: mongodb-fix-fork.patch
BuildRequires: python-devel
BuildRequires: scons
@@ -93,6 +94,7 @@ software, default configuration files, and init scripts.
%setup -q -n mongodb-src-r%{version}
%patch0 -p1 -b .js185
%patch1 -p1
+%patch2 -p1
# spurious permissions
chmod -x README
@@ -212,6 +214,9 @@ fi
%{_includedir}/mongo
%changelog
+* Wed Sep 14 2011 Chris Lalancette <clalance at redhat.com> - 1.8.0-5
+- Fix the js 1.8.5 patch to work properly
+
* Fri Jul 29 2011 Chris Lalancette <clalance at redhat.com> - 1.8.0-4
- Fix the js 1.8.5 patch to work properly
More information about the scm-commits
mailing list