Update to how we choose if we are running udevd or dumb-udev

This fixes some issues I found with startup.
This commit is contained in:
Josh.5
2023-09-29 21:26:17 +13:00
parent 5a1d20daf5
commit 93718e1855
5 changed files with 39 additions and 76 deletions

View File

@@ -9,50 +9,44 @@
# Modified By: Josh.5 (jsunnex@gmail.com)
###
# Running udev only works in privileged container
# Source: https://github.com/balena-io-playground/balena-base-images/
tmp_mount='/tmp/privileged_test'
mkdir -p "${tmp_mount}"
if mount -t devtmpfs none "${tmp_mount}" &> /dev/null; then
is_privileged=true
umount "${tmp_mount}"
else
is_privileged=false
fi
rm -rf "${tmp_mount}"
if [[ "${is_privileged}" == "true" ]]; then
# Since this container may also be run with CAP_SYS_ADMIN, ensure we can actually execute "udevadm trigger"
if [ ! -w /sys ]; then
# Disable supervisord script since we are not able to write to sysfs
echo "**** Disable udev - /sys is mounted RO ****";
sed -i 's|^autostart.*=.*$|autostart=false|' /etc/supervisor.d/udev.ini
elif [ ! -w /run/udev ]; then
# Disable supervisord script since we are not able to write to udev/data path
echo "**** Disable udev - /run/udev is mounted RO ****";
sed -i 's|^autostart.*=.*$|autostart=false|' /etc/supervisor.d/udev.ini
elif udevadm trigger &> /dev/null; then
echo "**** Configure container to run udev management ****";
# Enable supervisord script
sed -i 's|^autostart.*=.*$|autostart=true|' /etc/supervisor.d/udev.ini
# Configure udev permissions
if [[ -f /lib/udev/rules.d/60-steam-input.rules ]]; then
sed -i 's/MODE="0660"/MODE="0666"/' /lib/udev/rules.d/60-steam-input.rules
fi
else
# Disable supervisord script since we are not able to execute "udevadm trigger"
echo "**** Disable udev service due to privilege restrictions ****";
sed -i 's|^autostart.*=.*$|autostart=false|' /etc/supervisor.d/udev.ini
fi
else
# Disable supervisord script
echo "**** Disable udev service ****";
# Since this container may also be run with CAP_SYS_ADMIN, ensure we can actually execute "udevadm trigger"
run_dumb_udev="false"
if [ ! -w /sys ]; then
# Disable supervisord script since we are not able to write to sysfs
echo "**** Disable udevd - /sys is mounted RO ****";
sed -i 's|^autostart.*=.*$|autostart=false|' /etc/supervisor.d/udev.ini
if [ ! -d /run/udev/data ]; then
echo "**** Enable dumb-udev service ****";
sed -i 's|^autostart.*=.*$|autostart=true|' /etc/supervisor.d/dumb-udev.ini
run_dumb_udev="true"
elif [ ! -d /run/udev ]; then
# Disable supervisord script since we are not able to write to udev/data path
echo "**** Disable udevd - /run/udev does not exist ****";
sed -i 's|^autostart.*=.*$|autostart=false|' /etc/supervisor.d/udev.ini
run_dumb_udev="true"
elif [ ! -w /run/udev ]; then
# Disable supervisord script since we are not able to write to udev/data path
echo "**** Disable udevd - /run/udev is mounted RO ****";
sed -i 's|^autostart.*=.*$|autostart=false|' /etc/supervisor.d/udev.ini
run_dumb_udev="false"
elif udevadm trigger &> /dev/null; then
echo "**** Configure container to run udev management ****";
# Enable supervisord script
sed -i 's|^autostart.*=.*$|autostart=true|' /etc/supervisor.d/udev.ini
# Configure udev permissions
if [[ -f /lib/udev/rules.d/60-steam-input.rules ]]; then
sed -i 's/MODE="0660"/MODE="0666"/' /lib/udev/rules.d/60-steam-input.rules
fi
run_dumb_udev="false"
else
# Disable supervisord script since we are not able to execute "udevadm trigger"
echo "**** Disable udev service due to privilege restrictions ****";
sed -i 's|^autostart.*=.*$|autostart=false|' /etc/supervisor.d/udev.ini
run_dumb_udev="true"
fi
if [ "${run_dumb_udev}" = "true" ]; then
# Enable dumb-udev instead of udevd
echo "**** Enable dumb-udev service ****";
sed -i 's|^command.*=.*$|command=start-dumb-udev.sh|' /etc/supervisor.d/udev.ini
sed -i 's|^autostart.*=.*$|autostart=true|' /etc/supervisor.d/udev.ini
fi

View File

@@ -1,15 +0,0 @@
[program:udev]
priority=10
autostart=false
autorestart=true
user=root
directory=/
command=start-dumb-udev.sh
stopsignal=INT
stdout_logfile=/var/log/supervisor/dumb-udev.log
stdout_logfile_maxbytes=10MB
stdout_logfile_backups=7
stderr_logfile=/var/log/supervisor/dumb-udev.err.log
stderr_logfile_maxbytes=10MB
stderr_logfile_backups=7

View File

@@ -28,7 +28,7 @@ wait_for_x() {
wait_for_udev() {
MAX=10
CT=0
while [ ! -f /tmp/.started-udev ]; do
while [ ! -e /run/udev/control ]; do
sleep 1
CT=$(( CT + 1 ))
if [ "$CT" -ge "$MAX" ]; then
@@ -36,6 +36,7 @@ wait_for_udev() {
exit 11
fi
done
sleep 5
}
# Wait for dockerd to start

View File

@@ -17,18 +17,10 @@ _term() {
trap _term SIGTERM SIGINT
# CONFIGURE:
# Remove lockfile
rm -f /tmp/.started-udev
# EXECUTE PROCESS:
# Start dumb-udev
dumb-udev
dumb-udev &
dumb_udev_pid=$!
# Touch lockfile
sleep 1
touch /tmp/.started-udev
# WAIT FOR CHILD PROCESS:
wait "$dumb_udev_pid"

View File

@@ -16,12 +16,6 @@ _term() {
}
trap _term SIGTERM SIGINT
# CONFIGURE:
# Remove lockfile
rm -f /tmp/.started-udev
# EXECUTE PROCESS:
# Start udev
if command -v udevd &>/dev/null; then
@@ -32,9 +26,6 @@ fi
# Monitor kernel uevents
udevadm monitor &
monitor_pid=$!
# Touch lockfile
sleep 1
touch /tmp/.started-udev
# Wait for 10 seconds, then request device events from the kernel
sleep 10
udevadm trigger