Repository navigation
Expand file tree
/
Copy pathservices.html
More file actions
158 lines (158 loc) · 18 KB
/
Copy pathservices.html
File metadata and controls
158 lines (158 loc) · 18 KB
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
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Services - UraniumOS</title>
<link rel="stylesheet" href="style.css">
</head>
<body>
<header><div class="in"><nav class="l"><a href="index.html">Home</a><a href="download.html">Download</a><a href="docs.html" aria-current="page">Documentation</a><a href="rod.html">Packages</a><a href="news.html">News</a><a href="about.html">About</a></nav><nav class="r"><a href="features.html">Features</a><a href="media.html">Install</a><a href="security.html">Security</a><a href="hardware.html">Hardware</a></nav></div></header>
<main class="in docs">
<aside><div class="sbhead"><a class="sbh" href="index.html">⌂ UraniumOS</a><svg aria-hidden="true" viewBox="-50 -50 100 100"><circle r="48" fill="#f2d21b"/><circle r="6.5" fill="#1b1b19"/><path fill="#1b1b19" d="M6.50 -11.26 A13 13 0 0 0 -6.50 -11.26 L-20.00 -34.64 A40 40 0 0 1 20.00 -34.64 Z M-13.00 -0.00 A13 13 0 0 0 -6.50 11.26 L-20.00 34.64 A40 40 0 0 1 -40.00 -0.00 Z M6.50 11.26 A13 13 0 0 0 13.00 0.00 L40.00 0.00 A40 40 0 0 1 20.00 34.64 Z"/></svg><span class="ver">0.1.1</span><input type="search" placeholder="Search docs" aria-label="Search docs"></div><h4>Read first</h4><ul><li><a href="differences.html">Differences and known failures</a></li></ul><h4>1 Installation</h4><ul><li><a href="download.html">1.1 Download</a></li><li><a href="media.html">1.2 Live medium</a></li><li><a href="partitioning.html">1.3 Partitioning notes</a></li><li><a href="manual-install.html">1.4 Manual install</a></li><li><a href="first-steps.html">1.5 First steps</a></li></ul><h4>2 Configuration</h4><ul><li><a href="users.html">2.1 Users and groups</a></li><li><a href="keyboard.html">2.2 Keyboard</a></li><li><a href="time.html">2.3 Date and time</a></li><li><a href="services.html" aria-current="page">2.4 Services</a></li><li><a href="cron.html">2.5 Cron</a></li><li><a href="network.html">2.6 Network</a></li><li><a href="ssh.html">2.7 SSH</a></li><li><a href="blastdoor.html">2.8 Firewall</a></li><li><a href="desktop.html">2.9 Desktop</a></li><li><a href="firmware.html">2.10 Firmware</a></li><li><a href="boot.html">2.11 Boot</a></li><li><a href="kernel.html">2.12 Kernel</a></li><li><a href="storage.html">2.13 Storage</a></li><li><a href="security.html">2.14 Security</a></li><li><a href="geiger.html">2.15 Health report</a></li></ul><h4>3 Packages</h4><ul><li><a href="rod.html">3.1 rod</a></li><li><a href="cheatsheet.html">3.2 rod cheat sheet</a></li><li><a href="not-in-rod.html">3.3 Package not in rod</a></li><li><a href="recipes.html">3.4 Recipes</a></li><li><a href="silo.html">3.5 Containers</a></li><li><a href="hazmat.html">3.6 Sandboxes</a></li></ul><h4>4 Snapshots</h4><ul><li><a href="scram.html">4.1 scram</a></li><li><a href="backups.html">4.2 Backups</a></li></ul><h4>5 Reference</h4><ul><li><a href="system.html">5.1 System and files</a></li><li><a href="troubleshooting.html">5.2 Troubleshooting</a></li><li><a href="hardware.html">5.3 Hardware status</a></li><li><a href="faq.html">5.4 FAQ</a></li></ul><h4>6 Project</h4><ul><li><a href="developers.html">6.1 Developers</a></li><li><a href="contributing.html">6.2 Contributing</a></li><li><a href="about.html">6.3 About</a></li><li><a href="features.html">6.4 Features</a></li><li><a href="news.html">6.5 News</a></li></ul></aside><article><div class="band"><h1>Services</h1></div>
<p>UraniumOS supervises services with runit. The kernel starts the initramfs, the initramfs starts busybox init as process 1, and init reads <code>/etc/inittab</code>:</p>
<pre><code>::sysinit:/etc/rc
::respawn:/rod/profile/bin/runsvdir -P /etc/service
::ctrlaltdel:/rod/init/bin/reboot
::shutdown:/etc/rc.shutdown</code></pre>
<p>init runs <code>/etc/rc</code> once, keeps <code>runsvdir</code> running on <code>/etc/service</code>, runs <code>reboot</code> on Ctrl-Alt-Del and runs <code>/etc/rc.shutdown</code> at shutdown. <code>runsvdir</code>, <code>sv</code> and <code>svlogd</code> come from the runit package in <code>/rod/profile/bin</code>. The busybox applets are in <code>/rod/init/bin</code>, which is not on the <code>PATH</code> of a login shell, see <a href="system.html">system</a>. Jobs that run at fixed times belong in <a href="cron.html">cron</a>.</p>
<p>A process list of a freshly booted system, shortened:</p>
<pre><code> 1 0 root init
158 1 root /rod/profile/bin/sh /etc/rc
160 1 root /rod/profile/bin/runsvdir -P /etc/service
164 160 root runsv dhcp
165 160 root runsv getty-tty1
166 160 root runsv getty-ttyS0
167 160 root runsv autoframe
168 160 root runsv ntpd
169 160 root runsv crond
170 160 root runsv trial
182 164 root udhcpc -f -i eth0 -s /etc/udhcpc.script
184 169 root crond -f -c /etc/crontabs</code></pre>
<p>Process 158 is the <code>/etc/rc</code> shell.</p>
<h2>What /etc/rc does</h2>
<p><code>/etc/rc</code> is a shell script (bash from the profile) that runs with <code>PATH=/rod/profile/bin:/rod/init/bin</code>. It keeps going when a command fails. It:</p>
<ol>
<li>mounts <code>/proc</code>, <code>/sys</code> and <code>/dev</code> if the kernel has not, then <code>/dev/pts</code>, <code>/dev/shm</code> (<code>nosuid,nodev,noexec</code>) and <code>/tmp</code> (<code>nosuid,nodev</code>, mode 1777), and sets the kernel log level to 3;</li>
<li>mounts a tmpfs on <code>/run</code>. If the initramfs mounted the btrfs top level at <code>/run/scram/top</code>, it is moved onto the new <code>/run</code>;</li>
<li>remounts <code>/</code> read-write and runs <code>mount -a</code> for <code>/etc/fstab</code> (<code>/home</code> and <code>/boot</code>);</li>
<li>sets the hostname from <code>/etc/hostname</code>;</li>
<li>loads the console keymap named in <code>/etc/keymap</code>, see <a href="keyboard.html">keyboard</a>;</li>
<li>applies <code>/etc/sysctl.conf</code> and loads the firewall <code>/etc/nftables.conf</code>, see <a href="blastdoor.html">blastdoor</a>;</li>
<li>creates a zram swap device of half the memory. It asks for <code>zstd</code> compression, but the 0.1.0 image ends up with lzo-rle;</li>
<li>brings up <code>lo</code> with 127.0.0.1;</li>
<li>runs <code>/etc/rc.local</code> if it exists. The shell sources the file as root before any service starts;</li>
</ol>
<h3>Shutdown</h3>
<p><code>/etc/rc.shutdown</code> runs <code>sync</code> and <code>umount -a -r</code>, which remounts what it cannot unmount read-only. <code>reboot</code>, <code>poweroff</code> and <code>halt</code> are busybox applets in <code>/rod/init/bin</code>. Call them as <code>/rod/init/bin/reboot</code> or add that directory to your <code>PATH</code>.</p>
<h2>Service directories</h2>
<p>A service is a directory in <code>/etc/sv</code>. It is enabled when a link to it exists in <code>/etc/service</code>. <code>runsvdir</code> checks <code>/etc/service</code> every five seconds, starts a <code>runsv</code> supervisor for each new link and stops the supervisor of each removed link. The directory can hold:</p>
<dl>
<dt><code>run</code></dt><dd>Required, executable. It has to <code>exec</code> a process that stays in the foreground. When the process exits, <code>runsv</code> starts <code>run</code> again after one second.</dd>
<dt><code>log/run</code></dt><dd>Optional. The standard output of <code>run</code> goes through a pipe to this program. The log scripts that ship create <code>/var/log/NAME</code> and <code>exec svlogd -tt /var/log/NAME</code>.</dd>
<dt><code>finish</code></dt><dd>Optional. Runs when <code>run</code> exits.</dd>
<dt><code>check</code></dt><dd>Optional. <code>sv check</code> runs it, and exit status 0 means the service works.</dd>
<dt><code>down</code></dt><dd>An empty file. The supervisor starts but the service does not.</dd>
<dt><code>sandbox</code></dt><dd>Read by <code>hazmat -s</code>, see below.</dd>
<dt><code>supervise/</code></dt><dd>Made by <code>runsv</code>, mode 0700. It holds <code>control</code>, <code>lock</code>, <code>ok</code>, <code>pid</code>, <code>stat</code> and <code>status</code>.</dd>
</dl>
<p>A <code>run</code> script gets the environment that <code>runsvdir</code> inherited from init. <code>SVDIR</code> is only set by <code>/etc/profile</code>, so <code>sv check dhcp</code> inside a script fails and the script has to name the service by path.</p>
<p>The standard error of <code>run</code> is not part of the log pipe. Without <code>exec 2>&1</code> it goes to the console. The scripts of <code>dhcp</code>, <code>ntpd</code>, <code>crond</code> and <code>sshd</code> use <code>exec 2>&1</code>, and <code>autoframe</code> and <code>trial</code> do not.</p>
<h2>Control with sv</h2>
<p>In a login shell <code>SVDIR=/etc/service</code>, so <code>sv</code> takes a service name or a path. Anywhere else pass <code>/etc/service/NAME</code>.</p>
<pre><code># sv status /etc/service/*
run: /etc/service/autoframe: (pid 174) 4s; run: log: (pid 173) 4s
run: /etc/service/crond: (pid 184) 4s; run: log: (pid 183) 4s
run: /etc/service/dhcp: (pid 182) 4s; run: log: (pid 181) 4s
run: /etc/service/getty-tty1: (pid 179) 4s
run: /etc/service/getty-ttyS0: (pid 180) 4s
run: /etc/service/ntpd: (pid 186) 4s; run: log: (pid 171) 4s
run: /etc/service/trial: (pid 172) 4s</code></pre>
<dl>
<dt><code>sv up NAME</code>, <code>sv down NAME</code></dt><dd>Start the service and keep it running, or stop it and keep it stopped. A <code>down</code> state does not survive a reboot.</dd>
<dt><code>sv once NAME</code></dt><dd>Start the service once and do not restart it when it exits.</dd>
<dt><code>sv restart NAME</code></dt><dd>Stop and start. It reports the service as running when it is up again.</dd>
<dt><code>sv check NAME</code></dt><dd>Reports that the service is running and exits with status 0 when it is up.</dd>
<dt><code>sv status NAME</code></dt><dd>One line, see the table.</dd>
<dt><code>sv exit NAME</code>, <code>sv term NAME</code>, <code>sv hup NAME</code>, <code>sv kill NAME</code></dt><dd>Stop the supervisor, or send the signal to the service. See sv(8) of runit.</dd>
<dt><code>sv alarm NAME</code></dt><dd>Sends SIGALRM. On a <code>log</code> directory (<code>sv a /etc/service/dhcp/log</code>) it makes <code>svlogd</code> rotate the log.</dd>
</dl>
<p>Status lines:</p>
<table>
<tr><td><code>run: ntpd: (pid 219) 1s; run: log: (pid 171) 6s</code></td><td>Running, with its log process.</td></tr>
<tr><td><code>down: ntpd: 1s, normally up; run: log: (pid 171) 5s</code></td><td>Stopped with <code>sv down</code>.</td></tr>
<tr><td><code>run: crond: (pid 222) 3s, want down</code></td><td>Started with <code>sv once</code>.</td></tr>
<tr><td><code>down: web: 5s</code></td><td>Has a <code>down</code> file and has not been started.</td></tr>
<tr><td><code>down: bad1: 1s, normally up, want up</code></td><td>The <code>run</code> script keeps exiting and is being restarted.</td></tr>
<tr><td><code>fail: nosuch: unable to change to service directory: file does not exist</code></td><td>No such name in <code>SVDIR</code>.</td></tr>
</table>
<h3>Enable and disable</h3>
<pre><code># ln -s /etc/sv/sshd /etc/service/sshd
# rm /etc/service/sshd</code></pre>
<p>A new link starts the service within five seconds and at every later boot. Removing the link stops the supervisor and the service within about seven seconds. A link can also be made from a chroot, so a service can be enabled before the first boot.</p>
<h3>Try a service before it starts at boot</h3>
<pre><code># touch /etc/sv/web/down
# ln -s /etc/sv/web /etc/service/web
# sv once /etc/service/web
# sv status /etc/service/web
run: /etc/service/web: (pid 241) 1s, normally down, want down</code></pre>
<p>Remove the <code>down</code> file and run <code>sv up</code> when it works. <a href="geiger.html">geiger</a> skips services that have a <code>down</code> file.</p>
<h2>Logs</h2>
<p><code>svlogd -tt</code> writes <code>/var/log/NAME/current</code> with UTC timestamps, whatever the time zone is:</p>
<pre><code># cat /var/log/dhcp/current
2026-11-02_16:53:09.65038 udhcpc: started, v1.37.0
2026-11-02_16:53:09.66001 udhcpc: broadcasting discover
2026-11-02_16:53:09.68126 udhcpc: broadcasting select for 10.0.2.15, server 10.0.2.2
2026-11-02_16:53:09.70119 udhcpc: lease of 10.0.2.15 obtained from 10.0.2.2, lease time 86400</code></pre>
<p>When <code>current</code> reaches the size limit, or on SIGALRM, <code>svlogd</code> renames it to <code>@TAI64N.s</code> and starts a new file. The limits are the runit defaults, 1,000,000 bytes and 10 files.</p>
<p>A <code>log</code> directory added to a service that is already supervised is not used, and no <code>/var/log/NAME/current</code> appears. Create the log before the first start, or remove the link, wait for the supervisor to exit and link it again.</p>
<p>The logs are on the root subvolume, so every <a href="scram.html">frame</a> has them.</p>
<h2>The services of the system</h2>
<p>The stage links the seven services in the first block. <code>setup --ssh</code> links <code>sshd</code>, and <code>uranium-desktop</code> creates the last two.</p>
<table>
<tr><td><code>getty-tty1</code></td><td><code>getty -l /rod/init/bin/login 38400 tty1</code>. The login prompt of the first virtual console. No log.</td></tr>
<tr><td><code>getty-ttyS0</code></td><td><code>getty -l /rod/init/bin/login -L 115200 ttyS0 vt100</code>. The serial console. No log.</td></tr>
<tr><td><code>dhcp</code></td><td>Waits for a network device with a <code>device</code> entry in <code>/sys/class/net</code>, brings the first one up and runs <code>udhcpc -f</code> on it. See <a href="network.html">network</a>. Log: <code>/var/log/dhcp</code>.</td></tr>
<tr><td><code>ntpd</code></td><td><code>ntpd -n -p pool.ntp.org -p time.cloudflare.com</code>. See <a href="time.html">time</a>. Log: <code>/var/log/ntpd</code>.</td></tr>
<tr><td><code>crond</code></td><td><code>crond -f -c /etc/crontabs</code>. See <a href="cron.html">cron</a>. Log: <code>/var/log/crond</code>.</td></tr>
<tr><td><code>autoframe</code></td><td>Sleeps 3600 seconds, runs <code>scram auto 48</code> and exits, and <code>runsv</code> starts it again. The first frame comes an hour after boot. <code>scram auto</code> takes a frame labelled <code>auto</code> and deletes the older automatic frames beyond the newest 48. Log: <code>/var/log/autoframe</code>, which stays empty.</td></tr>
<tr><td><code>trial</code></td><td>Runs <code>scram verify</code>, sleeps 3600 seconds and repeats. <code>scram verify</code> returns at once unless an update is on trial. On trial it waits 300 seconds, runs <a href="geiger.html">geiger</a> up to three times 30 seconds apart, confirms the update on success and reboots on failure. See <a href="scram.html">scram</a>. No log.</td></tr>
<tr><td><code>sshd</code></td><td>Creates <code>/var/empty</code>, creates the ed25519 host key if it is missing and runs <code>sshd -D -e</code>. See <a href="ssh.html">ssh</a>. Log: <code>/var/log/sshd</code>.</td></tr>
<tr><td><code>udevd</code>, <code>seatd</code></td><td>Added and linked by <code>uranium-desktop USER</code> for the desktop profile.</td></tr>
</table>
<h2>Write a service</h2>
<p>This service serves <code>/srv/www</code> with the busybox web server. It is called by full path because busybox is not on the <code>PATH</code> of the scripts.</p>
<pre><code># mkdir -p /etc/sv/web/log /srv/www
# cat > /etc/sv/web/run <<'EOF'
#!/rod/profile/bin/sh
exec 2>&1
exec /rod/init/bin/httpd -f -p 8080 -h /srv/www
EOF
# cat > /etc/sv/web/log/run <<'EOF'
#!/rod/profile/bin/sh
mkdir -p /var/log/web
exec svlogd -tt /var/log/web
EOF
# chmod +x /etc/sv/web/run /etc/sv/web/log/run
# ln -s /etc/sv/web /etc/service/web</code></pre>
<p>Open the port for other machines with <code>blastdoor allow 8080</code>. A <code>run</code> script that is not executable fails once a second, with an error on the console. A script that runs a program that does not exist fails the same way.</p>
<h2>Start order</h2>
<p>All services start together. To wait for another one, test it in <code>run</code> and exit while it is down. <code>runsv</code> starts the script again a second later:</p>
<pre><code>sv check /etc/service/dhcp > /dev/null || exit 1</code></pre>
<p>The path form is needed because <code>SVDIR</code> is not set in a script.</p>
<h2>Sandbox a service</h2>
<p><code>hazmat -s COMMAND</code> in a <code>run</code> script reads the file <code>sandbox</code> in the current directory. <code>runsv</code> starts <code>run</code> in the service directory, and <code>HAZMAT_FILE</code> changes the name. Without the file the command runs without a sandbox. Each line is one of:</p>
<dl>
<dt><code>ro PATH</code></dt><dd>Bind the path read-only.</dd>
<dt><code>rw PATH</code></dt><dd>Bind the path writable. It is created if missing.</dd>
<dt><code>net</code>, <code>nonet</code></dt><dd>Share the host network, or not. The default is no network.</dd>
</dl>
<p>Blank lines and lines starting with <code>#</code> are ignored, and any other word stops hazmat with <code>unknown line</code>. hazmat then runs <code>bwrap --unshare-all</code>, with <code>--share-net</code> for <code>net</code>, and binds <code>/nix</code>, <code>/rod/profile</code>, <code>/bin</code>, <code>/usr</code>, <code>/lib</code>, <code>/lib64</code>, <code>/etc/ssl</code> and <code>/etc/resolv.conf</code> read-only, with a fresh <code>/proc</code>, <code>/dev</code> and <code>/tmp</code>. <code>/rod/init</code> is not bound, so use programs from the profile. The service keeps it's user id. See <a href="hazmat.html">hazmat</a>.</p>
<div class="pager"><a href="time.html">← Date and time</a><a href="cron.html">Cron →</a></div></article>
</main>
<footer><div class="in"><p>Public domain, CC0 1.0</p><p><a href="https://github.com/uranium-os">GitHub</a> <a href="https://texivi.github.io">Blog</a></p></div></footer>
<script>document.querySelectorAll("pre:not(.term):not(.portrait)").forEach(function(p){var b=document.createElement("button");b.textContent="\u29c9";b.title="Copy";b.onclick=function(){navigator.clipboard.writeText(p.innerText.replace(/\u29c9$/,"").trim());b.textContent="\u2713";setTimeout(function(){b.textContent="\u29c9"},900)};p.appendChild(b)});</script>
<script src="docs.js"></script>
<script src="fun.js"></script>
</body>
</html>