# Trying to fix a tgt bug # tgt can fail when we execute the `reload tgt` and `restart tgt` comands. # See: https://bugs.launchpad.net/ubuntu/+source/tgt/+bug/1294267 # "tgt doesn't export some LUNs after a reload operation (SIGHUP)" author "Rarylson Freitas " # Sorry. TGT doesn't permit us change the reload behavior # So, never run a `reload tgt`. It is broken. After all, if you run # `reload tgt` and see the syslog, you can find an error message like this: # "[...]tgtd: tgtd logger exits abnormally [...]" # We want to do this reload: # /usr/sbin/tgt-admin --update ALL # See: https://github.com/fujita/tgt/blob/master/scripts/initd.sample # To provide the `restart` functionality, we'll save the actually opened # devices for later processing. # From upstart cookbook: "[...] if the job contains post-stop, pre-start or # post-start stanzas, these will NOT be run for a restart. However, a pre-stop # stanza will be run." # See: "http://upstart.ubuntu.com/cookbook/#restart pre-stop script # Update actually opened devices mkdir -p /var/spool/tgt/ tgt-admin --dump | grep -o "\(backing-store\|direct-store\) \(.*\)" | cut -d' ' -f2 > /var/spool/tgt/devices end script # If start would fail, we'll add some delay to avoid this post-start script # Sleep until all devices are closed _device_opened=1 _time=10 while [ "$_time" -gt "0" ]; do # Exit when all devices are closed if [ `cat /var/spool/tgt/devices | wc -l` -eq "0" ]; then _device_opened=0 break fi _return=`cat /var/spool/tgt/devices | xargs lsof -V | grep -v "no file use located" | wc -l` if [ "$_return" -eq "0" ]; then _device_opened=0 break fi # Sleep some time if some device still opened sleep 0.1 _time=`expr $_time - 1` done # Log if there are some device opened [ "$_device_opened" -eq "1" ] && logger -t "tgtd" -p "WARN" "some" \ "backing-store or direct-store may not have corectly added to a LUN" # Load config file /usr/sbin/tgt-admin -e end script