HEX
Server: Apache/2.2.34 (Unix) mod_fastcgi/mod_fastcgi-SNAP-0910052141
System: Linux Kou-Etsu-Dou 4.4.59+ #25556 SMP PREEMPT Thu Mar 4 18:03:46 CST 2021 x86_64
User: hosam (1026)
PHP: 7.2.29
Disabled: NONE
Upload Files
File: //usr/share/init/umount-root-fs.conf
description "unmount root file system when poweroff/reboot"

start on stopped kill-all-process RETRY_COUNT=[12345]
console none

emits umount-root-ok

pre-start script
	/usr/syno/syslog/scripts/service/syslog_rm.sh || true

	/sbin/swapoff /dev/md1 || true
	/sbin/mdadm -S /dev/md1 || true
	/sbin/losetup -D || true
end script

script
	echo "umount root [$RETRY_COUNT]"
	echo `/bin/date` "try umount root [$RETRY_COUNT] times" >> /var/log/upstart/umount-root-fs.log || true
	RETRY_COUNT=$((RETRY_COUNT + 1))
	if [ $RETRY_COUNT -le 5 ]; then
		if ! /bin/umount /; then
			echo "umount fail, killall again"
			sleep 1
			initctl emit --no-wait kill-all-again RETRY_COUNT=$RETRY_COUNT || true
		else
			## if the flag can be success touch, root fs is not read-only
			## record current process for check which one cause umount fail
			if touch /.umount_root_failed > /dev/null 2>&1; then
				echo "umount root failed"
				ps auxf > /.umount_root_failed || true
			else
				echo "umount root success"
			fi
			initctl emit --no-wait umount-root-ok
		fi
	else
		echo `/bin/date` "umount root fail after 5 times, restart init" >> /var/log/upstart/umount-root-fs.log || true
		## umount failed after 5 times, use telinit u to restart init and umount again
		/usr/syno/etc/rc.sysv/system-util.sh handle-umount-root-fail || true
	fi
end script

# vim:ft=upstart