Browse Source

Various minor improvements to sample services

Davin McCall 3 years ago
parent
commit
1dae75ed44

+ 13 - 8
doc/linux/DINIT-AS-INIT.md

@@ -224,7 +224,8 @@ services can then start:
   support signalling readiness via a file descriptor.
 - `late-filesystems` - check and mount any filesystems which are not needed for general
   system operation (i.e. "user" filesystems). It's not expected that other services will
-  depend on this service.
+  depend on this service. This service uses the `late-filesystems.sh` script; configure
+  late filesystems via that script.
 - `dbusd` - starts the DBus daemon (system instance), which is used by other services to
   provide an interface to user processes
 - `dhcpcd` - starts a DHCP client daemon on a network interface (the example uses `enp3s0`).
@@ -263,10 +264,14 @@ which should `exec` dinit (so as to give it the same PID). Don't forget to make
 executable and to include the shebang line (`#!/bin/sh` or similar).
 
 You can run a shell directly on a virtual terminal by adding a `ttyN` service or modifying one
-of the existing ones (see the example services). You can remove most or all dependencies from
-this service so that it starts early, and set the `no-sigterm` option, as well as setting
-`stop-timeout = 0` (i.e. disabling stop timeout), so that it will not be killed at shutdown
-(you will need to manually exit the shell to complete shutdown). This means you always have a
-shell available to check system state when something is going wrong. While this is not something
-you want to enable permanently, it can be a good tool to debug a reproducable boot issue or
-shutdown issue.
+of the existing ones (see the example services). You'll still need getty to setup the
+terminal for the shell; an example setting:
+```
+command = /sbin/agetty tty6 linux-c -n -l /bin/bash
+```
+You can remove most or all dependencies from this service so that it starts early, and set the
+`no-sigterm` option, as well as setting `stop-timeout = 0` (i.e. disabling stop timeout), so that
+it will not be killed at shutdown (you will need to manually exit the shell to complete shutdown).
+This means you always have a shell available to check system state when something is going wrong.
+While this is not something you want to enable permanently, it can be a good tool to debug a
+reproducable boot issue or shutdown issue.

+ 1 - 0
doc/linux/services/dhcpcd

@@ -2,5 +2,6 @@
 
 type = process
 command = /usr/sbin/dhcpcd -B -M --logfile /var/log/dhcpcd-service.log enp3s0
+logfile = /var/log/dhcpcd.log
 restart = false
 depends-on = rcboot

+ 2 - 0
doc/linux/services/early-filesystems.sh

@@ -1,5 +1,7 @@
 #!/bin/sh
 
+set -e
+
 if [ "$1" = start ]; then
 
     PATH=/usr/bin:/usr/sbin:/bin:/sbin

+ 3 - 1
doc/linux/services/filesystems.sh

@@ -1,11 +1,13 @@
 #!/bin/sh
 export PATH=/usr/bin:/usr/sbin:/bin:/sbin
 
+set -e
+
 if [ "$1" != "stop" ]; then
 
   echo "Mounting auxillary filesystems...."
   mount -t tmpfs -o nodev,nosuid tmpfs /dev/shm
-  mount -t devpts -o gid=5 devpts /dev/pts
+  mount -t devpts -o gid=tty devpts /dev/pts
   swapon /swapfile
   mount -avt noproc,nonfs
 

+ 23 - 8
doc/linux/services/late-filesystems.sh

@@ -1,16 +1,31 @@
 #!/bin/sh
 
+# A list of devices to mount. These must have a mount point specified in
+# /etc/fstab (and should be set "noauto" to prevent earlier mounting).
+LATE_FILESYSTEMS=""
+
+RESULT=0
+
 if [ "$1" = start ]; then
 
     PATH=/usr/bin:/usr/sbin:/bin:/sbin
-
-    fsck -a /dev/sdb2
-    fsckresult=$?
-    if [ $fsckresult -eq 0 ]; then
-    	mount /dev/sdb2 /mnt/sdb2
-    	exit $?
-    else
-        exit $fsckresult
+    
+    if [ ! -z "$LATE_FILESYSTEMS" ]; then
+        for FS in $LATE_FILESYSTEMS; do
+            fsck -a "$FS"
+            fsckresult=$?
+            if [ $(( $fsckresult & ~(1 + 32) )) -eq 0 ]; then
+                mount "$FS"
+                mntresult=$?
+                if [ $mntresult -ne 0 ]; then
+                    RESULT=$mntresult
+                fi
+            else
+                RESULT=$fsckresult
+            fi
+        done
     fi
 
 fi
+
+exit $RESULT

+ 1 - 0
doc/linux/services/rcboot

@@ -3,5 +3,6 @@
 type = scripted
 command = /etc/dinit.d/rcboot.sh start
 stop-command = /etc/dinit.d/rcboot.sh stop
+logfile = /var/log/rcboot.log
 restart = false
 depends-on = filesystems

+ 2 - 0
doc/linux/services/rcboot.sh

@@ -2,6 +2,8 @@
 export PATH=/usr/bin:/usr/sbin:/bin:/sbin
 umask 0077
 
+set -e
+
 if [ "$1" != "stop" ]; then
   
   # cleanup

+ 3 - 0
src/includes/proc-service.h

@@ -180,6 +180,9 @@ class base_process_service : public service_record
     bool reserved_child_watch : 1;
     bool tracking_child : 1;  // whether we expect to see child process status
 
+    // If executing child process failed, information about the error
+    run_proc_err exec_err_info;
+
     // Run a child process (call after forking). Note that some parameters specify file descriptors,
     // but in general file descriptors may be moved before the exec call.
     void run_child_proc(run_proc_params params) noexcept;