ungleich-tools/monit-ceph-create-start
2020-07-02 21:55:15 +02:00

60 lines
1.4 KiB
Bash
Executable file

#!/bin/sh
# Nico Schottelius, 2018-02-22
# Copyright ungleich glarus ag
if [ $# -ne 1 ]; then
echo "$0: to monitor"
echo "f.i. osd.17 or mon.server4"
exit 1
fi
to_monitor=$1
set -e
depends="cephrundir"
osd=""
conf="/etc/monit/conf.d/$to_monitor"
if echo $to_monitor | grep ^osd; then
depends="${depends}, ${to_monitor}-whoami"
osd="yes"
osdid=$(echo $to_monitor | cut -d. -f2)
cat > "$conf" <<EOF
# Generated by $0
check process ${to_monitor} with pidfile /var/run/ceph/${to_monitor}.pid
start program = "/usr/bin/ceph-osd -i ${osdid} --pid-file /var/run/ceph/osd.${osdid}.pid -c /etc/ceph/ceph.conf --cluster ceph --setuser ceph --setgroup ceph" with timeout 3600 seconds
stop program = "/usr/bin/pkill -f '/usr/bin/ceph-osd -i ${osdid}'"
EOF
else
# monitor, mgr
cat > "$conf" <<EOF
# Generated by $0
check process ${to_monitor} with pidfile /var/run/ceph/${to_monitor}.pid
start program = "/etc/init.d/ceph start ${to_monitor}" with timeout 60 seconds
stop program = "/etc/init.d/ceph stop ${to_monitor}"
EOF
fi
# final clause same for both
cat >> "$conf" <<EOF
group ceph
depends on $depends
EOF
if [ "$osd" ]; then
cat >> "$conf" <<EOF
check file ${to_monitor}-whoami with path /var/lib/ceph/osd/ceph-${osdid}/whoami
if content != "${osdid}" then alert
EOF
fi
/etc/init.d/monit restart
# monit reload
sleep 1
monit start "${to_monitor}"