Skip to content

Commit c8191af

Browse files
committed
WIP: hotplug working
1 parent f877dcb commit c8191af

6 files changed

Lines changed: 54 additions & 20 deletions

File tree

scripts/files/camera-streamer/add-usb-camera

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ if [ ! -e "$DEVICE" ]; then
6363
exit 1
6464
fi
6565

66-
sudo cat > /boot/camera-streamer/$NAME.conf <<EOF
66+
cat > /boot/camera-streamer/$NAME.conf <<EOF
6767
### Options for USB based cameras
6868
6969
# The port on which the webcam server for the camera should listen on.
@@ -82,11 +82,11 @@ HEIGHT=720
8282
# The framerate to set on the camera. Defaults to 15fps.
8383
FRAMERATE=15
8484
85-
# Additional options. Leave at log-debug=0 if not needed.
86-
OPTIONS='-log-debug=0'
85+
# Additional options.
86+
OPTIONS=
8787
EOF
8888

89-
sudo systemctl start camera-streamer-usb@$NAME.path
89+
/root/bin/camera-streamer-control restart $NAME
9090

9191
echo "Camera $NAME added"
9292
echo

scripts/files/camera-streamer/camera-streamer-control

Lines changed: 44 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
#!/bin/bash
22

33
action=$1
4+
single=$2
45

5-
systemctl $action "camera-streamer-libcamera.service"
6+
[ -n "$single" ] || systemctl $action "camera-streamer-libcamera.service"
67

78
# iterate over all the camera confs in /boot/camera-streamer
89
for conf in /boot/camera-streamer/*.conf; do
@@ -14,7 +15,47 @@ for conf in /boot/camera-streamer/*.conf; do
1415
# get the name of the camera
1516
name=$(basename "$conf" .conf)
1617

17-
# enable the camera
18-
systemctl $action "camera-streamer-usb@$name.path"
18+
if [[ "$single" != "" ]] && [[ "$single" != "$name" ]]; then
19+
# if we are only doing a single camera, skip the others
20+
continue
21+
fi
22+
23+
source $conf
24+
25+
if [[ "$action" == "start" ]] || [[ "$action" == "restart" ]]; then
26+
# generate some additional files/config if we are starting this for the first time
27+
reload="no"
28+
29+
# Add runtime path unit file that starts the service when the device is plugged in
30+
path_dir="/run/systemd/system"
31+
if [[ ! -e "$path_dir/camera-streamer-usb-$name.path" ]] || [[ ! $(grep -q "PathExists=$DEVICE" "$path_dir/camera-streamer-usb-$name.path") ]]; then
32+
cat > "$path_dir/camera-streamer-usb-$name.path" <<EOF
33+
[Unit]
34+
Description=camera-streamer $name autolaunch
35+
After=network.target
36+
37+
[Path]
38+
PathExists=$DEVICE
39+
Unit=camera-streamer-usb@$name.service
40+
EOF
41+
reload="yes"
42+
fi
43+
44+
# Add path dependency to service file via runtime override
45+
override_dir="/run/systemd/system/camera-streamer-usb@$name.service.d"
46+
override_conf="$override_dir/override.conf"
47+
if [[ ! -e "$override_conf" ]] || [[! $(grep -q "ConditionPathExists=$DEVICE" "$override_conf") ]]; then
48+
mkdir -p "$override_dir"
49+
cat > "$override_conf" <<EOF
50+
[Unit]
51+
ConditionPathExists=$DEVICE
52+
EOF
53+
reload="yes"
54+
fi
55+
[[ "$reload" == "yes" ]] && systemctl daemon-reload || true
56+
fi
57+
58+
# do the action
59+
systemctl $action "camera-streamer-usb-$name.path"
1960
systemctl $action "camera-streamer-usb@$name.service"
2061
done

scripts/files/camera-streamer/camera-streamer-usb@.path

Lines changed: 0 additions & 9 deletions
This file was deleted.

scripts/files/camera-streamer/camera-streamer-usb@.service

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,13 @@
22
Description=camera-streamer %i
33
After=network.target
44
After=camera-streamer-libcamera.service
5+
ConditionPathExists=/boot/camera-streamer/%i.conf
56
ConditionPathExistsGlob=/dev/v4l/by-id/usb-*-video-index0
67
StartLimitIntervalSec=120
78
StartLimitBurst=10
89

910
[Service]
1011
EnvironmentFile=/boot/camera-streamer/%i.conf
11-
ExecCondition=/bin/sh -c "[ -e $DEVICE ]"
1212
ExecStart=/bin/sh -c "exec /usr/local/bin/camera-streamer \
1313
-http-port=${PORT} \
1414
-camera-path="${DEVICE}" \

scripts/files/camera-streamer/camera-streamer.service

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
[Unit]
22
Description=camera-streamer arm usb
33
After=network.target
4-
After=camera-streamer-libcamera
54

65
[Service]
76
Type=oneshot

scripts/files/camera-streamer/remove-usb-camera

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@ if [ ! -e "/boot/camera-streamer/$NAME.conf" ]; then
1717
exit 1
1818
fi
1919

20-
systemctl stop camera-streamer-usb@$NAME.path
21-
systemctl stop camera-streamer-usb@$NAME.service
20+
/root/bin/camera-streamer-control stop $NAME
21+
2222
rm /boot/camera-streamer/$NAME.conf
23+
rm /run/systemd/system/camera-streamer-usb-$NAME.path || true
24+
rm -r /run/systemd/system/camera-streamer-usb@$NAME.service.d || true
25+
systemctl daemon-reload

0 commit comments

Comments
 (0)