#!/bin/bash # service iscsi-server [] # control_port # threads # portal [:] [ ... ] # nop_interval # nop_count # debug if [ "$1" = "complete" ]; then compgen -W "help status start stop restart reload check list_options show" "$2" exit 0 fi . `dirname $0`/functions option control_port standard_option # port for tgtadm option threads standard_option $(nproc) # thread count 1..N option nop_interval standard_option # keep-alive interval in seconds option nop_count standard_option # keep-alive count option portal multiple_option # [:] [ ... ] option debug standard_option # debug level option procname reserved_option tgtd option pidfile reserved_option /var/run/tgtd.pid option bin reserved_option /usr/sbin/tgtd SVC_VARS="opt_iscsi" STOP_FIRST_WITH=KILL # assign default values to certain options for compatibility purposes function fct_end_section { local listener opt_iscsi= for listener in ${opt_portal[*]}; do opt_iscsi="${opt_iscsi}${opt_iscsi:+,}portal=${listener}" done if [ -n "$opt_nop_interval" ]; then opt_iscsi="${opt_iscsi}${opt_iscsi:+,}nop_interval=${opt_nop_interval}" fi if [ -n "$opt_nop_count" ]; then opt_iscsi="${opt_iscsi}${opt_iscsi:+,}nop_count=${opt_nop_count}" fi } function do_help { echo "Usage: ${0##*/} " echo "List of config.rc options (name, type, default value, current value) :" echo " - control_port " echo " - threads " echo " - portal [:] [ ... ]" echo " - nop_interval " echo " - nop_count " echo " - debug " exit 1 } function do_start { local instname=$2 local ret echo "# Starting $svcname${instname:+[$instname]} ..." do_status $svcname $instname > /dev/null 2>&1 if [ $? = 0 -a $FORCE_START_STOP -eq 0 ] ; then echo " ==> Service $svcname${instname:+[$instname]} already running."; [ $SVC_AUTO_START -eq 0 ] && echo " ==> please use '--force' or 'restart' instead or check with 'status'." return 0 fi if ! ${bin} ${opt_control_port:+-C $opt_control_port} ${opt_threads:+-t $opt_threads} ${pidfile:+-p $pidfile} ${debug:+-d $debug} ${opt_iscsi:+--iscsi ${opt_iscsi}}; then echo " ==> failed to start peer $svcname${instname:+[$instname]}." else echo " ==> stop $svcname${instname:+[$instname]} : Done." fi } function do_show { /usr/sbin/tgtadm ${opt_control_port:+-C ${opt_control_port}} --lld=iscsi --mode=target --op=show } load_config