Skip to content

Commit

Permalink
Merge pull request ceph#8222 from SUSE/wip-14984
Browse files Browse the repository at this point in the history
systemd: set up environment in rbdmap unit file

Reviewed-by: Boris Ranto <[email protected]>
  • Loading branch information
liewegas committed Mar 23, 2016
2 parents baa9883 + 0effb9e commit df6570c
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 12 deletions.
37 changes: 37 additions & 0 deletions qa/workunits/rbd/test_rbdmap_RBDMAPFILE.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
#!/bin/sh
#
# Regression test for http://tracker.ceph.com/issues/14984
#
# When the bug is present, starting the rbdmap service causes
# a bogus log message to be emitted to the log because the RBDMAPFILE
# environment variable is not set.
#
# When the bug is not present, starting the rbdmap service will emit
# no log messages, because /etc/ceph/rbdmap does not contain any lines
# that require processing.
#
set -ex

which ceph-detect-init >/dev/null || exit 1
[ "$(ceph-detect-init)" = "systemd" ] || exit 0

echo "TEST: save timestamp for use later with journalctl --since"
TIMESTAMP=$(date +%Y-%m-%d\ %H:%M:%S)

echo "TEST: assert that rbdmap has not logged anything since boot"
journalctl -b 0 -t rbdmap | grep 'rbdmap\[[[:digit:]]' && exit 1
journalctl -b 0 -t init-rbdmap | grep 'rbdmap\[[[:digit:]]' && exit 1

echo "TEST: restart the rbdmap.service"
sudo systemctl restart rbdmap.service

echo "TEST: ensure that /usr/bin/rbdmap runs to completion"
until sudo systemctl status rbdmap.service | grep 'active (exited)' ; do
sleep 0.5
done

echo "TEST: assert that rbdmap has not logged anything since TIMESTAMP"
journalctl --since "$TIMESTAMP" -t rbdmap | grep 'rbdmap\[[[:digit:]]' && exit 1
journalctl --since "$TIMESTAMP" -t init-rbdmap | grep 'rbdmap\[[[:digit:]]' && exit 1

exit 0
28 changes: 16 additions & 12 deletions src/rbdmap
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
#!/bin/sh

do_map() {

# default to reasonable value if RBDMAPFILE not set in environment
printenv RBDMAPFILE >/dev/null || local RBDMAPFILE=/etc/ceph/rbdmap

if [ ! -f "$RBDMAPFILE" ]; then
logger -p "daemon.warning" -t init-rbdmap "No $RBDMAPFILE found."
logger -p "daemon.warning" -t rbdmap "No $RBDMAPFILE found."
exit 0
fi

Expand All @@ -19,7 +23,7 @@ do_map() {
DEV=rbd/$DEV
;;
esac
logger -p "daemon.debug" -t init-rbdmap "Mapping '${DEV}'"
logger -p "daemon.debug" -t rbdmap "Mapping '${DEV}'"
newrbd=""
MAP_RV=""
OIFS=$IFS
Expand All @@ -37,22 +41,22 @@ do_map() {
newrbd="yes"
else
RET=$((${RET}+$?))
logger -p "daemon.warning" -t init-rbdmap "Failed to map '${DEV}"
logger -p "daemon.warning" -t rbdmap "Failed to map '${DEV}"
continue
fi
fi
logger -p "daemon.debug" -t init-rbdmap "Mapped '${DEV}' to '${MAP_RV}'"
logger -p "daemon.debug" -t rbdmap "Mapped '${DEV}' to '${MAP_RV}'"

if [ "$newrbd" ]; then
## Mount new rbd
MNT_RV=""
mount --fake /dev/rbd/$DEV >>/dev/null 2>&1 \
&& MNT_RV=$(mount -vn /dev/rbd/$DEV 2>&1)
[ -n "${MNT_RV}" ] && logger -p "daemon.debug" -t init-rbdmap "Mounted '${MAP_RV}' to '${MNT_RV}'"
[ -n "${MNT_RV}" ] && logger -p "daemon.debug" -t rbdmap "Mounted '${MAP_RV}' to '${MNT_RV}'"

## post-mapping
if [ -x "/etc/ceph/rbd.d/${DEV}" ]; then
logger -p "daemon.debug" -t init-rbdmap "Running post-map hook '/etc/ceph/rbd.d/${DEV}'"
logger -p "daemon.debug" -t rbdmap "Running post-map hook '/etc/ceph/rbd.d/${DEV}'"
/etc/ceph/rbd.d/${DEV} map "/dev/rbd/${DEV}"
fi
fi
Expand All @@ -71,32 +75,32 @@ do_unmap() {
LL="${L##/dev/rbd/}"
if [ "$(readlink -f $L)" = "${DEV}" ] \
&& [ -x "/etc/ceph/rbd.d/${LL}" ]; then
logger -p "daemon.debug" -t init-rbdmap "Running pre-unmap hook for '${DEV}': '/etc/ceph/rbd.d/${LL}'"
logger -p "daemon.debug" -t rbdmap "Running pre-unmap hook for '${DEV}': '/etc/ceph/rbd.d/${LL}'"
/etc/ceph/rbd.d/${LL} unmap "$L"
break
fi
done

logger -p "daemon.debug" -t init-rbdmap "Unmapping '${DEV}'"
logger -p "daemon.debug" -t rbdmap "Unmapping '${DEV}'"
MNT=$(findmnt --mtab --source ${DEV} --noheadings | awk '{print $1'})
if [ -n "${MNT}" ]; then
logger -p "daemon.debug" -t init-rbdmap "Unmounting '${MNT}'"
logger -p "daemon.debug" -t rbdmap "Unmounting '${MNT}'"
umount "${MNT}" >>/dev/null 2>&1
fi
if mountpoint -q "${MNT}"; then
## Un-mounting failed.
logger -p "daemon.warning" -t init-rbdmap "Failed to unmount '${MNT}'"
logger -p "daemon.warning" -t rbdmap "Failed to unmount '${MNT}'"
RET=$((${RET}+1))
continue
fi
## Un-mapping.
rbd unmap $DEV >>/dev/null 2>&1
if [ $? -ne 0 ]; then
logger -p "daemon.warning" -t init-rbdmap "Failed to unmap '${MNT}'"
logger -p "daemon.warning" -t rbdmap "Failed to unmap '${MNT}'"
RET=$((${RET}+$?))
continue
fi
logger -p "daemon.debug" -t init-rbdmap "Unmapped '${DEV}'"
logger -p "daemon.debug" -t rbdmap "Unmapped '${DEV}'"
done
fi
exit ${RET}
Expand Down
2 changes: 2 additions & 0 deletions systemd/rbdmap.service
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ After=network-online.target local-fs.target
Wants=network-online.target local-fs.target

[Service]
EnvironmentFile=-/etc/sysconfig/ceph
Environment=RBDMAPFILE=/etc/ceph/rbdmap
Type=oneshot
RemainAfterExit=yes
ExecStart=/usr/bin/rbdmap map
Expand Down

0 comments on commit df6570c

Please sign in to comment.