Skip to content
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

systemd service #84

Open
namxam opened this issue Sep 7, 2021 · 2 comments
Open

systemd service #84

namxam opened this issue Sep 7, 2021 · 2 comments

Comments

@namxam
Copy link

namxam commented Sep 7, 2021

I know that this is probably not the right place to ask, but I just created a small app which is checking a MediaPlayer for its status. The service is running great when manually started from the command line. But fails miserably when I try to create a systemd service to automatically start it when the system restarts.

Has anyone an idea how to tackle that issue?

@acrisci
Copy link
Member

acrisci commented Sep 7, 2021

This is going to be a bit difficult because a media player exposes the interface on the session bus and there can be zero or many session buses running on your system. The library will read DBUS_SESSION_BUS_ADDRESS env variable to specify which one (which is usually set by a session manager). You might want to look into using a dbus-activatable service which I use for playerctld on the Playerctl project.

@namxam
Copy link
Author

namxam commented Sep 8, 2021

@acrisci Thank you. I was already researching in this direction and it seems that I have a working setup… or at least a partially working solution.

I guess there might be more people who might be interested in this solution, so I try to be as explicit as possible.

I created a dbus service

# /usr/share/dbus-1/services/org.mpris.MediaPlayer2.vlc.service
[D-BUS Service]
Name=org.mpris.MediaPlayer2.vlc
Exec=/bin/false
SystemdService=vlc.service

with a corresponding systemd service

# /etc/systemd/user/vlc.service
Description=VLC media player

[Service]
Type=dbus
BusName=org.mpris.MediaPlayer2.vlc
Environment="DISPLAY=:0"
ExecStart=/usr/bin/vlc --video-on-top --fullscreen --no-video-title-show --no-osd --no-spu --start-paused

When I send a dbus message from command line it all works as expected and vlc is launched.
Next I created a systemd user service for my application

[Unit]
Description=Demo MediaPlayer
After=dbus.service

[Service]
ExecStart=/usr/bin/node demo.mjs
WorkingDirectory=/home/pi/demo-media-player
StandardOutput=inherit
StandardError=inherit
Restart=always
Environment="DISPLAY=:0"

[Install]
WantedBy=default.target

I made sure that user services get loaded during boot via loginctl enable-linger $USER. And when I enable it and reboot, the app starts as expected. BUT for some reason, it now hangs indefinitely when getting the proxy object. In my code this line hangs

let dbus = await bus.getProxyObject(
    "org.mpris.MediaPlayer2.vlc",
    "/org/mpris/MediaPlayer2"
  );

When I restart the service via systemctl --user restart demo.service it works immediately. It just hangs after rebooting the system. I also checked and the VLC service is running as expected.

Any idea what might cause it?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants