Take the 2-minute tour ×
Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

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.

share|improve this question
    
If you've found a solution, it is perfectly acceptable to answer your own question. You'll have to wait 48 hours to mark it as accepted, but it does let everyone else know that this problem was solved, and what the solution was. –  sysadmin1138 Aug 30 '11 at 2:20

2 Answers 2

up vote 4 down vote accepted

Debian Squeeze is moving to a dependency-based ordering of init scripts rather than numbering the scripts sequentially. If you want to use this, you'll need special comments in your script for insserv (the update-rc.d replacement) to pick up.

There is a guide to writing a "proper" init script on Debian's wiki here.

Ubuntu has gone with upstart to replace init, but has left an init compatibility system in place so the init script you write following Debian's rules should work properly in Ubuntu. Otherwise, you can write an upstart service file (a too-basic-for-your-needs example is given on Ubuntu's wiki here)

As for the rest, unloading the modules is probably not necessary (and not always possible). If you do unload the modules, I would assume they need to be unloaded after the service is stopped. You may also need to reverse the order of unloading the modules if the modules started later depend on the modules started earlier. Depending on how quickly the daemon gets from "started" to "ready to have configuration loaded into it", you may need a sleep 1 in there before running scstadmin (or you may not. Just something to be aware of it fails.)

share|improve this answer
    
Well as far as I can tell, the modules don't really need to be unloaded. The configuration does not require a init reload either, it is done through sysfs. What I am trying to accomplish is a script to launch the target daemon and modules at boot. right now I have to it manually –  Solignis Aug 30 '11 at 0:58

Check out /etc/init.d/skeleton for an example. This should be present on an Ubuntu host.

share|improve this answer
    
I found it, I did not know it was there. Awesome –  Solignis Aug 30 '11 at 0:05
    
If I need run modprobe before the daemon starts I would just put that before start-stop-daemon right? –  Solignis Aug 30 '11 at 0:23

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.