[Unit]
Description=iSCSI target framework daemon
Documentation=man:tgtd(8)
After=network.target

# On systems without virtual consoles, don't start any getty. Note
# that serial gettys are covered by serial-getty@.service, not this
# unit.
ConditionPathExists=/etc/tgt/targets.conf

[Service]
Type=forking
Environment=TGTD_CONFIG=/etc/tgt/targets.conf

ExecStart=/usr/sbin/tgtd
ExecStartPost=/usr/sbin/tgtadm --op update --mode sys --name State -v offline
ExecStartPost=/usr/sbin/tgtadm --op update --mode sys --name State -v ready
ExecStartPost=/usr/sbin/tgt-admin -e -c ${TGTD_CONFIG}

ExecReload=/usr/sbin/tgt-admin --update ALL -f -c ${TGTD_CONFIG}

ExecStop=/usr/sbin/tgtadm --op update --mode sys --name State -v offline
ExecStop=/usr/sbin/tgt-admin --offline ALL
ExecStop=/usr/sbin/tgt-admin --update ALL -c /dev/null -f
ExecStop=/usr/sbin/tgtadm  --op delete --mode system

# Exit code: 107 tgtd not running
ProtectHostname=true
ProtectClock=true
PrivateTmp=true
SystemCallArchitectures=native
RestrictNamespaces=true
ProtectHome=true

[Install]
WantedBy=multi-user.target
