Skip to content

Instantly share code, notes, and snippets.

Created January 31, 2013 15:58
Show Gist options
  • Save anonymous/4683906 to your computer and use it in GitHub Desktop.
Save anonymous/4683906 to your computer and use it in GitHub Desktop.
I wanted to be able to export iscsi volumes from SmartOS and not worry about them changing GUIDs on reboot. The first file goes in /opt/custom/bin and the second in /opt/custom/smf
#!/bin/sh
set -o xtrace
. /lib/svc/share/smf_include.sh
cd /
PATH=/usr/sbin:/usr/bin:/opt/custom/bin:/opt/custom/sbin; export PATH
case "$1" in
'start')
#Enable the needed services
svcadm enable -r svc:/network/iscsi/target:default
#Setup the ISCSI Target for the DVR
sbdadm create-lu /dev/zvol/rdsk/zones/dvr-iscsi
guid=`sbdadm list-lu | grep -w dvr-iscsi |awk '{print $1}'`
stmfadm add-view ${guid}
itadm create-target -n iqn.2010-08.org.illumos:02:dvr-iscsi
;;
'stop')
### Insert code to execute on shutdown here.
;;
*)
echo "Usage: $0 { start | stop }"
exit $SMF_EXIT_ERR_FATAL
;;
esac
exit $SMF_EXIT_OK
<?xml version="1.0"?>
<!DOCTYPE service_bundle SYSTEM "/usr/share/lib/xml/dtd/service_bundle.dtd.1">
<service_bundle type="manifest" name="custom:iscsi">
<service name="custom/iscsi" type="service" version="1">
<create_default_instance enabled="true"/>
<single_instance/>
<dependency name = 'network-physical'
grouping='require_all'
restart_on='none'
type='service'>
<service_fmri value='svc:/network/physical:default'/>
</dependency>
<dependency name = 'filesystem-local'
grouping='require_all'
restart_on='none'
type='service'>
<service_fmri value='svc:/system/filesystem/local:default'/>
</dependency>
<exec_method type="method" name="start" exec="/opt/custom/bin/enable-iscsi start" timeout_seconds="0">
</exec_method>
<exec_method type="method" name="stop" exec=":true" timeout_seconds="0">
</exec_method>
<property_group name="startd" type="framework">
<propval name="duration" type="astring" value="transient"/>
</property_group>
<stability value="Unstable"/>
</service>
</service_bundle>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment