summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'net-fs/cvmfs/files/cvmfsd.initd')
-rw-r--r--net-fs/cvmfs/files/cvmfsd.initd191
1 files changed, 191 insertions, 0 deletions
diff --git a/net-fs/cvmfs/files/cvmfsd.initd b/net-fs/cvmfs/files/cvmfsd.initd
new file mode 100644
index 000000000000..bc0c604dd95d
--- /dev/null
+++ b/net-fs/cvmfs/files/cvmfsd.initd
@@ -0,0 +1,191 @@
+#!/sbin/runscript
+
+. /etc/cvmfs/server.conf
+[[ -f /etc/cvmfs/server.local ]] && . /etc/cvmfs/server.local
+
+extra_commands="checkconfig"
+extra_started_commands="pause flush resume"
+
+description="Background daemon that writes the cvmfs character device into a log file"
+description_checkconfig="Check configuration file validity"
+description_pause="Pause the transactions (not a full stop)"
+description_flush="Flush the CernVM-FS change log"
+description_resume="Resume transactions after a pause"
+
+pidfile="/var/run/cvmfsd.pid"
+subsysfile="/var/lock/subsys/cvmfsd"
+
+checkconfig() {
+ local var ret=0
+ for var in SHADOW_DIR PUB_DIR LOG_FILE; do
+ eval value=\$$var
+ if [[ -z ${value} ]]; then
+ eerror "You need to set a value for ${var} in /etc/cvmfs/server.local"
+ ret=$((ret + $?))
+ fi
+ done
+ return ${ret}
+}
+
+depend() {
+ after localmount
+ use net
+}
+
+# returns: 0 (stopped), 1 (running), 2 (paused)
+check_status() {
+ if [ -f ${pidfile} ]; then
+ [ $(cat /sys/fs/redirfs/filters/cvmfsflt/lockdown) -eq 1 ] && return 2
+ return 1
+ fi
+ return 0
+}
+
+# FIXME: could we use start-stop-daemon instead of listen/unlisten?
+
+listen() {
+ ebegin "Starting journal writer"
+ nohup cat /dev/cvmfs >> "${LOG_FILE}" 2>/dev/null </dev/null &
+ [ $? -eq 0 ] && echo $! > ${pidfile}
+ eend $?
+}
+
+unlisten() {
+ ebegin "Stopping journal writer"
+ local pid=$(cat ${pidfile})
+ kill ${pid}
+ local killed=0 retries=0
+ while [ ${killed} -eq 0 ]; do
+ sleep 1
+ kill -0 ${pid} 2>/dev/null
+ killed=$?
+ retries=$((retries + 1))
+ [ ${retries} -eq 3 ] && kill -9 ${pid}
+ done
+ eend $?
+}
+
+start() {
+ checkconfig || return 1
+
+ if [ ! -d ${SHADOW_DIR} ]; then
+ eerror "Missing ${SHADOW_DIR}"
+ return 1
+ fi
+
+ if mkdir -p "$(echo "${LOG_FILE}" | grep -o '\([^\/]*\/\)*')"; then
+ eerror "Could not create file system journal in ${LOG_FILE}"
+ return 1
+ fi
+
+ ebegin "Loading cvmfsflt kernel module"
+ modprobe -q redirfs && modprobe -q cvmfsflt
+ eend $? || return 1
+
+ ebegin "Linking to character device"
+ rm -f /dev/cvmfs
+ mknod /dev/cvmfs c $(awk '/cvmfs/ {print $1}' /proc/devices) 0 > /dev/null 2>&1
+ chmod 0600 /dev/cvmfs
+ eend $? || return 1
+
+ ebegin "Setting filter path to ${SHADOW_DIR}"
+ echo -n "a:i:${SHADOW_DIR}" > /sys/fs/redirfs/filters/cvmfsflt/paths
+ eend $? || return 1
+
+ listen || return 1
+ ebegin "Starting CernVM-FS daemon"
+ touch ${subsysfile}
+ eend $?
+}
+
+
+pause() {
+ check_status
+ local ret=$?
+ if [ ${ret} -eq 0 ]; then
+ eerror "CernVM-FS daemon is stopped"
+ return 1
+ fi
+ if [ ${ret} -eq 2 ]; then
+ ewarn "CernVM-FS daemon is already paused"
+ return 1
+ fi
+
+ ebegin "Locking down ${SHADOW_DIR}"
+ echo -n "1" > /sys/fs/redirfs/filters/cvmfsflt/lockdown
+ eend $? || return 1
+
+ ebegin "Waiting for pending operations on ${SHADOW_DIR}"
+ local nowops noll
+ while true; do
+ nowops=$(cat /sys/fs/redirfs/filters/cvmfsflt/nowops)
+ [ $? -ne 0 ] && eend 1 && return 1
+ [ ${nowops} -eq 0 ] && break
+ sleep 1
+ done
+ eend $?
+
+ ebegin "Waiting for pending messages in call buffer"
+ local noll
+ while true; do
+ noll=$(cat /sys/fs/redirfs/filters/cvmfsflt/noll)
+ [ $? -ne 0 ] && eend 1 && return 1
+ [ ${noll} -eq 0 ] && break
+ sleep 1
+ done
+ eend $? || return 1
+ unlisten || return 1
+ mark_service_stopped cvmfsd
+}
+
+resume() {
+ check_status
+ local ret=$?
+ if [ ${ret} -eq 0 ]; then
+ eerror "CernVM-FS daemon is stopped"
+ return 1
+ fi
+ if [ $retval -eq 1 ]; then
+ ewarn "CernVM-FS daemon is already running"
+ return 1
+ fi
+
+ listen || return 1
+
+ ebegin "Open up ${SHADOW_DIR}"
+ echo -n "0" > /sys/fs/redirfs/filters/cvmfsflt/lockdown
+ eend $? || return 1
+ mark_service_started cvmfsd
+}
+
+
+stop() {
+ check_status
+ local ret=$?
+ if [ ${ret} -eq 0 ]; then
+ ewarn "CernVM-FS daemon is already stopped"
+ return 2
+ fi
+
+ if [ ${ret} -eq 1 ]; then
+ pause
+ ret=$?
+ [ ${ret} -ne 0 ] && return ${ret}
+ fi
+
+ ebegin "Unloading cvmfsflt kernel module"
+ echo -n "c\0" > /sys/fs/redirfs/filters/cvmfsflt/paths || ret=$((ret + 1))
+ echo -n "1\0" > /sys/fs/redirfs/filters/cvmfsflt/unregister || ret=$((ret + 1))
+ rmmod cvmfsflt || ret=$((ret + 1))
+ eend ${ret} || return 1
+
+ ebegin "Shutting down CernVM-FS daemon"
+ rm -f ${pidfile} ${subsysfile}
+ eend $?
+}
+
+flush() {
+ ebegin "Flushing CernVM-FS server file system change log"
+ cat /dev/null > "${LOG_FILE}"
+ eend $?
+}