I am trying to write an init script for the SCST iSCSI target software for Debian / Ubuntu. The current one in the download does not work and seems to be outfitted to work on SuSE and others.
This what I have so far, but I am basing this off of my limited knowledge of init scripts and a lot of google searches.
I am just wondering if I am over thinking this, do I need to unload the modules everytime I stop the script. The modules to no load on startup, I know I need to start the iscsi daemon and load the config.
Any help would be appreciated.
#!/bin/sh
DAEMON=/usr/local/sbin/iscsi-scstd
PIDFILE=/var/run/iscsi-scstd.pid
CONFIG=/etc/scst/scst.conf
case "$1" in
start)
echo "Starting SCST iSCSI target service: "
modprobe scst
modprobe scst_vdisk
modprobe iscsi_scst
start-stop-daemon --start --quiet --exec $DAEMON
scstadmin -config $CONFIG
$RETVAL=$?
if [ $RETVAL == "0" ]; then
echo -n "Success"
fi
;;
stop)
echo "Stopping SCST iSCSI target service: "
modprobe -r scst
modprobe -r scst_vdisk
modprobe -r iscsi_scst
start-stop-daemon --stop --quiet --exec $DAEMON --pidfile $PIDFILE
$RETVAL=$?
if [ $RETVAL == "3" ]; then
echo -n "Success"
fi
if [ $RETVAL == "1" ]; then
rm -f $PIDFILE
echo -n "Success"
fi
;;
restart)
echo "Stopping SCST iSCSI target service: "
modprobe -r scst
modprobe -r scst_vdisk
modprobe -r iscsi_scst
start-stop-daemon --stop --quiet --exec $DAEMON --pidfile $PIDFILE
sleep 2
echo "Stopping SCST iSCSI target service: "
modprobe scst
modprobe scst_vdisk
modprobe iscsi_scst
start-stop-daemon --start --quiet --exec $DAEMON
scstadmin -config $CONFIG
;;
status)
$RETVAL=$?
if [ $RETVAL == "0" ]; then
echo -n "SCST iSCSI target service is running"
fi
if [ $RETVAL == "3" ]; then
echo -n "SCST iSCSI target service is not running"
fi
if [ $RETVAL == "4" ]; then
echo -n "SCST iSCSI target service is unknown"
fi
*)
echo "Usage: /etc/init.d/scst {start|stop|restart}"
exit 1
esac
exit 0
I actually ended up finding exactly what I was looking for in an old Ubuntu PPA for my iSCSI target. So this question is pretty much moot.