0

I am trying to run VLC player with a url as input when my Rock starts. I have created a unit file called startup.service and put it in.

/etc/systemd/system/startup.service

It looks like this:

[Unit]

Description=Startup script

After=default.target

[Service]

ExecStart=sh /usr/sbin/startup.sh

[install]

WantedBy=default.target

/usr/sbin/startup.sh looks like this

sudo -u rock vlc https://dropbox.com/s/<fileID>/<fileName.mp4?raw=1>

When I run startup.sh VLC opens like it should and plays the video from the url.

When I start the service using

sudo systemctl daemon-restart
sudo systemctl start startup.service

nothing happens.

Looking at the logs using

sudo journalctl -u startup.service | less

I get the following output:

Nov 27 15:49:17 rockpi-4b systemd[1]: Started Startup script.
Nov 27 15:49:17 rockpi-4b sudo[1547]:     root : PWD=/ ; USER=rock ; COMMAND=/usr/bin/vlc https://www.dropbox.com/s/0k6xpcyp9ecpmau/test.mp4?raw=1
Nov 27 15:49:17 rockpi-4b sudo[1547]: pam_unix(sudo:session): session opened for user rock(uid=1000) by (uid=0)
Nov 27 15:49:17 rockpi-4b sh[1555]: [0000005593cfaf50] vlcpulse audio output error: PulseAudio server connection failure: Connection refused
Nov 27 15:49:17 rockpi-4b sh[1555]: [0000005593d20e40] dbus interface error: Failed to connect to the D-Bus session daemon: Unable to autolaunch a dbus-daemon without a $DISPLAY for X11
Nov 27 15:49:17 rockpi-4b sh[1555]: [0000005593d20e40] main interface error: no suitable interface module
Nov 27 15:49:17 rockpi-4b sh[1555]: [0000005593c25ee0] main libvlc error: interface "dbus,none" initialization failed
Nov 27 15:49:17 rockpi-4b sh[1555]: [0000005593d180c0] main interface error: no suitable interface module
Nov 27 15:49:17 rockpi-4b sh[1555]: [0000005593c25ee0] main libvlc error: interface "globalhotkeys,none" initialization failed
Nov 27 15:49:17 rockpi-4b sh[1555]: [0000005593c25ee0] main libvlc: Running vlc with the default interface. Use 'cvlc' to use vlc without interface.
Nov 27 15:49:17 rockpi-4b sh[1555]: error: XDG_RUNTIME_DIR not set in the environment.
Nov 27 15:49:17 rockpi-4b sh[1555]: [0000005593d180c0] skins2 interface error: cannot initialize OSFactory
Nov 27 15:49:17 rockpi-4b sh[1555]: [0000005593d180c0] [cli] lua interface: Listening on host "*console".
Nov 27 15:49:17 rockpi-4b sh[1555]: VLC media player 3.0.17.4 Vetinari
Nov 27 15:49:17 rockpi-4b sh[1555]: Command Line Interface initialized. Type `help' for help.
Nov 27 15:49:17 rockpi-4b sh[1555]: > Shutting down.
Nov 27 15:49:17 rockpi-4b sh[1555]: [0000005593d180c0] [cli] lua interface: Requested shutdown.
Nov 27 15:49:17 rockpi-4b sh[1555]: [0000007f9c002640] main tls client error: cannot resolve www.dropbox.com port 443: System error
Nov 27 15:49:17 rockpi-4b sh[1555]: [0000007f9c0016c0] access stream error: HTTP connection failure
Nov 27 15:49:17 rockpi-4b sudo[1547]: pam_unix(sudo:session): session closed for user rock
Nov 27 15:49:17 rockpi-4b systemd[1]: startup.service: Succeeded.

Can anyone help me figure out why I can run VLC with the desired remote file from the cli but not via the service?

For more info on Rock Pi:

https://wiki.radxa.com/Rock4/getting_started

Thank you.

8
  • 1
    Running a GUI application as a system service is basically a flawed idea. You want to run it from your desktop environment's startup hooks instead.
    – tripleee
    Commented Nov 28, 2022 at 8:05
  • Good point. How to do that in Debian?
    – AHaahr
    Commented Nov 28, 2022 at 10:36
  • I guess the alternative is to find a different video player that isn't GUI based. Any suggestions?
    – AHaahr
    Commented Nov 28, 2022 at 10:37
  • How would you play a video without a GUI?
    – tripleee
    Commented Nov 28, 2022 at 11:26
  • We don't know which desktop environment you are running, so advice will necessarily be speculative. For Gnome, Quick Duck Duck Going gets me stackoverflow.com/questions/8247706/… which has a recent answer which is probably more useful than the older ones.
    – tripleee
    Commented Nov 28, 2022 at 11:27

1 Answer 1

1

Have a look at https://www.freedesktop.org/software/systemd/man/[email protected]

A short and simple solution is to add a

User=%I

After the

[Service]

Also a script should work without the sh prefix, just make sure it is executable.

[Unit]
Description=Startup script for %I
After=default.target

[Service]
User=%I
ExecStart=/usr/sbin/startup.sh

[install]
WantedBy=default.target

Rename your unit file to something like:

/etc/systemd/system/[email protected]

Remove the sudo inside the script.

/usr/sbin/startup.sh

vlc https://dropbox.com/s/<fileID>/<fileName.mp4?raw=1>

Now using systemctl Assuming rock is the name of the user.

sytemctl status [email protected]

If should print something about the unit file.


Then just start it with:

sytemctl start [email protected]

Don't forget to enable it if you want to start it at boot.


3
  • Thanks for the answer. Makes a lot of sense. Using you suggestions, the log is now giving me a single error saying: [email protected]: Failed to execute /usr/sbin/startup.sh: Exec format error
    – AHaahr
    Commented Nov 28, 2022 at 9:10
  • startup.sh just has vlc https://... and it is executable. Any idea what could be wrong?
    – AHaahr
    Commented Nov 28, 2022 at 9:11
  • You need to add a shebang, and you should really store it in a better place. Most of /usr is managed by your OS and should not be modified directly. /usr/local/bin exists precisely to provide a place for your local additions.
    – tripleee
    Commented Nov 28, 2022 at 11:30

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .