summaryrefslogtreecommitdiffstats
path: root/doc/service/system/goetia-shutdown.html
blob: 7f6a866f6676122dae73c4b83c7af980910e25fe (plain)
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
<!DOCTYPE html>
<html>
	<head>
    	<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
    	<meta http-equiv="Content-Language" content="en" />
		<meta name="viewport" content="width=device-width, initial-scale=1.0" />
    	<title>goetia-shutdown</title>
    	<meta name="Description" content="Shutdown service for FreeBSD providing the actual shutdown procedure." />
    	<meta name="Keywords" content="goetia s6 s6-rc service FreeBSD shutdown" />
	</head>
	<header>
		<p>
			<a href="//0x53.net/software/goetia/goetia-freebsd-init">goetia-freebsd-init</a>
			<br />
			<a href="//0x53.net/software/goetia">goetia</a>
			<br />
			<a href="//0x53.net/software">Software</a>
			<br />
			<a href="//0x53.net">0x53.net</a>
		</p>
	</header>
	<body>
		<h1>The goetia-shutdown service</h1>
		<p>
			goetia-shutdown is the service that starts
			<a href="//0x53.net/software/goetia/goetia-base/bin/system-shutdown-daemon.html">system-shutdown-daemon</a>.
			goetia-shutdown is down by default.
			Starting it initiates the shutdown procedure.
		</p>
		<p>
			goetia-shutdown consists of three scripts:
		</p>
		<h2>run</h2>
		<ul>
			<li>
    			This script just executes system-shutdown-daemon.
			</li>
		</ul>
		<h2>stage3b</h2>
		<ul>
			<li>
    			stage3b tries to execute <code>./stage4</code>,
				which is by default not executable.
				If it can not execute <code>./stage4</code>,
				and <em>only</em> in this case,
				it continues with the following.
			</li>
			<li>
    			It makes <code>./stage4</code> executable.
			</li>
			<li>
    			It sends SIGCONT to all processes.
			</li>
			<li>
    			It sleeps for 1 second.
			</li>
			<li>
    			It writes a banner to its standard out.
			</li>
			<li>
    			It send SIGKILL to all processes.
			</li>
			<li>
    			This also stops the system-shutdown-daemon process.
				It is automatically restarted by the system supervision tree,
				but this time, <em>both</em> the files
				<code>./stage3b</code> and
				<code>./stage4</code>
				are executable.
				Which leads to the execution of <code>./stage4</code>.
			</li>
		</ul>
		<h2>stage4</h2>
		<ul>
    		<li>
    			stage4 reads the envdir at the
    			<code>shutdown-directive</code> subdirectory of the
    			<a href="//0x53.net/software/goetia/rundir.html#system">system runtimedirectory</a>
    			using
    			<a href="https://skarnet.org/software/s6/s6-envdir.html">s6-envdir</a>.
			</li>
			<li>
    			It reads the <code>DIRECTIVE</code> evironment variable,
    			defaulting to <code>-r</code>, if <code>DIRECTIVE</code> is
    			not specified.
			</li>
			<li>
    			It runs <code>umount -A</code>.
			</li>
			<li>
    			It remounts the root filesystem read-only.
			</li>
			<li>
    			It runs <code>shutdown -o ${DIRECTIVE} now</code>.
			</li>
		</ul>
		<h2>Notes</h2>
		<p>
			The entire shutdown procedure roughly works as follows:
		</p>
		<ul>
			<li>
    			This service, running
				<a href="//0x53.net/software/goetia/goetia-base/bin/system-shutdown-daemon.html">system-shutdown-daemon</a>
				gets the instructions from
				<a href="//0x53.net/software/goetia/goetia-freebsd-init/bin/system-shutdown.html">system-shutdown</a>
				to shutdown.
			</li>
			<li>
    			system-shutdown-daemon does most of the shutdown procedure.
				Part of it is to make stage3b executable.
				In the end, system-shutdown-daemon sends SIGTERM to all processes but
				PID 1, including itself.
			</li>
			<li>
    			this service gets restarted automatically.
				system-shutdown-daemon now instantly executes into stage3b.
			</li>
			<li>
    			stage3b makes stage4 executable.
				Followed by sending SIGKILL to all processes
				but PID 1, including itself.
			</li>
			<li>
    			The final restart of this service causes
				system-shutdown-daemon to instantly execute into
				stage3b which instantly executes into stage4,
				which instructs the Kernel to do the actual
				halt, poweroff or reboot.
			</li>
		</ul>
	</body>
</html>