commit b8a17417c81ec8f9e34e98cfcdbfa247842ef39d
parent 57269ca111b21f34eab6b404d5c827d7e8666cb7
Author: torter <koubbamohamedrayan@gmail.com>
Date: Sat, 14 Nov 2026 20:18:42 +0000
init: the service scripts move to /etc/rc.d like FreeBSD, /etc/services is the port name file again, an /etc/hosts
Diffstat:
16 files changed, 120 insertions(+), 80 deletions(-)
diff --git a/files/etc/hosts b/files/etc/hosts
@@ -0,0 +1,2 @@
+127.0.0.1 localhost
+::1 localhost
diff --git a/files/etc/rc.d/NetworkManager b/files/etc/rc.d/NetworkManager
@@ -0,0 +1,5 @@
+#!/bin/sh
+. /etc/rc.subr
+procname=NetworkManager
+svc_start() { NetworkManager; }
+run "$1"
diff --git a/files/etc/rc.d/dbus b/files/etc/rc.d/dbus
@@ -0,0 +1,11 @@
+#!/bin/sh
+. /etc/rc.subr
+procname=dbus-daemon
+svc_start() {
+ mkdir -p /var/lib/dbus /run/dbus
+ chown dbus:dbus /run/dbus
+ [ -s /var/lib/dbus/machine-id ] || dbus-uuidgen --ensure=/var/lib/dbus/machine-id
+ rm -f /run/dbus/pid
+ dbus-daemon --system
+}
+run "$1"
diff --git a/files/etc/rc.d/modules b/files/etc/rc.d/modules
@@ -0,0 +1,10 @@
+#!/bin/sh
+. /etc/init.sh
+. /etc/rc.subr
+svc_start() {
+ for m in $(conf modules); do
+ modprobe "$m" || log "cannot load $m"
+ done
+}
+svc_stop() { :; }
+run "$1"
diff --git a/files/etc/rc.d/network b/files/etc/rc.d/network
@@ -0,0 +1,5 @@
+#!/bin/sh
+. /etc/rc.subr
+procname=dhcpcd
+svc_start() { mkdir -p /var/db/dhcpcd /run/dhcpcd; dhcpcd; }
+run "$1"
diff --git a/files/etc/rc.d/udev b/files/etc/rc.d/udev
@@ -0,0 +1,9 @@
+#!/bin/sh
+. /etc/rc.subr
+procname=udevd
+svc_start() {
+ udevd --daemon || return
+ udevadm trigger && udevadm settle
+}
+svc_stop() { udevadm control --exit; }
+run "$1"
diff --git a/files/etc/rc.subr b/files/etc/rc.subr
@@ -0,0 +1,35 @@
+# what a script in /etc/rc.d uses: set procname, define svc_start (and svc_stop, svc_status if the
+# defaults do not fit), then call run "$1"
+name=${0##*/}
+
+log() { echo "$name: $*"; }
+
+pids() {
+ for _d in /proc/[0-9]*; do
+ read -r _c 2>/dev/null < $_d/comm && [ "$_c" = "${1:0:15}" ] && echo ${_d#/proc/}
+ done
+}
+
+running() { [ -n "$procname" ] && [ -n "$(pids $procname)" ]; }
+
+svc_stop() {
+ running || return 0
+ kill $(pids $procname)
+ _n=0
+ while running && [ $_n -lt 10 ]; do sleep 1; _n=$((_n + 1)); done
+}
+
+svc_status() {
+ [ -n "$procname" ] || { log "nothing to report"; return 0; }
+ if running; then log "running as pid $(pids $procname)"; else log "not running"; return 1; fi
+}
+
+run() {
+ case $1 in
+ start) if running; then log "already running"; else svc_start; fi;;
+ stop) svc_stop;;
+ restart) svc_stop; svc_start;;
+ status) svc_status;;
+ *) echo "usage: $0 start|stop|restart|status" >&2; exit 2;;
+ esac
+}
diff --git a/files/etc/services b/files/etc/services
@@ -0,0 +1,37 @@
+# port numbers by name, for getaddrinfo and friends
+echo 7/tcp
+echo 7/udp
+discard 9/tcp
+daytime 13/tcp
+ftp-data 20/tcp
+ftp 21/tcp
+ssh 22/tcp
+telnet 23/tcp
+smtp 25/tcp
+time 37/tcp
+domain 53/tcp
+domain 53/udp
+bootps 67/udp
+bootpc 68/udp
+tftp 69/udp
+gopher 70/tcp
+http 80/tcp
+www 80/tcp
+kerberos 88/tcp
+pop3 110/tcp
+sunrpc 111/tcp
+sunrpc 111/udp
+ntp 123/udp
+imap 143/tcp
+snmp 161/udp
+ldap 389/tcp
+https 443/tcp
+https 443/udp
+submission 587/tcp
+ldaps 636/tcp
+rsync 873/tcp
+imaps 993/tcp
+pop3s 995/tcp
+mysql 3306/tcp
+postgresql 5432/tcp
+http-alt 8080/tcp
diff --git a/files/etc/services.subr b/files/etc/services.subr
@@ -1,35 +0,0 @@
-# what a script in /etc/services uses: set procname, define svc_start (and svc_stop, svc_status if the
-# defaults do not fit), then call run "$1"
-name=${0##*/}
-
-log() { echo "$name: $*"; }
-
-pids() {
- for _d in /proc/[0-9]*; do
- read -r _c 2>/dev/null < $_d/comm && [ "$_c" = "${1:0:15}" ] && echo ${_d#/proc/}
- done
-}
-
-running() { [ -n "$procname" ] && [ -n "$(pids $procname)" ]; }
-
-svc_stop() {
- running || return 0
- kill $(pids $procname)
- _n=0
- while running && [ $_n -lt 10 ]; do sleep 1; _n=$((_n + 1)); done
-}
-
-svc_status() {
- [ -n "$procname" ] || { log "nothing to report"; return 0; }
- if running; then log "running as pid $(pids $procname)"; else log "not running"; return 1; fi
-}
-
-run() {
- case $1 in
- start) if running; then log "already running"; else svc_start; fi;;
- stop) svc_stop;;
- restart) svc_stop; svc_start;;
- status) svc_status;;
- *) echo "usage: $0 start|stop|restart|status" >&2; exit 2;;
- esac
-}
diff --git a/files/etc/services/NetworkManager b/files/etc/services/NetworkManager
@@ -1,5 +0,0 @@
-#!/bin/sh
-. /etc/services.subr
-procname=NetworkManager
-svc_start() { NetworkManager; }
-run "$1"
diff --git a/files/etc/services/dbus b/files/etc/services/dbus
@@ -1,11 +0,0 @@
-#!/bin/sh
-. /etc/services.subr
-procname=dbus-daemon
-svc_start() {
- mkdir -p /var/lib/dbus /run/dbus
- chown dbus:dbus /run/dbus
- [ -s /var/lib/dbus/machine-id ] || dbus-uuidgen --ensure=/var/lib/dbus/machine-id
- rm -f /run/dbus/pid
- dbus-daemon --system
-}
-run "$1"
diff --git a/files/etc/services/modules b/files/etc/services/modules
@@ -1,10 +0,0 @@
-#!/bin/sh
-. /etc/init.sh
-. /etc/services.subr
-svc_start() {
- for m in $(conf modules); do
- modprobe "$m" || log "cannot load $m"
- done
-}
-svc_stop() { :; }
-run "$1"
diff --git a/files/etc/services/network b/files/etc/services/network
@@ -1,5 +0,0 @@
-#!/bin/sh
-. /etc/services.subr
-procname=dhcpcd
-svc_start() { mkdir -p /var/db/dhcpcd /run/dhcpcd; dhcpcd; }
-run "$1"
diff --git a/files/etc/services/udev b/files/etc/services/udev
@@ -1,9 +0,0 @@
-#!/bin/sh
-. /etc/services.subr
-procname=udevd
-svc_start() {
- udevd --daemon || return
- udevadm trigger && udevadm settle
-}
-svc_stop() { udevadm control --exit; }
-run "$1"
diff --git a/files/sbin/service b/files/sbin/service
@@ -1,7 +1,7 @@
#!/bin/sh
# service -l | -e | name start|stop|restart|status
. /etc/init.sh
-dirs="/etc/services /usr/local/etc/services"
+dirs="/etc/rc.d /usr/local/etc/rc.d"
find_script() {
for d in $dirs; do
[ -x "$d/$1" ] && { echo "$d/$1"; return 0; }
diff --git a/handbook/handbook.md b/handbook/handbook.md
@@ -637,7 +637,7 @@ lines are ignored, spaces around `=` are free. A list is in braces and may go ov
The parser is `conf` in `/etc/init.sh`; `conf KEY` prints the value, with a list separated by spaces. A change to
`ttys` or `getty` takes effect at the next boot.
-A service is an executable file in `/etc/services` (or `/usr/local/etc/services`, for the ones you add) that takes
+A service is an executable file in `/etc/rc.d` (or `/usr/local/etc/rc.d`, for the ones you add) that takes
`start`, `stop`, `restart` or `status`. The base set has three: `udev` (starts `udevd`, replays the devices and waits
for them), `modules` and `network` (`dhcpcd`). A name in `boot-services` without a script is skipped with one line
saying so.
@@ -650,12 +650,12 @@ saying so.
service udev status
To add a service, write the script, make it executable, and put its name in `boot-services`. With
-`/etc/services.subr` it is short. Set `procname` to the name the process shows in `/proc/PID/comm`, write
+`/etc/rc.subr` it is short. Set `procname` to the name the process shows in `/proc/PID/comm`, write
`svc_start`, and finish with `run "$1"`; `stop` then kills that process, `status` looks for it and `start` refuses to
start it twice. Override `svc_stop` and `svc_status` if the defaults do not fit:
#!/bin/sh
- . /etc/services.subr
+ . /etc/rc.subr
procname=chronyd
svc_start() { chronyd; }
run "$1"
@@ -1025,7 +1025,8 @@ into a staging directory and prints where the files are.
|------|------|
| `/sbin/init`, `/etc/rc`, `/etc/rc.shutdown` | init, the boot script, the shutdown script, all run by mksh |
| `/etc/init.conf` | host name, boot services, modules, ttys |
-| `/etc/services/`, `/usr/local/etc/services/` | the service scripts |
+| `/etc/rc.d/`, `/usr/local/etc/rc.d/` | the service scripts |
+| `/etc/services`, `/etc/hosts` | port names and the local host name, the libc reads them |
| `/etc/profile` | `PATH`, `EDITOR`, `PAGER`, `umask` |
| `/etc/passwd`, `/etc/group`, `/etc/shells` | accounts, groups, login shells |
| `/etc/fstab` | file systems |