#!@shebangdir@/execlineb -P

# ISC license.

tryexec { ./stage3b }

if -n {
	foreground { echo "\nshutdown\n" }
	foreground { s6-rc -l @tmpfsdir@/@sysrundir@/s6-rc -v2 -b -Da -t@timeout@ change }
	foreground {
		pipeline { ls -1 @tmpfsdir@/@sysrundir@/service/ }
		pipeline {
			sed
				-e /s6-svscan-log/d
				-e /.s6-svscan/d
				-e /goetia-shutdown/d
				-e /goetia-rescue/d
		}
		forstdin -pE SERVICE
			s6-svc -T @timeout@ -D @tmpfsdir@/@sysrundir@/service/${SERVICE}
	}

	foreground { rm -Rf -- @syslogdir@/uncaught-logs }
	foreground { cp -Rpf -- @tmpfsdir@/@sysrundir@/log/uncaught-logs @syslogdir@/ }

	foreground { chmod u+x ./stage3b }
	foreground { echo "sending all processes the TERM signal..." }
	foreground { kill -SIGTERM -- -1 }
}
foreground { touch ./down }
chmod a-x ./stage3b
