This file is indexed.

postinst is in open-iscsi 2.0.873+git0.3b4b4500-14ubuntu3.

This file is a maintainer script. It is executed when installing (*inst) or removing (*rm) the package.

The actual contents of the file can be viewed below.

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
#!/bin/sh

. /usr/share/debconf/confmodule
set -e

restore_old_timeouts()
{
    if [ -s /run/open-iscsi/upgrade/restore_old_timeouts ] ; then
        sh /run/open-iscsi/upgrade/restore_old_timeouts || :
    fi
    rm -f /run/open-iscsi/upgrade/restore_old_timeouts
    [ ! -d /run/open-iscsi/upgrade ] || rmdir --ignore-fail-on-non-empty /run/open-iscsi/upgrade
    [ ! -d /run/open-iscsi ] || rmdir --ignore-fail-on-non-empty /run/open-iscsi
}

case "$1" in
    configure)
        # We switched over to modules-load.d logic, so we have to take
        # care of this in postinst now.
        MODULES_FILE=/lib/modules-load.d/open-iscsi.conf
        if [ -f /etc/modules-load.d/open-iscsi.conf ] ; then
            MODULES_FILE=/etc/modules-load.d/open-iscsi.conf
        fi
        grep '^[^#]' $MODULES_FILE | while read module args ; do
            [ "$module" ] || continue
            modprobe $module $args >/dev/null 2>&1 || true
        done

	# Move old configuration from /etc/ into /etc/iscsi/
	# But only if configuration in /etc/iscsi is untouched
	# (FIXME: should this be removed? this is ancient and was
	# already in Squeeze's postinst - and we don't really need to
	# support direct upgrades from Lenny (5) to Stretch (9).)
	
        if [ -f /etc/initiatorname.iscsi ] ; then
            if grep -q "^GenerateName=yes" /etc/iscsi/initiatorname.iscsi ; then
                mv /etc/initiatorname.iscsi /etc/iscsi/initiatorname.iscsi
		chmod 600 /etc/iscsi/initiatorname.iscsi
	    fi
	fi

	if dpkg --compare-versions "$2" le-nl "2.0.873+git0.3b4b4500-12" ; then
	    # Handle the fact that /etc/iscsi/initiatorname.iscsi is no longer
	    # a conffile of this package but we want to keep it.
	    if [ -f /etc/iscsi/initiatorname.iscsi.dpkg-backup ] && ! [ -f /etc/iscsi/initiatorname.iscsi ] ; then
		mv -f /etc/iscsi/initiatorname.iscsi.dpkg-backup /etc/iscsi/initiatorname.iscsi
	    fi
	fi

	# Compatibility symlinks
	for file in iscsid iscsi_discovery iscsi-iname iscsistart; do
		if [ ! -e /usr/sbin/$file ]; then
			ln -s /sbin/$file /usr/sbin/$file
		fi
	done

	# Obsolete: only open-iscsi 1.0, never even shipped with any
	# stable Debian release. But postinst up to Jessie still
	# created this directory, so keep this until at least Stretch.
	if [ -d /var/lib/open-iscsi ]; then
		rmdir --ignore-fail-on-non-empty /var/lib/open-iscsi
	fi

        # generate a unique iSCSI InitiatorName
        NAMEFILE=/etc/iscsi/initiatorname.iscsi
        if [ ! -e $NAMEFILE ] && [ -z "$2" ] ; then
            # Generate a unique InitiatorName and save it
            INAME=$(iscsi-iname -p iqn.1993-08.org.debian:01)
            if [ -n "$INAME" ] ; then
                echo "## DO NOT EDIT OR REMOVE THIS FILE!" > $NAMEFILE
                echo "## If you remove this file, the iSCSI daemon will not start." >> $NAMEFILE
                echo "## If you change the InitiatorName, existing access control lists" >> $NAMEFILE
                echo "## may reject this initiator.  The InitiatorName must be unique">> $NAMEFILE
                echo "## for each iSCSI initiator.  Do NOT duplicate iSCSI InitiatorNames." >> $NAMEFILE
                printf "InitiatorName=%s\n" "$INAME" >> $NAMEFILE
                chmod 600 $NAMEFILE
            else
                echo "Error: failed to generate an iSCSI InitiatorName, driver cannot start."
                echo
                exit 1;
            fi
        fi
    ;;

    abort-upgrade|abort-remove|abort-deconfigure)
    ;;

    *)
        echo "postinst called with unknown argument \`$1'" >&2
        exit 1
    ;;
esac

# Automatically added by dh_systemd_enable
# This will only remove masks created by d-s-h on package removal.
deb-systemd-helper unmask iscsid.service >/dev/null || true

# was-enabled defaults to true, so new installations run enable.
if deb-systemd-helper --quiet was-enabled iscsid.service; then
	# Enables the unit on first installation, creates new
	# symlinks on upgrades if the unit file has changed.
	deb-systemd-helper enable iscsid.service >/dev/null || true
else
	# Update the statefile to add new symlinks (if any), which need to be
	# cleaned up on purge. Also remove old symlinks.
	deb-systemd-helper update-state iscsid.service >/dev/null || true
fi
# End automatically added section
# Automatically added by dh_systemd_enable
# This will only remove masks created by d-s-h on package removal.
deb-systemd-helper unmask iscsid.service >/dev/null || true

# was-enabled defaults to true, so new installations run enable.
if deb-systemd-helper --quiet was-enabled iscsid.service; then
	# Enables the unit on first installation, creates new
	# symlinks on upgrades if the unit file has changed.
	deb-systemd-helper enable iscsid.service >/dev/null || true
else
	# Update the statefile to add new symlinks (if any), which need to be
	# cleaned up on purge. Also remove old symlinks.
	deb-systemd-helper update-state iscsid.service >/dev/null || true
fi
# End automatically added section
# Automatically added by dh_systemd_enable
# This will only remove masks created by d-s-h on package removal.
deb-systemd-helper unmask open-iscsi.service >/dev/null || true

# was-enabled defaults to true, so new installations run enable.
if deb-systemd-helper --quiet was-enabled open-iscsi.service; then
	# Enables the unit on first installation, creates new
	# symlinks on upgrades if the unit file has changed.
	deb-systemd-helper enable open-iscsi.service >/dev/null || true
else
	# Update the statefile to add new symlinks (if any), which need to be
	# cleaned up on purge. Also remove old symlinks.
	deb-systemd-helper update-state open-iscsi.service >/dev/null || true
fi
# End automatically added section
# Automatically added by dh_installinit
if [ "$1" = "configure" ] || [ "$1" = "abort-upgrade" ]; then
	if [ -x "/etc/init.d/iscsid" ]; then
		update-rc.d iscsid defaults >/dev/null || exit $?
	fi
fi
# End automatically added section
# Automatically added by dh_installinit
if [ "$1" = "configure" ] || [ "$1" = "abort-upgrade" ]; then
	if [ -x "/etc/init.d/open-iscsi" ]; then
		update-rc.d open-iscsi defaults >/dev/null || exit $?
	fi
fi
# End automatically added section
# Automatically added by dh_installdeb
dpkg-maintscript-helper rm_conffile /etc/init.d/umountiscsi.sh 2.0.873+git0.3b4b4500-9 -- "$@"
# End automatically added section
# Automatically added by dh_installdeb
dpkg-maintscript-helper rm_conffile /etc/init/iscsi-network-interface.conf 2.0.873-3ubuntu12~ -- "$@"
# End automatically added section


if [ "$1" = configure ] ; then
    # There already is a check in preinst with a debconf prompt that
    # allows the administrator to abort. Don't abort here, because
    # leaving the package in a half-configured state is probably worse.
    # Just make sure to wait a while to see if recovery happens. If
    # not, proceed anyway.
    RETRIES=0
    while cat /sys/class/iscsi_session/session*/state 2>/dev/null | grep -qv LOGGED_IN ; do
        if [ $RETRIES -eq 0 ] ; then
            echo "open-iscsi postinst: since the check in preinst some iSCSI sessions have" >&2
            echo "                     failed. -> will wait 30s for automatic recovery" >&2
        fi
        if [ $RETRIES -gt 30 ]; then
            echo "open-iscsi postinst: some sessions are still in failed state -> iscsid" >&2
            echo "                     will be restarted regardless, since that may" >&2
            echo "                     actually help with the session recovery." >&2
            break
        fi
        RETRIES=$((RETRIES + 1))
        sleep 1
    done

    # Before we restart iscsid, we should increase the recovery timeout
    # significantly. Thanks to Mike Christie (open-iscsi upstream) for
    # the suggestion. But store the old timeouts and restore them
    # later.
    new_timeout=120
    mkdir -m 0700 -p /run/open-iscsi/upgrade
    rm -f /run/open-iscsi/upgrade/restore_old_timeouts
    trap restore_old_timeouts EXIT
    for settingfile in /sys/class/iscsi_session/session*/recovery_tmo ; do
        [ -f "${settingfile}" ] || continue
        setting="$(cat "$settingfile" 2>/dev/null || :)"
        if [ -n "$setting" ] ; then
            echo "echo "'"'"${setting}"'"'" > "'"'"${settingfile}"'" 2>/dev/null' >> /run/open-iscsi/upgrade/restore_old_timeouts
        fi
        if [ ${new_timeout} -gt ${setting} ] ; then
            echo ${new_timeout} > "${settingfile}" 2>/dev/null
        fi
    done

    # Just in case something goes wrong:
    sync

    # We are upgrading from a pre-Stretch version of open-iscsi. There,
    # we only had an open-iscsi init script. Since we now have iscsid
    # for the daemon (which is and should be restarted on upgrades) and
    # open-iscsi for logging in to the targets (which shouldn't be
    # touched on upgrades, especially not restarted, because we don't
    # want the storage stack to suddenly disappear on package
    # installation!), we have to manually take care of this.
    #
    # Notes:
    #   - kill iscsid directly, don't use the old stop script, since
    #     we don't want to sever any connection. Can't use the new
    #     stop script, because systemd tracks service status. Note
    #     that services from init scripts have RemainAfterExit=yes, so
    #     manually killing it is OK with systemd and the open-iscsi
    #     service will still be considered to be started.
    #   - use PIDFILE, not killall, since support for namespacing iSCSI
    #     might come to the kernel soon (maybe 4.2?). Since that will
    #     require no userspace change, people might run Jessie with a
    #     backported kernel that supports this, and we REALLY don't
    #     want to kill iscsid in containers (LXC, nspawn, ...)
    #
    # For safety, this upgrade path should be kept until at least
    # Buster.
    if dpkg --compare-versions "$2" le-nl "2.0.873+git0.3b4b4500-9"; then
        # We need to query invoke-rc.d here to comply with Debian's
        # policy, so we check if the old stop script would have been
        # executed.
        set +e
        invoke-rc.d --query open-iscsi stop
        POLICY_RC=$?
        set -e
        # invoke-rc.d will return 105 if there is no policy-rc.d.
        # Also, even if there is a policy-rc.d and that returns 105
        # ('undefined behavior'), invoke-rc.d will assume that it may
        # in fact execute the action. Therefore, we will treat exit
        # code 105 the same as exit code 104 here.
        if [ $POLICY_RC -eq 104 ] || [ $POLICY_RC -eq 105 ] ; then
            PIDFILE=/var/run/iscsid.pid
            if ! start-stop-daemon --oknodo --stop --quiet \
                                   --pidfile "$PIDFILE" \
                                   --name iscsid --signal TERM \
                                   --retry 30 ; then
                # Check if it's still running, as error exit by
                # start-stop-daemon might not be an actual error.
                if [ -s $PIDFILE ] && kill -0 `sed -n 1p $PIDFILE` >/dev/null 2>/dev/null ; then
                    echo "ERROR: Could not terminate old iscsid on upgrade, your system is most" >&2
                    echo "likely hung. Don't know what to do, sorry! Aborting." >&2
                    exit 1
                fi
            fi
            rm -f $PIDFILE
            unset PIDFILE
        fi

        # Note: 3>&- is required because iscsid doesn't close unused
        #       FDs, but debconf/confmodule will make the fd 3 point to
        #       the original stdout (and stdout to stderr) to make sure
        #       no program accidentally issues a command on stdout. On
        #       sysvinit systems this combination (iscsid not closing
        #       fds, fd 3 remaining open) will cause dpkg to wait
        #       forever for the maintscript to finish. (iscsid keeps
        #       this end of the pipe open even though the maintscript
        #       is finished, so dpkg will never receive a POLLHUP on
        #       its end of the pipe, waiting forever.) Closing fd 3
        #       here is the simplest solution. This issue does not
        #       occur with other init systems, since they start
        #       services in a clean environment without any extraneous
        #       open fds.
        invoke-rc.d iscsid start 3>&-
    else
        if [ -n "$2" ]; then
            invoke-rc.d iscsid restart 3>&-
        else
            invoke-rc.d iscsid start 3>&-
        fi
    fi

    RETRIES=0
    while cat /sys/class/iscsi_session/session*/state 2>/dev/null | grep -qv LOGGED_IN ; do
        if [ $RETRIES -eq 0 ]; then
            echo "open-iscsi postinst: after iscsid restart, waiting for iSCSI sessions" >&2
            echo "                     to recover. This may take a couple of seconds." >&2
        fi

        if [ $RETRIES -gt ${new_timeout} ]; then
            db_reset open-iscsi/upgrade_recovery_error || true
            db_input critical open-iscsi/upgrade_recovery_error || true
            db_go
            break
        fi

        RETRIES=$((RETRIES + 1))
        sleep 1
    done

    restore_old_timeouts
    trap - EXIT

    # Don't restart (and therefore stop) open-iscsi, because we don't
    # want to logout from targets during a simple upgrade. But also,
    # if for some reason there's some misconfigured target in the
    # config that couldn't be activated, don't break postinst, so
    # ignore the exit code.
    # See above for why 3>&- is here. (Technically it's not required
    # for postinst to work, but vgchange likes to complain about leaked
    # file descriptors, and we don't need to show that message to the
    # user.)
    invoke-rc.d open-iscsi start 3>&- || true
fi

exit 0