summaryrefslogtreecommitdiff
path: root/skip/ceph/ceph.initd
blob: c522efa694afe27f169a96572ad9e00ceba69e3b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
#!/sbin/openrc-run

# Original source: https://gitweb.gentoo.org/repo/gentoo.git/tree/sys-cluster/ceph/files/ceph.initd-r12

# make sure /etc/conf.d/ceph gets loaded for ceph-mon etc
_CONFD_FILE="${RC_SERVICE%/*}/../conf.d/${RC_SVCNAME%-*}"
if [ -r "${_CONFD_FILE}" ]; then
	. "${_CONFD_FILE}" || exit 1
fi

: "${ceph_conf:=/etc/ceph/ceph.conf}"
daemon_type="${RC_SVCNAME#ceph-}"
daemon_type="${daemon_type%%.*}"
daemon_id="${RC_SVCNAME#ceph-*.}"
daemon_id="${daemon_id:-0}"
: "${rundir:=/run/ceph}"
: "${user:=ceph}"
: "${group:=ceph}"
: "${rc_ulimit:=-n 1048576 -u 1048576}"

pidfile="${rundir}/supervisor-${daemon_type}.${daemon_id}.pid"
daemon_pidfile="${rundir}/${daemon_type}.${daemon_id}.pid"

command="/usr/bin/${RC_SVCNAME%%.*}"
command_args="-i ${daemon_id} --pid-file ${daemon_pidfile} -c ${ceph_conf}"
extra_commands="${extra_commands} reload"
command_args_foreground="--foreground"

retry="${CEPH_TERMTIMEOUT:-TERM/120/KILL/5}"
start_stop_daemon_args="--user ${user} --group ${group}"
supervise_daemon_args="--user ${user} --group ${group}"

: "${supervisor:=supervise-daemon}"
: "${stdout:=/var/log/ceph/ceph}"
: "${stderr:=/var/log/ceph/ceph}"
: "${respawn_delay:=10}"
: "${respawn_max:=5}"
: "${respawn_period:=1800}"

: "${osd_respawn_delay:=15}"
: "{osd_respawn_max:=10}"

: "{radosgw_respawn_max:=5}"
: "${radosgw_respawn_period:=30}"

depend() {
	use dns logger
	after net ntpd ntp-client chronyd
	before netmount
}

is_type_valid() {
	case ${daemon_type} in
		mon|mds|osd|mgr|radosgw) return 0;;
		*) return 1;;
	esac
}

start_pre() {
	local log_dir
	export CEPH_CONF="${ceph_conf}"

	checkpath -d -q -o "${user}:${group}" "${rundir}"

	if ! is_type_valid ;then
		eerror "Please give valid Ceph Server Type: mds, mon, osd"
		return 1

	elif pgrep -f "[c]eph-${daemon_type} -i ${daemon_id} "; then
		eerror "${daemon_type}.${daemon_id} is still running, refusing to start"
		return 1
	fi

	if [ -n "${bluestore_osd_fsid}" ]; then
		einfo "Mounting Bluestore"
		ceph-volume lvm activate "${daemon_id}" "${bluestore_osd_fsid}" --no-systemd
	fi

	if [ "${daemon_type}" = radosgw ] && [ "${RADOSGW_WANT_NAME_PARAM}" = y ]; then
		command_args="${command_args} --name client.${daemon_id}"
	fi

	local arg_name arg_val repl_arg_name
	for arg_name in stdout stderr respawn_delay respawn_max respawn_period; do
		eval arg_val="\${${daemon_type}_${arg_name}}"

		if [ -z "${arg_val}" ]; then
			eval arg_val="\${${arg_name}}"
		else
			eval "${arg_name}=\"${arg_val}\""
		fi

		if [ "${arg_name}" = "stderr" ] || [ "${arg_name}" = "stdout" ]; then
			local log_file log_postfix
			log_postfix=".${daemon_id}-${arg_name}.log"
			log_file="${arg_val}"

			if [ "${log_file}" != /dev/null ]; then
				log_file="${log_file}${log_postfix}"

				log_dir="$(dirname "${log_file}")"
				checkpath -m 0755 -o "${user}:${group}" -d "${log_dir}"
			fi

			repl_arg_name="$(printf -- "%s\n" "${arg_name}" | tr _ -)"
			supervise_daemon_args="${supervise_daemon_args} --${repl_arg_name}=${log_file}"
		fi
	done
}

reload() {
	ebegin "Reloading Ceph ${daemon_type}.${daemon_id}"
	start-stop-daemon --signal 1 "${start_stop_daemon_args}"
	eend ${?}
}

# vim:ft=gentoo-init-d:ts=4:sts=4:sw=4:noet: