Startup Script

Having issues with your DietPi installation, or, found a bug? Post it here.
Sipador

Startup Script

Post by Sipador »

Hi Everyone,

I have an mplayer script I want to run once the desktop environment (and any other relent programs) starts up.

Tried to add:
@reboot /root/mplayer_script.sh

At the bottom of /etc/crontab
Sorry still learning my way around bash, loving dietpi btw :D.

Thanks for any help!
User avatar
Fourdee
Site Admin
Posts: 2788
Joined: Tue Feb 06, 2007 1:36 pm

Re: Startup Script

Post by Fourdee »

Sipador wrote:Hi Everyone,

I have an mplayer script I want to run once the desktop environment (and any other relent programs) starts up.

Tried to add:
@reboot /root/mplayer_script.sh

At the bottom of /etc/crontab
Sorry still learning my way around bash, loving dietpi btw :D.

Thanks for any help!
Try this using a SystemD service to launch after graphical.target (copy and paste all into terminal):

Code: Select all

cat << _EOF_ > /etc/systemd/system/myscript.service
[Unit]
Description=myscript
After=graphical.target

[Service]
Type=oneshot
RemainAfterExit=yes

ExecStart=/bin/bash -c '/root/mplayer_script.sh'

[Install]
WantedBy=default.target
_EOF_
systemctl enable myscript.service
systemctl daemon-reload
reboot, then check the status with:

Code: Select all

systemctl status mplayer_script.sh -l
If you find our project or support useful, then we’d really appreciate it if you’d consider contributing to the project however you can.
Donating is the easiest – you can use PayPal or become a DietPi patron.
Sipador

Re: Startup Script

Post by Sipador »

Fourdee wrote:
Sipador wrote:Hi Everyone,

I have an mplayer script I want to run once the desktop environment (and any other relent programs) starts up.

Tried to add:
@reboot /root/mplayer_script.sh

At the bottom of /etc/crontab
Sorry still learning my way around bash, loving dietpi btw :D.

Thanks for any help!
Try this using a SystemD service to launch after graphical.target (copy and paste all into terminal):

Code: Select all

cat << _EOF_ > /etc/systemd/system/myscript.service
[Unit]
Description=myscript
After=graphical.target

[Service]
Type=oneshot
RemainAfterExit=yes

ExecStart=/bin/bash -c '/root/mplayer_script.sh'

[Install]
WantedBy=default.target
_EOF_
systemctl enable myscript.service
systemctl daemon-reload
reboot, then check the status with:

Code: Select all

systemctl status mplayer_script.sh -l
Hey, Fourdee thanks for the assistance! I followed it but ended up with:

Code: Select all

root@DietPi:~# systemctl status mplayer_script.sh -l
● mplayer_script.sh.service
   Loaded: not-found (Reason: No such file or directory)
   Active: inactive (dead)
Which is strange because if I just copy and paste

Code: Select all

root@DietPi:~#/root/mplayer_script.sh
it'll start playing the video. Could it be root privileges?

Thanks again for your help :)
User avatar
Fourdee
Site Admin
Posts: 2788
Joined: Tue Feb 06, 2007 1:36 pm

Re: Startup Script

Post by Fourdee »

My bad lol ;)

Correct command is:

Code: Select all

systemctl status myscript.service -l
If you find our project or support useful, then we’d really appreciate it if you’d consider contributing to the project however you can.
Donating is the easiest – you can use PayPal or become a DietPi patron.
Sipador

Re: Startup Script

Post by Sipador »

Fourdee wrote:My bad lol ;)

Correct command is:

Code: Select all

systemctl status myscript.service -l
Ah yes that makes sense, interesting results:

Code: Select all

● myscript.service - myscript
   Loaded: loaded (/etc/systemd/system/myscript.service; enabled)
   Active: active (exited) since Thu 2016-11-03 05:02:49 GMT; 10min ago
  Process: 1186 ExecStart=/bin/bash -c /root/mplayer_script.sh (code=exited, status=0/SUCCESS)
 Main PID: 1186 (code=exited, status=0/SUCCESS)
   CGroup: /system.slice/myscript.service

Nov 03 05:02:47 DietPi systemd[1]: Starting myscript...
Nov 03 05:02:49 DietPi bash[1186]: Cannot find HOME directory.
Nov 03 05:02:49 DietPi bash[1186]: MPlayer2 2.0-728-g2c378c7-4 (C) 2000-2012 MPlayer Team
Nov 03 05:02:49 DietPi bash[1186]: Terminal type `unknown' is not defined.
Nov 03 05:02:49 DietPi bash[1186]: Playing big_buck_bunny_1080p_H264_AAC_25fps_7200K.MP4.
Nov 03 05:02:49 DietPi bash[1186]: Cannot open file 'big_buck_bunny_1080p_H264_AAC_25fps_7200K.MP4': No such file or directory
Nov 03 05:02:49 DietPi bash[1186]: Failed to open big_buck_bunny_1080p_H264_AAC_25fps_7200K.MP4.
Nov 03 05:02:49 DietPi bash[1186]: Dead key input on file descriptor 0
Nov 03 05:02:49 DietPi bash[1186]: Exiting... (End of file)
Nov 03 05:02:49 DietPi systemd[1]: Started myscript.
So it does run the script, but when its run it can't see root directory or any contents. Is it because myscript.service is being run outside of root access?
User avatar
Fourdee
Site Admin
Posts: 2788
Joined: Tue Feb 06, 2007 1:36 pm

Re: Startup Script

Post by Fourdee »

Sipador wrote: Nov 03 05:02:49 DietPi bash[1186]: Cannot find HOME directory.

So it does run the script, but when its run it can't see root directory or any contents. Is it because myscript.service is being run outside of root access?
Can you paste the contents of your script? I'll take a look.
If you find our project or support useful, then we’d really appreciate it if you’d consider contributing to the project however you can.
Donating is the easiest – you can use PayPal or become a DietPi patron.
Sipador

Re: Startup Script

Post by Sipador »

Code: Select all

#!/bin/sh
set -e

if [ ! -w /dev/cedar_dev ]; then
        # chmod 666 /dev/cedar_dev
        echo "Error: /dev/cedar_dev missing or no access"
        exit 1
fi

if [ ! -w /dev/ion ]; then
        # chmod 666 /dev/ion
        echo "Error: /dev/ion missing or no access"
        exit 1
fi

if [ ! -w /dev/disp ]; then
        # chmod 666 /dev/disp
        echo "Error: /dev/disp missing or no access"
        exit 1
fi

export VDPAU_DRIVER=sunxi
DISPLAY=:0 mplayer -fs -autosync 50 -mc 1.5 -vo vdpau -vc ffmpeg12vdpau,ffh264vdpau,ffhevcvdpau, big_buck_bunny_1080p_H264_AAC_25fps_7200K.MP4 -loop 0
User avatar
Fourdee
Site Admin
Posts: 2788
Joined: Tue Feb 06, 2007 1:36 pm

Re: Startup Script

Post by Fourdee »

Sipador wrote:

Code: Select all

#!/bin/sh
set -e

if [ ! -w /dev/cedar_dev ]; then
        # chmod 666 /dev/cedar_dev
        echo "Error: /dev/cedar_dev missing or no access"
        exit 1
fi

if [ ! -w /dev/ion ]; then
        # chmod 666 /dev/ion
        echo "Error: /dev/ion missing or no access"
        exit 1
fi

if [ ! -w /dev/disp ]; then
        # chmod 666 /dev/disp
        echo "Error: /dev/disp missing or no access"
        exit 1
fi

export VDPAU_DRIVER=sunxi
DISPLAY=:0 mplayer -fs -autosync 50 -mc 1.5 -vo vdpau -vc ffmpeg12vdpau,ffh264vdpau,ffhevcvdpau, big_buck_bunny_1080p_H264_AAC_25fps_7200K.MP4 -loop 0
Try defining the absolute filepath to big_buck_bunny_1080p_H264_AAC_25fps_7200K.MP4. eg:

Code: Select all

/root/mystuff/big_buck_bunny_1080p_H264_AAC_25fps_7200K.MP4
If you find our project or support useful, then we’d really appreciate it if you’d consider contributing to the project however you can.
Donating is the easiest – you can use PayPal or become a DietPi patron.
Sipador

Re: Startup Script

Post by Sipador »

Hey Fourdee,

Sorry for the late reply, went through exams and my image was corrupted so I went back and remade it.

Some of the names have changed but much the same as before.
On the plus side when I rebooted the audio was playing but the video didn't show, so that's positive step forward :) .

This is the output from the script.

Thanks again!

Code: Select all

root@DietPi:~# systemctl status myscript.service -l
● myscript.service - myscript
   Loaded: loaded (/etc/systemd/system/myscript.service; enabled)
   Active: activating (start) since Wed 2016-11-30 00:17:38 GMT; 2min 27s ago
 Main PID: 908 (mplayer-play.sh)
   CGroup: /system.slice/myscript.service
           ├─908 /bin/sh /EBTV/mplayer-play.sh
           └─911 mplayer -fs -autosync 50 -mc 1.5 -vo vdpau -vc ffmpeg12vdpau,ff                                                                                                                                                             h264vdpau,ffhevcvdpau, /EBTV/big_buck_bunny_1080p_H264_AAC_25fps_7200K.MP4 -loop                                                                                                                                                              0

Nov 30 00:19:10 DietPi bash[908]: [2.0K blob data]
Nov 30 00:19:16 DietPi bash[908]: [1.9K blob data]
Nov 30 00:19:23 DietPi bash[908]: [1.9K blob data]
Nov 30 00:19:28 DietPi bash[908]: [1.9K blob data]
Nov 30 00:19:33 DietPi bash[908]: [1.9K blob data]
Nov 30 00:19:39 DietPi bash[908]: [1.9K blob data]
Nov 30 00:19:46 DietPi bash[908]: [1.9K blob data]
Nov 30 00:19:52 DietPi bash[908]: [1.9K blob data]
Nov 30 00:19:58 DietPi bash[908]: [1.9K blob data]
Nov 30 00:20:04 DietPi bash[908]: [1.9K blob data]
User avatar
Fourdee
Site Admin
Posts: 2788
Joined: Tue Feb 06, 2007 1:36 pm

Re: Startup Script

Post by Fourdee »

Mplayer should work on fbdev, so not sure why there is no video. Does the video work when you run from the cmdline? Might also be SystemD, try adding StandardOutput=tty under the [Service] section of the service.

Failing that, lets try X11, change your script so that xinit is called, before mplayer, eg:

Code: Select all

xinit mplayer -fs -autosyn......................
Also, make sure you have X11 installed:

Code: Select all

dietpi-software install 6
If you find our project or support useful, then we’d really appreciate it if you’d consider contributing to the project however you can.
Donating is the easiest – you can use PayPal or become a DietPi patron.
Post Reply