#!/bin/sh
# pstorage chunk server monitor script
###
# chkconfig: 2345 49 85
# description: pstorage chunk server monitor
###

### BEGIN INIT INFO
# required-start: $network $remote_fs $local_fs
# required-stop:
# Default-Start: 2 3 5
# Default-Stop:
### END INIT INFO

SERVICE="cs"
SERVICE_VERSION=1
SERVICE_DESCR="pstorage chunk server"
CONTROL_DIR="control"

# source libraries
source /usr/libexec/pstorage/service-lib.sh

vz_sysctl_enable() {
	local fname="$1"

	[ -f "$fname" ] &&
	if [ x$(cat "$fname" 2>/dev/null) != x1 ]; then
		echo "1" 2>/dev/null >"$fname" && return 0
		echo "Failed to fix sysctl $fname!"
		return 1
	fi
	return 0
}

vz_init() {
	# check if we are on a VZ-enabled machine
	[ -d /proc/vz ] || return 0
	# check if we are inside a VE
	[ ! -f /proc/vz/version ] || return 0
	# try to enable sysctls
	vz_sysctl_enable /proc/sys/fs/fsync-enable &&
	vz_sysctl_enable /proc/sys/fs/odirect_enable
}

mon_prestart_hook() {
	vz_init
}

mon_check_dirty_hook() {
	true
}

mon_create_dirty_hook() {
	true
}

mon_remove_dirty_hook() {
	true
}

handle_service "$@"
