From: Nathan Cutler <ncutler@suse.com>
Date: Wed, 27 May 2015 11:48:57 +0200
Subject: [PATCH] logrotate: fixes for systemd

This is a combination of 4 commits:

3109a8855291b7ee4270c72cf92d1a44b9ae2692 logrotate: fixes for systemd

Before this patch, the command 'logrotate -f /etc/logrotate.d/ceph'
was generating an error "Failed to reload ceph.target: Job type reload is not
applicable for unit ceph.target".

https://bugzilla.suse.com/show_bug.cgi?id=931451 Fixes: bnc#931451

Signed-off-by: Nathan Cutler <ncutler@suse.com>

d35cbfe411704d41c2cdada7e24fe9c09acbe956 logrotate: check for active systemd services

Before we issue systemctl reload, check that there is at least
one active ceph* service.

Signed-off-by: Nathan Cutler <ncutler@suse.com>

1e85f63185b2a39dc1f613468f4bd5d95f6e9654 src/logrotate.conf: add hyphen to systemctl reload

Without the hyphen, the systemctl reload command matches ceph.target,
which generates an undesirable error message.

Signed-off-by: Nathan Cutler <ncutler@suse.com>

145364bbd933da8c1f384bea41f1b5cf37e9e082 logrotate: fix log rotation with systemd

systemctl does not have a nice way to enumerate (active) units so we can
reload them.  On centos7, the is-active wildcard syntax does not appear to
be supported.  On fedora 22, it prints the state only but not which unit
the state belongs to.

Simply killall -1 instead.

Signed-off-by: Sage Weil <sage@redhat.com>

Conflicts:
	src/logrotate.conf
	src/rgw/logrotate.conf
            Ignore some Debian-specific differences

(cherry picked from commit 65d481d57f59a3756a3df652ef6229b4b2c5c178)
---
 src/logrotate.conf            | 2 ++
 src/rgw/logrotate.conf        | 3 +++
 systemd/ceph-mds@.service     | 1 +
 systemd/ceph-mon@.service     | 1 +
 systemd/ceph-osd@.service     | 1 +
 systemd/ceph-radosgw@.service | 1 +
 6 files changed, 9 insertions(+)

diff --git a/src/logrotate.conf b/src/logrotate.conf
index 1833d55..7bf8f69 100644
--- a/src/logrotate.conf
+++ b/src/logrotate.conf
@@ -6,6 +6,8 @@
     postrotate
         if which invoke-rc.d > /dev/null 2>&1 && [ -x `which invoke-rc.d` ]; then
             invoke-rc.d ceph reload >/dev/null
+        elif which systemctl > /dev/null 2>&1 && [ -x `which systemctl` ]; then
+	    killall -q -1 ceph-mon ceph-mds ceph-osd
         elif which service > /dev/null 2>&1 && [ -x `which service` ]; then
             service ceph reload >/dev/null
         fi
diff --git a/src/rgw/logrotate.conf b/src/rgw/logrotate.conf
index 7e527e8..7aef6cc 100644
--- a/src/rgw/logrotate.conf
+++ b/src/rgw/logrotate.conf
@@ -8,6 +8,9 @@
             invoke-rc.d radosgw reload >/dev/null
         elif which service > /dev/null 2>&1 && [ -x `which service` ]; then
             service ceph-radosgw reload >/dev/null
+        elif which systemctl > /dev/null 2>&1 && [ -x `which systemctl` ]; then
+	    # systemd does not provide an easy way to list (active) units
+	    killall -q -1 radosgw
         fi
         # Possibly reload twice, but depending on ceph.conf the reload above may be a no-op
         if which initctl > /dev/null 2>&1 && [ -x `which initctl` ]; then
diff --git a/systemd/ceph-mds@.service b/systemd/ceph-mds@.service
index 22a787d..aec46fd 100644
--- a/systemd/ceph-mds@.service
+++ b/systemd/ceph-mds@.service
@@ -8,6 +8,7 @@ PartOf=ceph.target
 EnvironmentFile=-/etc/sysconfig/ceph
 Environment=CLUSTER=ceph
 ExecStart=/usr/bin/ceph-mds -f --cluster ${CLUSTER} --id %i
+ExecReload=/bin/kill -HUP $MAINPID
 
 [Install]
 WantedBy=ceph.target
diff --git a/systemd/ceph-mon@.service b/systemd/ceph-mon@.service
index 437ef4d..a080808 100644
--- a/systemd/ceph-mon@.service
+++ b/systemd/ceph-mon@.service
@@ -13,6 +13,7 @@ PartOf=ceph.target
 EnvironmentFile=-/etc/sysconfig/ceph
 Environment=CLUSTER=ceph
 ExecStart=/usr/bin/ceph-mon -f --cluster ${CLUSTER} --id %i
+ExecReload=/bin/kill -HUP $MAINPID
 
 [Install]
 WantedBy=ceph.target
diff --git a/systemd/ceph-osd@.service b/systemd/ceph-osd@.service
index 09f51c5..6c55457 100644
--- a/systemd/ceph-osd@.service
+++ b/systemd/ceph-osd@.service
@@ -10,6 +10,7 @@ Environment=CLUSTER=ceph
 ExecStart=/usr/bin/ceph-osd -f --cluster ${CLUSTER} --id %i
 ExecStartPre=/usr/lib/ceph/ceph-osd-prestart.sh --cluster ${CLUSTER} --id %i
 LimitNOFILE=131072
+ExecReload=/bin/kill -HUP $MAINPID
 
 [Install]
 WantedBy=ceph.target
diff --git a/systemd/ceph-radosgw@.service b/systemd/ceph-radosgw@.service
index f0c24e3..63ceb7a 100644
--- a/systemd/ceph-radosgw@.service
+++ b/systemd/ceph-radosgw@.service
@@ -10,6 +10,7 @@ Environment=CLUSTER=ceph
 ExecStart=/usr/bin/radosgw -f --conf /etc/ceph/${CLUSTER}.conf --name client.radosgw.%i
 ExecStartPre=/usr/lib/ceph-radosgw/ceph-radosgw-prestart.sh --cluster ${CLUSTER} --name %i
 User=wwwrun
+ExecReload=/bin/kill -HUP $MAINPID
 
 [Install]
 WantedBy=ceph.target
