systemd fixes

This commit is contained in:
David Teigland 2012-11-06 14:03:24 -06:00
parent cb11b79929
commit 768d5dd8ed
4 changed files with 80 additions and 142 deletions

View File

@ -1,27 +0,0 @@
From 9f47804b2e8a0bc822b038427562d3a481c28693 Mon Sep 17 00:00:00 2001
From: David Teigland <teigland@redhat.com>
Date: Mon, 23 Jul 2012 10:58:50 -0500
Subject: [PATCH 1/2] daemon: include resource.h
for rlimits
Signed-off-by: David Teigland <teigland@redhat.com>
---
src/main.c | 1 +
1 file changed, 1 insertion(+)
diff --git a/src/main.c b/src/main.c
index d5f4d04..fdf068d 100644
--- a/src/main.c
+++ b/src/main.c
@@ -32,6 +32,7 @@
#include <sys/mman.h>
#include <sys/mman.h>
#include <sys/utsname.h>
+#include <sys/resource.h>
#include <uuid/uuid.h>
#define EXTERN
--
1.7.10.1.362.g242cab3

View File

@ -0,0 +1,57 @@
From 337c30353d650bd02bd1203b7859124926dfef71 Mon Sep 17 00:00:00 2001
From: David Teigland <teigland@redhat.com>
Date: Mon, 5 Nov 2012 15:53:40 -0600
Subject: [PATCH] fix systemd service files
add [Unit] and disable the cgroup stuff to avoid
the set_scheduler failures
Signed-off-by: David Teigland <teigland@redhat.com>
---
init.d/fence_sanlockd.service | 1 +
init.d/sanlock.service | 2 ++
init.d/wdmd.service | 2 ++
3 files changed, 5 insertions(+)
diff --git a/init.d/fence_sanlockd.service b/init.d/fence_sanlockd.service
index 873da59..f2d655b 100644
--- a/init.d/fence_sanlockd.service
+++ b/init.d/fence_sanlockd.service
@@ -1,3 +1,4 @@
+[Unit]
Description=daemon for fence_sanlock agent
After=syslog.target wdmd.service sanlock.service
Before=corosync.service
diff --git a/init.d/sanlock.service b/init.d/sanlock.service
index ff4a3e7..f026fe0 100644
--- a/init.d/sanlock.service
+++ b/init.d/sanlock.service
@@ -1,8 +1,10 @@
+[Unit]
Description=Shared Storage Lease Manager
After=syslog.target wdmd.service
[Service]
Type=forking
+ControlGroup=cpu:/
ExecStart=/lib/systemd/systemd-sanlock start
ExecStop=/lib/systemd/systemd-sanlock stop
diff --git a/init.d/wdmd.service b/init.d/wdmd.service
index 88d00b6..efe46bf 100644
--- a/init.d/wdmd.service
+++ b/init.d/wdmd.service
@@ -1,8 +1,10 @@
+[Unit]
Description=Watchdog Multiplexing Daemon
After=syslog.target
[Service]
Type=forking
+ControlGroup=cpu:/
ExecStart=/lib/systemd/systemd-wdmd start
ExecStop=/lib/systemd/systemd-wdmd stop
--
1.7.10.1.362.g242cab3

View File

@ -1,104 +0,0 @@
From a80c4a0d0b3cd1cb9a10fb8b681c48bf639ca9d1 Mon Sep 17 00:00:00 2001
From: David Teigland <teigland@redhat.com>
Date: Tue, 24 Jul 2012 09:21:30 -0500
Subject: [PATCH 2/2] daemon: fix lockfile ownership
make the owner sanlock uid/gid instead of root
so the daemon continues to have access to it
after the process drops root privileges.
Signed-off-by: David Teigland <teigland@redhat.com>
---
src/lockfile.c | 18 ++++++++++++++++--
src/lockfile.h | 2 +-
src/main.c | 8 ++++----
3 files changed, 21 insertions(+), 7 deletions(-)
diff --git a/src/lockfile.c b/src/lockfile.c
index cd4d4e2..129d956 100644
--- a/src/lockfile.c
+++ b/src/lockfile.c
@@ -29,7 +29,7 @@
#include "log.h"
#include "lockfile.h"
-int lockfile(const char *dir, const char *name)
+int lockfile(const char *dir, const char *name, int uid, int gid)
{
char path[PATH_MAX];
char buf[16];
@@ -38,13 +38,20 @@ int lockfile(const char *dir, const char *name)
int fd, rv;
old_umask = umask(0022);
- rv = mkdir(SANLK_RUN_DIR, 0777);
+ rv = mkdir(SANLK_RUN_DIR, 0775);
if (rv < 0 && errno != EEXIST) {
umask(old_umask);
return rv;
}
umask(old_umask);
+ rv = chown(SANLK_RUN_DIR, uid, gid);
+ if (rv < 0) {
+ log_error("lockfile chown error %s: %s",
+ SANLK_RUN_DIR, strerror(errno));
+ return rv;
+ }
+
snprintf(path, PATH_MAX, "%s/%s", dir, name);
fd = open(path, O_CREAT|O_WRONLY|O_CLOEXEC, 0666);
@@ -83,6 +90,13 @@ int lockfile(const char *dir, const char *name)
goto fail;
}
+ rv = fchown(fd, uid, gid);
+ if (rv < 0) {
+ log_error("lockfile fchown error %s: %s",
+ path, strerror(errno));
+ goto fail;
+ }
+
return fd;
fail:
close(fd);
diff --git a/src/lockfile.h b/src/lockfile.h
index 1702d71..57bbcec 100644
--- a/src/lockfile.h
+++ b/src/lockfile.h
@@ -9,7 +9,7 @@
#ifndef __LOCKFILE_H__
#define __LOCKFILE_H__
-int lockfile(const char *dir, const char *name);
+int lockfile(const char *dir, const char *name, int uid, int gid);
void unlink_lockfile(int fd, const char *dir, const char *name);
#endif
diff --git a/src/main.c b/src/main.c
index fdf068d..8e39855 100644
--- a/src/main.c
+++ b/src/main.c
@@ -1558,14 +1558,14 @@ static int do_daemon(void)
setup_logging();
+ fd = lockfile(SANLK_RUN_DIR, SANLK_LOCKFILE_NAME, com.uid, com.gid);
+ if (fd < 0)
+ return fd;
+
setup_host_name();
setup_groups();
- fd = lockfile(SANLK_RUN_DIR, SANLK_LOCKFILE_NAME);
- if (fd < 0)
- return fd;
-
log_error("sanlock daemon started %s aio %d %d renew %d %d host %s time %llu",
RELEASE_VERSION,
main_task.use_aio, main_task.io_timeout_seconds,
--
1.7.10.1.362.g242cab3

View File

@ -1,6 +1,6 @@
Name: sanlock
Version: 2.6
Release: 1%{?dist}
Release: 3%{?dist}
Summary: A shared disk lock manager
Group: System Environment/Base
@ -8,11 +8,16 @@ License: GPLv2 and GPLv2+ and LGPLv2+
URL: https://fedorahosted.org/sanlock/
BuildRoot: %{_tmppath}/%{name}-%{version}-%{release}-root-%(%{__id_u} -n)
BuildRequires: libblkid-devel libaio-devel python python-devel
%if 0%{?fedora} >= 16 || 0%{?rhel} >= 7
BuildRequires: systemd-units
%endif
Requires: %{name}-lib = %{version}-%{release}
Requires(pre): /usr/sbin/groupadd
Requires(pre): /usr/sbin/useradd
Source0: https://fedorahosted.org/releases/s/a/sanlock/%{name}-%{version}.tar.gz
Patch0: 0001-fix-systemd-service-files.patch
%description
sanlock uses disk paxos to manage leases on shared storage.
Hosts connected to a common SAN can use this to synchronize their
@ -20,6 +25,7 @@ access to the shared disks.
%prep
%setup -q
%patch0 -p1 -b .0001-fix-systemd-service-files.patch
%build
# upstream does not require configure
@ -44,7 +50,7 @@ make -C fence_sanlock \
install LIBDIR=%{_libdir} \
DESTDIR=$RPM_BUILD_ROOT
%if 0%{?fedora} >= 16
%if 0%{?fedora} >= 16 || 0%{?rhel} >= 7
install -D -m 0755 init.d/sanlock $RPM_BUILD_ROOT/lib/systemd/systemd-sanlock
install -D -m 0644 init.d/sanlock.service $RPM_BUILD_ROOT/%{_unitdir}/sanlock.service
install -D -m 0755 init.d/wdmd $RPM_BUILD_ROOT/lib/systemd/systemd-wdmd
@ -85,7 +91,7 @@ getent passwd sanlock > /dev/null || /usr/sbin/useradd \
%post
if [ $1 -eq 1 ] ; then
%if 0%{?fedora} >= 16
%if 0%{?fedora} >= 16 || 0%{?rhel} >= 7
/bin/systemctl daemon-reload >/dev/null 2>&1 || :
%else
/sbin/chkconfig --add sanlock
@ -95,7 +101,7 @@ fi
%preun
if [ $1 = 0 ]; then
%if 0%{?fedora} >= 16
%if 0%{?fedora} >= 16 || 0%{?rhel} >= 7
/bin/systemctl --no-reload sanlock.service > /dev/null 2>&1 || :
/bin/systemctl --no-reload wdmd.service > /dev/null 2>&1 || :
/bin/systemctl stop sanlock.service > /dev/null 2>&1 || :
@ -110,7 +116,7 @@ fi
%postun
if [ $1 -ge 1 ] ; then
%if 0%{?fedora} >= 16
%if 0%{?fedora} >= 16 || 0%{?rhel} >= 7
/bin/systemctl try-restart sanlock.service >/dev/null 2>&1 || :
/bin/systemctl try-restart wdmd.service >/dev/null 2>&1 || :
%else
@ -121,7 +127,7 @@ fi
%files
%defattr(-,root,root,-)
%if 0%{?fedora} >= 16
%if 0%{?fedora} >= 16 || 0%{?rhel} >= 7
/lib/systemd/systemd-sanlock
/lib/systemd/systemd-wdmd
%{_unitdir}/sanlock.service
@ -132,6 +138,7 @@ fi
%endif
%{_sbindir}/sanlock
%{_sbindir}/wdmd
%dir /etc/wdmd.d
%dir %attr(-,sanlock,sanlock) %{_localstatedir}/run/sanlock
%{_mandir}/man8/wdmd*
%{_mandir}/man8/sanlock*
@ -206,7 +213,7 @@ daemon for using sanlock and wdmd as a cluster fence agent.
%files -n fence-sanlock
%defattr(-,root,root,-)
%if 0%{?fedora} >= 16
%if 0%{?fedora} >= 16 || 0%{?rhel} >= 7
/lib/systemd/systemd-fence_sanlockd
%{_unitdir}/fence_sanlockd.service
%else
@ -214,14 +221,13 @@ daemon for using sanlock and wdmd as a cluster fence agent.
%endif
%{_sbindir}/fence_sanlock
%{_sbindir}/fence_sanlockd
%dir /etc/wdmd.d
%dir %attr(-,root,root) %{_localstatedir}/run/fence_sanlock
%dir %attr(-,root,root) %{_localstatedir}/run/fence_sanlockd
%{_mandir}/man8/fence_sanlock*
%post -n fence-sanlock
if [ $1 -eq 1 ] ; then
%if 0%{?fedora} >= 16
%if 0%{?fedora} >= 16 || 0%{?rhel} >= 7
/bin/systemctl daemon-reload >/dev/null 2>&1 || :
%else
/sbin/chkconfig --add fence_sanlockd
@ -231,7 +237,7 @@ fi
%preun -n fence-sanlock
if [ $1 = 0 ]; then
%if 0%{?fedora} >= 16
%if 0%{?fedora} >= 16 || 0%{?rhel} >= 7
/bin/systemctl --no-reload fence_sanlockd.service > /dev/null 2>&1 || :
%else
/sbin/service fence_sanlockd stop > /dev/null 2>&1
@ -241,7 +247,7 @@ fi
%postun -n fence-sanlock
if [ $1 -ge 1 ] ; then
%if 0%{?fedora} >= 16
%if 0%{?fedora} >= 16 || 0%{?rhel} >= 7
/bin/systemctl try-restart fence_sanlockd.service > /dev/null 2>&1 || :
%else
/sbin/service fence_sanlockd condrestart >/dev/null 2>&1 || :
@ -249,6 +255,12 @@ if [ $1 -ge 1 ] ; then
fi
%changelog
* Mon Nov 05 2012 David Teigland <teigland@redhat.com> - 2.6-3
- fix systemd service files and install them on rhel7
* Wed Oct 24 2012 David Teigland <teigland@redhat.com> - 2.6-2
- move creation of /etc/wdmd.d
* Tue Oct 09 2012 David Teigland <teigland@redhat.com> - 2.6-1
- Update to sanlock-2.6