[mongodb] Fixes for mongod under systemd
Chris Lalancette
clalance at fedoraproject.org
Mon Sep 12 18:15:55 UTC 2011
commit 1ee86c4cf9659869975e2426724deb71e92f596c
Author: Chris Lalancette <clalance at redhat.com>
Date: Mon Sep 12 13:53:43 2011 -0400
Fixes for mongod under systemd
- Add a patch to fix the forking to play nice with systemd
(sent upstream, haven't heard back yet)
- Make the /var/run/mongodb directory owned by mongodb
Signed-off-by: Chris Lalancette <clalance at redhat.com>
mongod.service | 3 +-
mongodb-fix-fork.patch | 71 ++++++++++++++++++++++++++++++++++++++++++++++++
mongodb.spec | 10 ++++++-
3 files changed, 81 insertions(+), 3 deletions(-)
---
diff --git a/mongod.service b/mongod.service
index 543c74c..3e53a84 100644
--- a/mongod.service
+++ b/mongod.service
@@ -5,10 +5,9 @@ After=syslog.target network.target
[Service]
Type=forking
User=mongodb
-PIDFile=/var/run/mongodb.pid
+PIDFile=/var/run/mongodb/mongodb.pid
EnvironmentFile=/etc/sysconfig/mongod
ExecStart=/usr/bin/mongod $OPTIONS run
-ExecStop=/bin/kill -TERM $MAINPID
[Install]
WantedBy=multi-user.target
diff --git a/mongodb-fix-fork.patch b/mongodb-fix-fork.patch
new file mode 100644
index 0000000..3911388
--- /dev/null
+++ b/mongodb-fix-fork.patch
@@ -0,0 +1,71 @@
+diff -urp mongodb-src-r1.8.2.orig/db/cmdline.cpp mongodb-src-r1.8.2/db/cmdline.cpp
+--- mongodb-src-r1.8.2.orig/db/cmdline.cpp 2011-06-15 09:43:13.000000000 -0400
++++ mongodb-src-r1.8.2/db/cmdline.cpp 2011-09-12 10:44:59.962485040 -0400
+@@ -213,11 +213,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);
+@@ -251,6 +274,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")) {
+@@ -260,7 +298,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.spec b/mongodb.spec
index c7a1893..07eab57 100644
--- a/mongodb.spec
+++ b/mongodb.spec
@@ -1,7 +1,7 @@
%global daemon mongod
Name: mongodb
Version: 1.8.2
-Release: 6%{?dist}
+Release: 7%{?dist}
Summary: High-performance, schema-free document-oriented database
Group: Applications/Databases
License: AGPLv3 and zlib and ASL 2.0
@@ -17,6 +17,7 @@ Source3: %{name}.logrotate
Source4: %{name}.conf
Patch1: mongodb-no-term.patch
Patch2: mongodb-src-r1.8.2-js.patch
+Patch3: mongodb-fix-fork.patch
BuildRequires: python-devel
BuildRequires: scons
@@ -89,6 +90,7 @@ software, default configuration files, and init scripts.
%setup -q -n mongodb-src-r%{version}
%patch1 -p1
%patch2 -p1
+%patch3 -p1
# spurious permissions
chmod -x README
@@ -122,6 +124,7 @@ rm -f %{buildroot}%{_libdir}/libmongoclient.a
mkdir -p %{buildroot}%{_sharedstatedir}/%{name}
mkdir -p %{buildroot}%{_localstatedir}/log/%{name}
+mkdir -p %{buildroot}%{_localstatedir}/run/%{name}
mkdir -p %{buildroot}/lib/systemd/system
mkdir -p %{buildroot}%{_sysconfdir}/sysconfig
@@ -194,6 +197,7 @@ fi
%{_mandir}/man1/mongos.1*
%dir %attr(0755, %{name}, root) %{_sharedstatedir}/%{name}
%dir %attr(0755, %{name}, root) %{_localstatedir}/log/%{name}
+%dir %attr(0755, %{name}, root) %{_localstatedir}/run/%{name}
%config(noreplace) %{_sysconfdir}/logrotate.d/%{name}
%config(noreplace) %{_sysconfdir}/mongodb.conf
%config(noreplace) %{_sysconfdir}/sysconfig/%{daemon}
@@ -203,6 +207,10 @@ fi
%{_includedir}/mongo
%changelog
+* Mon Sep 12 2011 Chris Lalancette <clalance at redhat.com> - 1.8.2-7
+- Add a patch to fix the forking to play nice with systemd
+- Make the /var/run/mongodb directory owned by mongodb
+
* Thu Jul 28 2011 Chris Lalancette <clalance at redhat.com> - 1.8.2-6
- BZ 725601 - fix the javascript engine to not hang (thanks to Eduardo Habkost)
More information about the scm-commits
mailing list