From b0a902a6a154c10fb61f0082c2e4a0a538611741 Mon Sep 17 00:00:00 2001 From: Mark Buechler Date: Wed, 11 Feb 2009 16:09:45 +0000 Subject: [PATCH] Add lsb support for init.d scripts. Patch from Bart Van Assche. git-svn-id: http://svn.code.sf.net/p/scst/svn/trunk@669 d57e44dd-8a1f-0410-8b47-8ef2f437770f --- scstadmin/Makefile | 10 ++- scstadmin/README | 4 + scstadmin/init.d/qla2x00t | 122 +++++++++++++++++++++++++++ scstadmin/init.d/scst | 172 +++++++++++++++++++++++++++----------- 4 files changed, 255 insertions(+), 53 deletions(-) create mode 100755 scstadmin/init.d/qla2x00t diff --git a/scstadmin/Makefile b/scstadmin/Makefile index c67b50a44..1ffccd2c7 100644 --- a/scstadmin/Makefile +++ b/scstadmin/Makefile @@ -6,13 +6,15 @@ all: perl-module install: install -m 755 $(TOOL) /usr/local/sbin install -m 755 init.d/scst /etc/init.d + /usr/lib/lsb/install_initd scst + install -m 755 init.d/qla2x00t /etc/init.d + /usr/lib/lsb/install_initd qla2x00t $(MAKE) -C scst-$(MODULE_VERSION) install - @echo - @echo "The SCST init file has been installed in /etc/init.d," - @echo "be sure to enable it with your favorite SysV init editor." - @echo uninstall: + -/usr/lib/lsb/remove_initd qla2x00t + -rm -f /etc/init.d/qla2x00t + -/usr/lib/lsb/remove_initd scst -rm -f /etc/init.d/scst -rm -f /usr/local/sbin/$(TOOL) $(MAKE) -C scst-$(MODULE_VERSION) uninstall diff --git a/scstadmin/README b/scstadmin/README index 1677c644a..4f4801a20 100644 --- a/scstadmin/README +++ b/scstadmin/README @@ -38,6 +38,10 @@ This installs scstadmin, the init.d script and the perl module. If you want SCST startup and configure automatically upon boot, enable SCST using your favorite SysV init editor. +NOTE: The init.d startup & shutdown scripts now depend on lsb-core. Ensure you have +lsb-core installed or 'make install' will fail. Make sure /usr/lib/lsb/install_initd +exists. + Getting Started: ================ diff --git a/scstadmin/init.d/qla2x00t b/scstadmin/init.d/qla2x00t new file mode 100755 index 000000000..f3d90e71d --- /dev/null +++ b/scstadmin/init.d/qla2x00t @@ -0,0 +1,122 @@ +#!/bin/sh +# +# Copyright (C) 2008 Mark Buechler +# Copyright (C) 2009 Bart Van Assche +# This software is made available under the GPLv2 license. +# +# System startup script for the QLogic 22xx/23xx card target driver. +# +# Note: on most Linux distributions /bin/sh is a soft link to /bin/bash, while +# on a default Ubuntu setup /bin/sh is a soft link to /bin/dash ! +# +# See also: +# * http://refspecs.freestandards.org/LSB_3.1.0/LSB-Core-generic/LSB-Core-generic/iniscrptact.html +# * http://www.opengroup.org/onlinepubs/009695399/utilities/xcu_chap02.html +# +### BEGIN INIT INFO +# Provides: qla2x00t +# Required-Start: $syslog $local_fs scst +# Required-Stop: $syslog $local_fs scst +# Default-Start: 2 3 4 5 +# Default-Stop: 0 1 6 +# Description: QLogic 22xx/23xx card target driver +### END INIT INFO +### BEGIN CHKCONFIG INFO +# chkconfig: 2345 14 86 +# description: QLogic 22xx/23xx card target driver +### END CHKCONFIG IFO + +PATH=/bin:/usr/bin:/sbin:/usr/sbin:/usr/local/sbin:/usr/local/bin + +# Modules to load/unload. +KERNEL_MODULES="qla2x00t" + +# Return values according to LSB for all commands but status: +# 0 - success +# 1 - generic or unspecified error +# 2 - invalid or excess argument(s) +# 3 - unimplemented feature (e.g. "reload") +# 4 - insufficient privilege +# 5 - program is not installed +# 6 - program is not configured +# 7 - program is not running +# + +. /lib/lsb/init-functions + +case "$1" in + start) + ## Start the service. + echo -n "Loading and configuring the QLogic target driver" + + for module in ${KERNEL_MODULES}; do + if ! modprobe "${module}"; then + log_failure_msg + exit 5 + fi + done + ;; + stop) + ## Stop the service. + echo -n "Stopping the QLogic target driver" + + reverse_list="" + for module in ${KERNEL_MODULES}; do + reverse_list="${module} ${reverse_list}" + done + for module in ${reverse_list}; do + if [ -e "/sys/module/${module}" ] && ! rmmod "${module}"; then + log_failure_msg FAILED + exit 1 + fi + done + + log_success_msg + ;; + restart) + ## Stop and restart the service if the service is already running, + ## otherwise start the service. + $0 stop + $0 start + ;; + try-restart) + ## Restart the service if the service is already running. + $0 status >/dev/null && $0 restart + ;; + reload) + ## Cause the configuration of the service to be reloaded without + ## actually stopping and restarting the service. + echo -n "Reloading QLogic target driver configuration" + log_success_msg + ;; + force-reload) + ## Cause the configuration to be reloaded if the service supports this, + ## otherwise restart the service if it is running. + echo -n "Reloading QLogic target driver configuration" + log_success_msg + ;; + status) + ## Print the current status of the service. + echo -n "QLogic target driver status: " + + # Status has a slightly different meaning for the status command: + # 0 - service running + # 1 - service dead, but /var/run/ pid file exists + # 2 - service dead, but /var/lock/ lock file exists + # 3 - service not running + + for module in ${KERNEL_MODULES}; do + if [ ! -e "/sys/module/${module}" ]; then + echo "Not loaded" + exit 3 + fi + done + echo "OK" + ;; + *) + echo "Usage: $0 {start|stop|status|try-restart|restart|force-reload|reload}" + exit 2 + ;; +esac + +exit 0 diff --git a/scstadmin/init.d/scst b/scstadmin/init.d/scst index 5deccddb3..4874215f0 100755 --- a/scstadmin/init.d/scst +++ b/scstadmin/init.d/scst @@ -1,7 +1,32 @@ #!/bin/sh +# +# Copyright (C) 2008 Mark Buechler +# Copyright (C) 2009 Bart Van Assche +# This software is made available under the GPLv2 license. +# +# System startup script for the SCST core functionality. +# +# Note: on most Linux distributions /bin/sh is a soft link to /bin/bash, while +# on a default Ubuntu setup /bin/sh is a soft link to /bin/dash ! +# +# See also: +# * http://refspecs.freestandards.org/LSB_3.1.0/LSB-Core-generic/LSB-Core-generic/iniscrptact.html +# * http://www.opengroup.org/onlinepubs/009695399/utilities/xcu_chap02.html +# +### BEGIN INIT INFO +# Provides: scst +# Required-Start: $syslog $local_fs +# Required-Stop: $syslog $local_fs +# Default-Start: 2 3 4 5 +# Default-Stop: 0 1 6 +# Description: SCST core +### END INIT INFO +### BEGIN CHKCONFIG INFO +# chkconfig: 2345 13 87 +# description: SCST core +### END CHKCONFIG IFO PATH=/bin:/usr/bin:/sbin:/usr/sbin:/usr/local/sbin:/usr/local/bin -SCST_CMD=/usr/local/sbin/scstadmin SCST_CFG=/etc/scst.conf # Modules to load/unload. @@ -10,64 +35,113 @@ SCST_CFG=/etc/scst.conf # !!! NEW CONNECTIONS, BECAUSE AT THIS POINT ACCESS CONTROL HASN'T CONFIGURED # !!! YET! # -SCST_MODULES="qla2x00tgt scst_vdisk scst_disk" +SCST_MODULES="scst scst_disk scst_vdisk" -OPTIONS="" +# Return values according to LSB for all commands but status: +# 0 - success +# 1 - generic or unspecified error +# 2 - invalid or excess argument(s) +# 3 - unimplemented feature (e.g. "reload") +# 4 - insufficient privilege +# 5 - program is not installed +# 6 - program is not configured +# 7 - program is not running +# -test -x $SCST_CMD -a -f $SCST_CFG || exit 0 +[ -x "$(which scstadmin)" ] || exit 5 +[ -f $SCST_CFG ] || exit 6 + +. /lib/lsb/init-functions case "$1" in - start) - echo -n "Loading and configuring SCSI Target Mid-level SCST " + start) + ## Start the service. + echo -n "Loading and configuring the mid-level SCSI target SCST" - for module in ${SCST_MODULES}; do - modprobe ${module} || { echo "[${module} failed]" ; exit 1 ; } - done + for module in ${SCST_MODULES}; do + if ! modprobe "${module}"; then + log_failure_msg + exit 5 + fi + done - $SCST_CMD -config $SCST_CFG + if scstadmin -config $SCST_CFG >/dev/null 2>&1; then + log_success_msg + else + log_failure_msg + exit 1 + fi + ;; + stop) + ## Stop the service. + echo -n "Stopping the mid-level SCSI target SCST" - RC=$? + reverse_list="" + for module in ${SCST_MODULES}; do + reverse_list="${module} ${reverse_list}" + done + for module in ${reverse_list}; do + if [ -e "/sys/module/${module}" ] && ! rmmod "${module}"; then + log_failure_msg FAILED + exit 1 + fi + done - if [ $RC -ne 0 ]; - then - echo "[config failed]" - fi + log_success_msg + ;; + restart) + ## Stop and restart the service if the service is already running, + ## otherwise start the service. + $0 stop + $0 start + ;; + try-restart) + ## Restart the service if the service is already running. + $0 status >/dev/null 2>&1 && $0 restart + ;; + reload) + ## Cause the configuration of the service to be reloaded without + ## actually stopping and restarting the service. + echo -n "Reloading SCST configuration" + if scstadmin -config $SCST_CFG >/dev/null 2>&1; then + log_success_msg + else + log_failure_msg + exit 1 + fi + ;; + force-reload) + ## Cause the configuration to be reloaded if the service supports this, + ## otherwise restart the service if it is running. + echo -n "Reloading SCST configuration" + if scstadmin -config $SCST_CFG >/dev/null 2>&1; then + log_success_msg + else + $0 restart + fi + ;; + status) + ## Print the current status of the service. + echo -n "SCST status: " - echo "." - ;; - stop) - echo -n "Stopping SCSI Target Mid-level SCST " + # Status has a slightly different meaning for the status command: + # 0 - service running + # 1 - service dead, but /var/run/ pid file exists + # 2 - service dead, but /var/lock/ lock file exists + # 3 - service not running - for module in ${SCST_MODULES}; do - rmmod ${module} || { echo "[${module} failed]" ; } - done - - rmmod scst || { echo "[scst failed]" ; } - - echo "." - ;; - force-reload|restart) - $0 stop - sleep 5 - $0 start - ;; - reload-config) - echo -n "Reloading SCST configuration " - - $SCST_CMD -config $SCST_CFG - - RC=$? - - if [ $RC -ne 0 ]; - then - echo "[config failed]" - fi - - echo "." - ;; - *) - echo "Usage: /etc/init.d/scst {start|stop|restart|force-reload|reload-config}" - exit 1 + for module in ${SCST_MODULES}; do + if [ ! -e "/sys/module/${module}" ]; then + echo "Not loaded" + exit 3 + fi + done + echo "OK" + ;; + *) + echo "Usage: $0 {start|stop|status|try-restart|restart|force-reload|reload}" + exit 2 + ;; esac exit 0