-
-
Notifications
You must be signed in to change notification settings - Fork 238
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
init.d and systemctl scripts #16
Comments
Systemctl service configuration Preparation
Create a system user for better security and not run as root:
Add the system user to the group video allowing the system user access to the device:
... or manually edit systemctl creation
Here is an example. You will need to update the options as needed for your setup and use: [Unit]
Description=uStreamer service
After=network.target
[Service]
Environment="SCRIPT_ARGS=%I"
User=ustreamer
ExecStart=/usr/bin/ustreamer --process-name-prefix ustreamer-%I --log-level 0 --device /dev/video%I --device-timeout=8 --quality 100 --resolution 1920x1080 --desired-fps=29 --host=0.0.0.0 --port=808%I --static /var/www/html/ustreamer-%I/
[Install]
WantedBy=multi-user.target Enable the service:
Enable the service with argument for starting at boot:
Start the service:
The number after the Verify added service is working:
You might want to make sure that each usb port has a specific camera. This is easy to do with udev: https://unix.stackexchange.com/questions/66901/how-to-bind-usb-device-under-a-static-name https://wiki.archlinux.org/index.php/Udev#Setting_static_device_names For example: https://github.com/pikvm/kvmd/blob/master/configs/os/udev/v0-vga-rpi3.rules#L3 |
Looks like I answered your question :) I've added a link to this issue to README for those who will encounter this problem. |
Here's a udev rules file I wrote for my C920. I put it in
|
Hi! Thank you for the systemctl script, it works great! Do you know if I can create a systemd socket unit instead of a systemd service unit? I want it to be activated when requested and deactivated after the client disconnects. Is that possible? Thanks! |
Sup. This is not supported now because it requires some code on the part of ustreamer. |
Ok, anyway without it works great! Thanks! |
|
@cthulux Implemented socket activation. Please try it from master branch. Build with |
@cthulux upd: added option |
Thank you @mdevaev ! This is great! I had an issue I solved by installing libsystemd-dev (just commenting it for anyone else that wants to try it). I'll try it and come back to let you know how it was. Thanks! |
Hi @mdevaev, I've been trying to follow online tutorials in order to create the systemd socket file with the new options but I was not very sucessful, I don't know what is missing:
And the systemd socket file is:
Thanks! |
Remove |
Also remove |
Hi @mdevaev , I followed your suggestions and had to change the service template file to service file only because there was some issue with the template I couldn't manage. Finaly I was able to make the sytemd socket file run without issues but I couldn't connect to it. I am using Haproxy in order to add TLS encryption and authentication. Previous to adding the systemd socket file, It listened in port 8090 and forwarded it to ustreamer localhost port 8089. Now I adapted it so it listens on the tcp unix path but I am unable to see any video since it looks like the systemd service is not trigered or I don't know what. This is the Haproxy which worked previously with "server rpicam 127.0.0.1:8089" and now for the socket systed file I changed to "server rpicam /run/ustreamer.sock":
This is the systemd service file:
And this is the systemd socket file:
I added ustreamer user for both systemd unit files, also added haproxy user to the ustreamer group and just in case made the ustreamer socket permissions 755 so haproxy can read the socket (with option SocketMode=755).
After I login with the credentials I defined in haproxy basic authentication to https://host:8090 I can see the error Do you know if there is another way (instead of Haproxy) to test if the /run/ustreamer.sock. If this is something dificult, I can use the previous configuration without socket file which worked really fine. Thanks a lot! |
Try I used the systemd debugging tool to check. Everything works:
|
Thank you @mdevaev! It works! Now I'll have to figure out myself howto make it work with Haproxy. :) |
Glad to hear it! |
I'm having some trouble trying to parse the comments here and am not sure if I am having the same issues that others are having. after enabling the script with systemctl I recieve this error: Unfortunately when I try to connect to the specified port I can't connect as I can when I manually start ustreamer. Do you have any suggestions? Thank you! |
I tried setting up the socket but failed, anyone care to give me a step-by-step example? Would be an nice addition to the otherwise well written guide. |
Hi @ZyberSE, It is a bit difficult for me to answer this since I am not currently using it. This are the instructions I was able to recover from what I did to get it working: Step 1: Download latest version and compile with "WITH_SYSTEMD=1". You don't need to use git, since current releases may include the systemd compilation flag. At the time I did it, I had to use git due to it was a new feature @mdevaev implemented:
If you need to update it later:
Create specific camera user:
Check if you have the systemd services for ustreamer:
If you have those, then just start/enable the socket:
Else, create the systemd files. Here you are some systemd examples (they are overloaded with options that certainly are not needed and others may not be up to date, that's why I said examples): root@rpi4:/home/pi# systemctl cat [email protected]
root@rpi4:/home/pi# systemctl cat ustreamer.service
This is were you create the socket file, please edit and replace "/var/lib/haproxy/ustreamer.sock" with your socket name
|
Hi! I just saw your question today, are you still facing this issue? |
Hi. I Found this thread and decided to create my own autostart script. After some time i manage to make full working and enabling on start. Wanted to share it. I'm running OctoPrint on LUbuntu. Video is from USB camera
All other things like creating etc. same as @mdevaev mentioned in first post (btw thx for it). If u're gonna use only one camera it better to create script without "@" allias. |
I slapped together a quick nixos module for this with socket activation, since there wasn't one in nixpkgs, and figured I'd share it here! {
config,
lib,
pkgs,
...
}:
with lib;
let
cfg = config.services.ustreamer;
in
{
options = {
services.ustreamer = {
enable = mkEnableOption "ustreamer webcam streamer";
user = mkOption {
type = types.str;
default = "ustreamer";
description = "ustreamer user name.";
};
group = mkOption {
type = types.str;
default = "video";
description = "ustreamer group name.";
};
listenStream = mkOption {
type = types.str;
default = "/run/ustreamer.sock";
description = "ustreamer socket.";
};
extraArgs = mkOption {
type = types.str;
default = "";
description = "ustreamer cli args";
};
};
};
config = mkIf cfg.enable {
users.users = optionalAttrs (cfg.user == "ustreamer") {
ustreamer = {
group = cfg.group;
isSystemUser = true;
};
};
systemd.services.ustreamer = {
description = "ustreamer webcam streamer";
after = [
"network.target"
"ustreamer.socket"
];
requires = [ "ustreamer.socket" ];
serviceConfig = {
User = cfg.user;
Group = cfg.group;
ExecStart = "${pkgs.ustreamer}/bin/ustreamer --systemd --exit-on-no-clients 300 ${cfg.extraArgs}";
};
};
systemd.sockets.ustreamer = {
description = "ustreamer webcam socket";
partOf = [ "ustreamer.service" ];
wantedBy = [ "sockets.target" ];
listenStreams = [ cfg.listenStream ];
};
};
} Then you can use it with nginx+mainsail like this! services.ustreamer = {
enable = true;
extraArgs = "--resolution 1280x720";
};
services.nginx.upstreams.ustreamer = {
servers = {
"unix:${config.services.ustreamer.listenStream}" = { };
};
};
services.mainsail = {
enable = true;
nginx = {
# ...
locations."/webcam/" = {
proxyPass = "http://ustreamer/";
extraConfig = ''
postpone_output 0;
proxy_buffering off;
proxy_ignore_headers X-Accel-Buffering;
'';
};
};
}; |
@jacob-swanson, your config looks good to me. You should submit it to nixpkgs and help everyone out. |
Has anyone put together scripts to start, restart, and stop the service so ustreamer could start at boot or easily managed?
The text was updated successfully, but these errors were encountered: