Raspberry Pi 3b+ & VLC

*nix specific usage questions
ColtonParadigm
Blank Cone
Blank Cone
Posts: 14
Joined: 15 Jan 2019 04:47

Raspberry Pi 3b+ & VLC

Postby ColtonParadigm » 15 Jan 2019 05:01

Good day to all,
I am having an issue with a restarting process.
i currently an running Raspbian Stretch on a Pi 3b+
VLC is under default settings currently as everything i need is being executed through cmd line bash script

i have a few scripts and i am using crontab to automate the transitions.
~/Scripts/script.sh

the script in question that i am having an issue with is a script that downloads new FTP files every 4 hours based on crontab line

Code: Select all

* */4 * * * /home/pi/Scripts/SupplementalFTP.sh
Script contains sftp script using sshpass then using variables it determines what script to run depending on the time of day
Everything executes properly all the way through to the end where i have an if statement using the time of day to pick the proper script to run.
this statement on the THEN and the ELSE both kills VLC using "SUDO PKILL -9 VLC"
then echos a statement into a logfile. then executes the following cmds depending on timeframe

"

Code: Select all

cvlc --loop --fullscreen /home/pi/Desktop/From_FTP/Morning/*
"
or
"

Code: Select all

cvlc --loop --fullscreen /home/pi/Desktop/From_FTP/Afternoon/*
"

NOW,
My issue is once it kills VLC and that does appear to work,
VLC is never relaunched and my log files
give me an error

Code: Select all

"vlc media player 3.0.6 Vetinari Command line interface initialized type 'help' for help > Shutting down "
I would appreciate ANY help

*NOTE: running all scripts manually executes all with no issues*
Apologies i cannot upload all of the script contents due to confidentiality clause at this time

ColtonParadigm
Blank Cone
Blank Cone
Posts: 14
Joined: 15 Jan 2019 04:47

Re: Raspberry Pi 3b+ & VLC

Postby ColtonParadigm » 16 Jan 2019 00:48

EDIT ADD: VLC is currently running a slideshow started from CMD from another script

Code: Select all

cvlc --loop --fullscreen /home/pi/Desktop/From_FTP/Morning/*
Here is my LOG

Code: Select all

... VLC Killed for Afternoon Restart VLC media player 3.0.6 Vetinari Command Line Interface initialized. Type 'help' for help >Shutting Down
Here is my Script(partial)

Code: Select all

tme= $(date +%k%M) if [[$tme -ge 000 ]] && [[ $tme -le 1030 ]] then sudo pkill -9 vlc echo "VLC Killed for Morning Restart" cvlc --loop --fullscreen cvlc --loop --fullscreen /home/pi/Desktop/From_FTP/Morning/* else sudo pkill -9 vlc echo "VLC Killed for Afternoon Restart" cvlc --loop --fullscreen cvlc --loop --fullscreen /home/pi/Desktop/From_FTP/Morning/* fi

unidan
Developer
Developer
Posts: 1493
Joined: 25 Mar 2018 01:00

Re: Raspberry Pi 3b+ & VLC

Postby unidan » 17 Jan 2019 10:26

Hi, you might want to launch vlc with

Code: Select all

vlc -I dummy

ColtonParadigm
Blank Cone
Blank Cone
Posts: 14
Joined: 15 Jan 2019 04:47

Re: Raspberry Pi 3b+ & VLC

Postby ColtonParadigm » 17 Jan 2019 14:01

will launching with vlc -I dummy not show a display. Also should i use vlc or cvlc with the interface switch.
i have tried a lot of things this was not one of them though. i will give it a shot and let you know.

ColtonParadigm
Blank Cone
Blank Cone
Posts: 14
Joined: 15 Jan 2019 04:47

Re: Raspberry Pi 3b+ & VLC

Postby ColtonParadigm » 17 Jan 2019 20:35

I modified the script to include the '-I dummy'
however the error did not change.. it still shows the same error as OP

ColtonParadigm
Blank Cone
Blank Cone
Posts: 14
Joined: 15 Jan 2019 04:47

Re: Raspberry Pi 3b+ & VLC

Postby ColtonParadigm » 25 Jan 2019 15:40

Still working on this issue, no resolution as of yet.
Any ideas would be greatly appreciated

1MAXT3HKphYo
Blank Cone
Blank Cone
Posts: 22
Joined: 29 Jan 2019 01:35

Re: Raspberry Pi 3b+ & VLC

Postby 1MAXT3HKphYo » 29 Jan 2019 03:35

One thing I spot is "cvlc --loop --fullscreen" is specified twice on each vlc line in your script. Maybe that's part of what's causing the issue. Probably unrelated but I also see the path you're sourcing from to be identical (both point to "Morning"). I assume you want vlc to look in "Afternoon" when it's restarted.

maybe try replacing the lines in your script with:

Code: Select all

tme=$(date +%k%M) # tme will always be greater than or equal to zero so checking for it is redundant if [[ $tme -le 1030 ]] ; then # sudo is unnecessary here pkill -9 vlc echo "VLC Killed for Morning Restart" cvlc --verbose=3 --loop --fullscreen /home/pi/Desktop/From_FTP/Morning/* else pkill -9 vlc echo "VLC Killed for Afternoon Restart" cvlc --verbose=3 --loop --fullscreen /home/pi/Desktop/From_FTP/Afternoon/* fi
Does the morning bit launch successfully or is it only not working in the afternoon?

ColtonParadigm
Blank Cone
Blank Cone
Posts: 14
Joined: 15 Jan 2019 04:47

Re: Raspberry Pi 3b+ & VLC

Postby ColtonParadigm » 29 Jan 2019 04:59

One thing I spot is "cvlc --loop --fullscreen" is specified twice on each vlc line in your script. Maybe that's part of what's causing the issue. Probably unrelated but I also see the path you're sourcing from to be identical (both point to "Morning"). I assume you want vlc to look in "Afternoon" when it's restarted.

Does the morning bit launch successfully or is it only not working in the afternoon?
if i run my scripts manually then yes they all execute according to design....i will make your suggested modifications as they will indeed help slim down my script.
I have modified my script prior to the following

Code: Select all

if [[ $tme -ge 000 ]] && [[ $tme -le 1030 ]] then echo "VLC Killed for Morning Restart" sudo pkill -9 vlc sleep 30s sudo -H -u pi find /home/pi/Desktop/From_FTP/Morning/Horizontal/MorningPL.xspf -type f -exec vlc -LZ --metadata-network-access --fullscreen '{}' + & else echo "VLC killed for Afternoon Restart" sudo pkill -9 vlc sleep 30s sudo -H -u pi find /home/pi/Desktop/From_FTP/Afternoon/Horizontal/AfternoonPL.xspf -type f -exec vlc -LZ --metadata-network-access --fullscreen '{}' + & fi
I will make your suggested modifications and see how it runs
I opted to use vlc vs cvlc because i want the display for the playlist....when i used cvlc it opened but did not open using the proper formatting for some reason.

1MAXT3HKphYo
Blank Cone
Blank Cone
Posts: 22
Joined: 29 Jan 2019 01:35

Re: Raspberry Pi 3b+ & VLC

Postby 1MAXT3HKphYo » 29 Jan 2019 06:23

I just realized. If you're launching it from cron, vlc is not going to have access to the DISPLAY environment variable specifying your X server's address. What you can do is: log into x as usual (start a gui session), do an "echo $DISPLAY" to find the value and then use that in your script file immediately prior to each vlc command.

(example: if echo $DISPLAY returns ":1")

Code: Select all

If [[ foo ]] ; then DISPLAY=:1 cvlc --loop --fullscreen folder_of_jpegs/* fi
Otherwise it won't be able to connect to the display server. Also, you probably don't want to launch your script as a privileged user or use sudo at all in it. You can use crontab -u to specify a user. Note that vlc will refuse to launch as root (which, if you're editing the root crontab is what it will launch as).

My suggestion would be to delete the pi user entirely and create a new one for this purpose. The pi user is in way too many groups by default, including sudo. The first thing I do on a new Pi is to create a new admin user in the sudo group, and at least one new standard user.

suggestion:

Code: Select all

sudo adduser some_admin # add privileged user sudo usermod -aG sudo some_admin # let user sudo by adding sudo group exit # (and log back in) # test admin user can login and sudo here!!! sudo deluser pi # delete the pi user (from the admin user) sudo adduser some_shmo # log in as this to do normal stuff sudo addgroup --system slideshow # system group for the slideshow user below: sudo adduser --system --shell /bin/false --no-create-home --ingroup slideshow --disabled-password --disabled-login slideshow
Then you run "sudo crontab -u slideshow -e" as your new admin user and stick your script in there. It should then run as the slideshow user which can't log in, has no password, has no home folder, etc. If somebody manages to make vlc do something funny with a malformed image while it's running as "slideshow", damage is more likely (cont...)
Last edited by 1MAXT3HKphYo on 29 Jan 2019 07:59, edited 1 time in total.

1MAXT3HKphYo
Blank Cone
Blank Cone
Posts: 22
Joined: 29 Jan 2019 01:35

Re: Raspberry Pi 3b+ & VLC

Postby 1MAXT3HKphYo » 29 Jan 2019 07:58

(... cont) to be contained

Of course, if you do this, keep in mind the script itself and it's resources should live somewhere readable to 'slideshow'. Depending on how your permissions are set for your home folder, this probably means someplace like a subfolder of /var/ or something for the images and something like /usr/bin for the script itself or even something outside of $PATH.

Given that run repeatedly, your script can possibly do undesirable things to the pi, it may also be best to only make it executable to the slideshow user. To do this chown the script to root:slideshow and chmod it to 750. (RW only for root, execute and read to slideshow, none to anybody else). If you need to test the script manually, you can "sudo -u slideshow /usr/bin/script" to run the script as the slideshow user.

ColtonParadigm
Blank Cone
Blank Cone
Posts: 14
Joined: 15 Jan 2019 04:47

Re: Raspberry Pi 3b+ & VLC

Postby ColtonParadigm » 29 Jan 2019 14:11

Of course, if you do this, keep in mind the script itself and it's resources should live somewhere readable to 'slideshow'. Depending on how your permissions are set for your home folder, this probably means someplace like a subfolder of /var/ or something for the images and something like /usr/bin for the script itself or even something outside of $PATH.

Given that run repeatedly, your script can possibly do undesirable things to the pi, it may also be best to only make it executable to the slideshow user. To do this chown the script to root:slideshow and chmod it to 750. (RW only for root, execute and read to slideshow, none to anybody else). If you need to test the script manually, you can "sudo -u slideshow /usr/bin/script" to run the script as the slideshow user.
I am a noob when it come to linux and pi alike so i am learning as i go
Can you please explain this abit in more detail if possible

1MAXT3HKphYo
Blank Cone
Blank Cone
Posts: 22
Joined: 29 Jan 2019 01:35

Re: Raspberry Pi 3b+ & VLC

Postby 1MAXT3HKphYo » 30 Jan 2019 01:24

I am a noob when it come to linux and pi alike so i am learning as i go
Can you please explain this abit in more detail if possible
Sure, no problem. I think everybody is still learning when it comes to Linux since things are constantly shifting. Just stick with it. So in Linux, X11 (ignoring Wayland for now) is used for the gui. X's job is to sit there and act as a server for clients to connect to. Clients include the window manager (gnome, kde, xfce, etc...) as well as just about any gui application you can think of. You can even forward X over ssh to work remotely. In order for all of this to work, however, client apps need to know the address of the X server. This is stored in the $DISPLAY environment variable.

If for some reason a client doesn't have access to $DISPLAY or the X server won't let a client connect you usually get an error to the effect of "could not connect to display". Launching a gui app from cron is one of those situations where it's likely not going to have access. Ssh is another. Therefore you will need to specify $DISPLAY to each app. For example:

bad display value:

Code: Select all

$ DISPLAY=:0 gnome-terminal Invalid MIT-MAGIC-COOKIE-1 keyUnable to init server: Could not connect: Connection refused
good display value:

Code: Select all

$ DISPLAY=:2 gnome-terminal (gnome-terminal launches)

1MAXT3HKphYo
Blank Cone
Blank Cone
Posts: 22
Joined: 29 Jan 2019 01:35

Re: Raspberry Pi 3b+ & VLC

Postby 1MAXT3HKphYo » 30 Jan 2019 01:37

As far as permissions go, if you need a cheat sheet or an explanation of how they work, here's one. As far as what directories mean what on unix, here's a good cheat sheet. $PATH is an environment variable that, like on Windows, tells a shell when executable files can be found. I hope that clears some things up and hopefully doesn't make things more confusing. Ask questions if you need to. One thing at a time; however. Have you tested whether setting DISPLAY fixes the problem?

ColtonParadigm
Blank Cone
Blank Cone
Posts: 14
Joined: 15 Jan 2019 04:47

Re: Raspberry Pi 3b+ & VLC

Postby ColtonParadigm » 30 Jan 2019 01:58

Ill definitely keep these cheat sheets....the will come in handy as i form my programs and scripts....still testing this script....its being run through cron and i dont know how to test running AS cron.

1MAXT3HKphYo
Blank Cone
Blank Cone
Posts: 22
Joined: 29 Jan 2019 01:35

Re: Raspberry Pi 3b+ & VLC

Postby 1MAXT3HKphYo » 30 Jan 2019 02:42

Ill definitely keep these cheat sheets....the will come in handy as i form my programs and scripts....still testing this script....its being run through cron and i dont know how to test running AS cron.
Cron *should* just run the script as a user you specify when you created/edited the crontab file with "crontab -u script_runner_user -e". If you don't specify -u, crontab will use whatever user it's run as. You should be able to test it with "sudo -u script_runner_user /path/to/script" (or su -c /path/to/script script_runner_user) where script_runner_user is the user you created to run the script.

If somehow your script ends up run as root it won't work even if it can connect to the display because vlc will give an error if launched as root. To check what user your script is running as, you could add the following line to your script:

Code: Select all

echo Script run as `whoami`

ColtonParadigm
Blank Cone
Blank Cone
Posts: 14
Joined: 15 Jan 2019 04:47

Re: Raspberry Pi 3b+ & VLC

Postby ColtonParadigm » 30 Jan 2019 07:13

settings adjusted to match what was suggested for execute this is the errors i receive

Code: Select all

[017156d0] dbus interface error: failed to connect to the d-bus session daemon: unable to autolauch a dbus-daemon without a $DISPLAY for x11 [017156d0] main interface error: no suitable interface module [0169ba18] main libvlc error: interface 'dbus,none" initialization failed [0169ba18] main libvlc error: d-bus session bus connection failure: unable to autolauch a dbus-daemon without a $DISPLAY for x11 [0171b008] main interface error: no suitable interface module [0169ba18] main libvlc error: interface "globalhotkeys,none" initialization failed [0169ba18] main libvlc: running vlc with the default interface. user 'cvlc' to use vlc without interface error: xdg_runtime_dir not set in the environment [0171b9d8] skins2 interface error: cannot initialize OSFactory [0171b9d8] [cli] lus interface: listening on host "*Console". VLC media player 3.0.6 vetinari command line initialized. type 'help' for hlep > shutting down [0171b9d8] [cli] lua interface: requested shutdown [73b00828] cache_read stream error: cannot pre fill buffer
This is the script being executed by cron via "0 0 * * * sudo -u pi $file &

Code: Select all

#!/bin/bash # #Shell and Error logging exec 3>&1 4>&2 trap 'exec 2>&4 1>&3' 0 1 2 3 exec 1>$log 2>&1 # #Import Config File source $folder$file # file=$file if [[ $file ]] then pkill -9 vlc sleep 10s sudo -H -u pi vlc -LZ --metadata-network-access --fullscreen $playlist & else echo " no playlist found, continuing previous playlist" fi
ANY SUGGESTIONS WOULD BE GREAT

vlc closes as it is supposed to per script but never restarts properly with the new playlist file

is there a way to change playlists without having to close VLC maybe that will be more adequate to do then kill and restart

ColtonParadigm
Blank Cone
Blank Cone
Posts: 14
Joined: 15 Jan 2019 04:47

Re: Raspberry Pi 3b+ & VLC

Postby ColtonParadigm » 30 Jan 2019 07:19

EDIT1
running the script manually and running the command exactly as cron has it manually executes the program with no errors in the log file

1MAXT3HKphYo
Blank Cone
Blank Cone
Posts: 22
Joined: 29 Jan 2019 01:35

Re: Raspberry Pi 3b+ & VLC

Postby 1MAXT3HKphYo » 30 Jan 2019 08:40

So, those errors are related to vlc not being to connect to the x server. You're going to have to log into an x session, find the value for $DISPLAY by doing "echo $DISPLAY", copying that value and using in the script as suggested in the quote below.

Second bit: you probably want to remove the existing line in the crontab you have and instead add the script to Pi's crontab (or another user) by logging in as the user and doing "crontab -e". You won't need the sudo.

Sudo is meant for interactive usage. Generally you don't want to use it in scripts. If you need to run a script as a particular user, you can sudo the script itself if it really needs it or in the case of cron, use it's existing capabilities to launch processes as a given user (crontab -u pi -e). -u specifies the user for crontab. -u defaults to the user crontab is run as so if you launch it as pi it won't need this. -e launches the editor for you (on pi it will give you a choice of editors).
I just realized. If you're launching it from cron, vlc is not going to have access to the DISPLAY environment variable specifying your X server's address. What you can do is: log into x as usual (start a gui session), do an "echo $DISPLAY" to find the value and then use that in your script file immediately prior to each vlc command.

(example: if echo $DISPLAY returns ":1")

Code: Select all

If [[ foo ]] ; then DISPLAY=:1 cvlc --loop --fullscreen folder_of_jpegs/* fi
Otherwise it won't be able to connect to the display server. Also, you probably don't want to launch your script as a privileged user or use sudo at all in it. You can use crontab -u to specify a user. Note that vlc will refuse to launch as root (which, if you're editing the root crontab is what it will launch as).

ColtonParadigm
Blank Cone
Blank Cone
Posts: 14
Joined: 15 Jan 2019 04:47

Re: Raspberry Pi 3b+ & VLC

Postby ColtonParadigm » 30 Jan 2019 17:52

Is this a normal out put for this echo $DISPLAY

Code: Select all

:0.0
this is exactly what is displayed when i execute that echo cmd
i will attempt this and let you know.
also i have updated the cron to be the -u cron vs the sudo cron and purged sudo crons table info.
I really hope this works lol

ColtonParadigm
Blank Cone
Blank Cone
Posts: 14
Joined: 15 Jan 2019 04:47

Re: Raspberry Pi 3b+ & VLC

Postby ColtonParadigm » 30 Jan 2019 18:01

i have one script that is running from /etc/xdg/lxsession/LXDE-pi/autostart that executes an SFTP process.
does this need to still run as sudo or will it execute properly if the pi user has access the folders it uses?

1MAXT3HKphYo
Blank Cone
Blank Cone
Posts: 22
Joined: 29 Jan 2019 01:35

Re: Raspberry Pi 3b+ & VLC

Postby 1MAXT3HKphYo » 30 Jan 2019 20:29

Is this a normal out put for this echo $DISPLAY

Code: Select all

:0.0
this is exactly what is displayed when i execute that echo cmd
i will attempt this and let you know.
also i have updated the cron to be the -u cron vs the sudo cron and purged sudo crons table info.
I really hope this works lol
Yes, that's normal. here are some more example values.

1MAXT3HKphYo
Blank Cone
Blank Cone
Posts: 22
Joined: 29 Jan 2019 01:35

Re: Raspberry Pi 3b+ & VLC

Postby 1MAXT3HKphYo » 30 Jan 2019 20:36

i have one script that is running from /etc/xdg/lxsession/LXDE-pi/autostart that executes an SFTP process.
does this need to still run as sudo or will it execute properly if the pi user has access the folders it uses?
Probably better to put that in pi user's cron with the vlc script. You have it right re: sudo. You shouldn't need sudo if it's downloading to a folder pi owns.

You might want to check on the ownership of the files you have already downloaded. They might be owned by root which isn't a big deal but errors will happen if you try to delete or modify those files. Chown can fix that for you (chown --help and/or man chown).

ColtonParadigm
Blank Cone
Blank Cone
Posts: 14
Joined: 15 Jan 2019 04:47

Re: Raspberry Pi 3b+ & VLC

Postby ColtonParadigm » 31 Jan 2019 01:15

i want this process to run at every boot so will this be possible to do with cron...i dont know

1MAXT3HKphYo
Blank Cone
Blank Cone
Posts: 22
Joined: 29 Jan 2019 01:35

Re: Raspberry Pi 3b+ & VLC

Postby 1MAXT3HKphYo » 31 Jan 2019 01:48

i want this process to run at every boot so will this be possible to do with cron...i dont know
Cron is a daemon that normally starts at boot and runs in the background, so yes, provided it's enabled. You can check if the cron daemon is running with "systemctl status cron". If it's not running and enabled (unlikely) you can enable it with "systemctl enable cron".

1MAXT3HKphYo
Blank Cone
Blank Cone
Posts: 22
Joined: 29 Jan 2019 01:35

Re: Raspberry Pi 3b+ & VLC

Postby 1MAXT3HKphYo » 31 Jan 2019 02:00

I see what you mean. You want it to start on boot in addition to being launched by cron, which is launched on boot. If that's the case, put your script in a file called .xsessionrc in Pi's home folder. When X is started by the display manager and pi logs in (if you have pi set up to log in automatically), your script will be run.

. xsessionrc is sort of like the windows start folder, but not exactly, and there other (possibly preferable) ways to launch apps when X is started. More info here.


Return to “VLC media player for Linux and friends Troubleshooting”

Who is online

Users browsing this forum: No registered users and 23 guests