Use a systemd container to manage dslr-webcam
This commit is contained in:
parent
1f3653c6fb
commit
4831928351
@ -1,4 +1,3 @@
|
||||
|
||||
{ pkgs, lib, ... }:
|
||||
|
||||
let
|
||||
@ -8,7 +7,8 @@ let
|
||||
'';
|
||||
|
||||
dslrUdevRule = ''
|
||||
ACTION=="add", SUBSYSTEM=="usb", ATTR{idVendor}=="04a9", ENV{ID_USB_MODEL}=="Canon_Digital_Camera", RUN+="${pkgs.writeScriptBin "dslr-webcam" dslrWebcamScript}/bin/dslr-webcam"
|
||||
ACTION=="add", SUBSYSTEM=="usb", ATTR{idVendor}=="04a9", ENV{ID_USB_MODEL}=="Canon_Digital_Camera", RUN+="${pkgs.systemd}/bin/systemctl start dslr-webcam.service"
|
||||
ACTION=="remove", SUBSYSTEM=="usb", ATTR{idVendor}=="04a9", ENV{ID_USB_MODEL}=="Canon_Digital_Camera", RUN+="${pkgs.systemd}/bin/systemctl stop dslr-webcam.service"
|
||||
'';
|
||||
|
||||
dslrWebcamScript = ''
|
||||
@ -16,6 +16,20 @@ let
|
||||
modprobe dslr-webcam || true
|
||||
exec "${pkgs.gphoto2}/bin/gphoto2" --stdout --capture-movie | "${pkgs.ffmpeg}/bin/ffmpeg" -i - -vcodec rawvideo -pix_fmt yuv420p -f v4l2 /dev/video10
|
||||
'';
|
||||
|
||||
dslrWebcamService = ''
|
||||
[Unit]
|
||||
Description=DSLR Webcam Service
|
||||
After=network.target
|
||||
|
||||
[Service]
|
||||
ExecStart=${pkgs.writeScriptBin "dslr-webcam" dslrWebcamScript}/bin/dslr-webcam
|
||||
ExecStop=/bin/kill -s TERM $MAINPID
|
||||
Restart=on-failure
|
||||
|
||||
[Install]
|
||||
WantedBy=multi-user.target
|
||||
'';
|
||||
in
|
||||
{
|
||||
# Ensure your system configuration includes these options:
|
||||
@ -28,8 +42,21 @@ in
|
||||
# Udev rule for DSLR camera
|
||||
services.udev.extraRules = dslrUdevRule;
|
||||
|
||||
# Install dslr-webcam script
|
||||
# Install dslr-webcam script and systemd service
|
||||
environment.systemPackages = with pkgs; [
|
||||
(writeScriptBin "dslr-webcam" dslrWebcamScript)
|
||||
];
|
||||
|
||||
systemd.services.dslr-webcam = {
|
||||
description = "DSLR Webcam Service";
|
||||
after = [ "network.target" ];
|
||||
serviceConfig = {
|
||||
ExecStart = "${pkgs.writeScriptBin "dslr-webcam" dslrWebcamScript}/bin/dslr-webcam";
|
||||
ExecStop = "/bin/kill -s TERM $MAINPID";
|
||||
Restart = "on-failure";
|
||||
};
|
||||
wantedBy = [ "multi-user.target" ];
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user