88 lines
1.7 KiB
Bash
Executable File
88 lines
1.7 KiB
Bash
Executable File
#!/bin/bash
|
|
|
|
### BEGIN INIT INFO
|
|
# Provides: rtslib-fb-targetctl
|
|
# Required-Start: $network $local_fs $remote_fs $syslog
|
|
# Required-Stop: $local_fs $network $remote_fs
|
|
# Default-Start: 2 3 4 5
|
|
# Default-Stop: 0 1 6
|
|
# Short-Description: Start LIO targets
|
|
# Description: Loads configfs and restores LIO config with targetctl
|
|
### END INIT INFO
|
|
|
|
# Author: Thomas Goirand <zigo@debian.org>
|
|
|
|
PATH=/sbin:/usr/sbin:/bin:/usr/bin
|
|
DESC="rstlib-fb targetctl"
|
|
NAME=targetctl
|
|
DAEMON=/usr/bin/${NAME}
|
|
PIDFILE=/var/run/$NAME.pid
|
|
SCRIPTNAME=/etc/init.d/rtslib-fb-targetctl
|
|
|
|
[ -x $DAEMON ] || exit 0
|
|
|
|
#. /lib/lsb/init-functions
|
|
. /etc/sysconfig/rc
|
|
. ${rc_functions}
|
|
|
|
check_configfs_module () {
|
|
if ! modprobe configfs ; then
|
|
echo "Could not load configfs module: exiting!"
|
|
exit 0
|
|
fi
|
|
sleep 10
|
|
}
|
|
|
|
check_configfs_mounted () {
|
|
WORD_TO_GREP_IN_PROCMOUNT=configfs
|
|
#echo -n "Waiting for configfs to be loaded"
|
|
NUM_RETRY=500
|
|
while ! cat /proc/mounts | grep -q ${WORD_TO_GREP_IN_PROCMOUNT} && [ "${NUM_RETRY}" != 0 ] ; do
|
|
NUM_RETRY=$(( $NUM_RETRY - 1 ))
|
|
#echo -n "."
|
|
sleep 0.1
|
|
done
|
|
|
|
if ! cat /proc/mounts | grep -q ${WORD_TO_GREP_IN_PROCMOUNT} ; then
|
|
echo " ${WORD_TO_GREP_IN_PROCMOUNT} not found in /proc/mount: exiting!"
|
|
exit 0
|
|
# else
|
|
#echo ": mounted!"
|
|
fi
|
|
}
|
|
|
|
case "$1" in
|
|
start)
|
|
#check_configfs_module
|
|
#check_configfs_mounted
|
|
boot_mesg "Loading $DESC $NAME" ${NORMAL}
|
|
${DAEMON} restore
|
|
if [ $? -gt 0 ] ; then
|
|
echo_failure
|
|
exit 1
|
|
fi
|
|
echo_ok
|
|
;;
|
|
stop)
|
|
#check_configfs_module
|
|
boot_mesg "Unloading $DESC $NAME" ${NORMAL}
|
|
${DAEMON} clear
|
|
if [ $? -gt 0 ] ; then
|
|
echo_failure
|
|
exit 1
|
|
fi
|
|
echo_ok
|
|
;;
|
|
restart|reload|force-reload)
|
|
$0 stop
|
|
sleep 3
|
|
$0 start
|
|
;;
|
|
*)
|
|
echo "usage: $SCRIPTNAME {start|stop|restart|reload|force-reload}"
|
|
exit 1
|
|
;;
|
|
esac
|
|
|
|
exit 0
|