Startup Script Topic is solved

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

Re: Startup Script

Post by Sipador »

I gave that a shot and ended up with some fatal errors in the log lol (x11 was installed).

But that's all good, when I watched the boot I noticed the audio would begin to play before the boot messages would finish and the desktop would eventually load. I decided to add a sleep 60 to the beginning of my script and when it rolled around it all loaded up correctly.

Its hacky as all hell and the OCD part of me would like something more concrete but I am happy that it loads :), thank you for your help Fourdee, really do appreciate it.

Not sure if there is a way to tell myscript.services to wait until x11 has loaded or potentially some other processes so it runs once all other processes are operational?

after I get this baby operational I'll be moving on to playing with cloud stuff :)
User avatar
Fourdee
Site Admin
Posts: 2788
Joined: Tue Feb 06, 2007 1:36 pm

Re: Startup Script

Post by Fourdee »

Sipador wrote:I gave that a shot and ended up with some fatal errors in the log lol (x11 was installed).

But that's all good, when I watched the boot I noticed the audio would begin to play before the boot messages would finish and the desktop would eventually load. I decided to add a sleep 60 to the beginning of my script and when it rolled around it all loaded up correctly.

Its hacky as all hell and the OCD part of me would like something more concrete but I am happy that it loads :), thank you for your help Fourdee, really do appreciate it.

after I get this baby operational I'll be moving on to playing with cloud stuff :)
:D
Not sure if there is a way to tell myscript.services to wait until x11 has loaded or potentially some other processes so it runs once all other processes are operational?
Yep, is your systemD service currently set to After=graphical.target?

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
If After=graphical.target isnt waiting for X11, you can add some code to your script that will wait for the X11 process to start, eg (untested):

Code: Select all

# - Wait for X11 process to run
while (( ! $(ps aux | grep -ci -m1 '[X]11') ))
do 
	# - wait 3 seconds before checking again
	sleep 3
	
done

play movie
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 »

Yep, is your systemD service currently set to After=graphical.target?

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
If After=graphical.target isnt waiting for X11, you can add some code to your script that will wait for the X11 process to start, eg (untested):

Code: Select all

# - Wait for X11 process to run
while (( ! $(ps aux | grep -ci -m1 '[X]11') ))
do 
	# - wait 3 seconds before checking again
	sleep 3
	
done

play movie
Yep After=graphical.target is set in myscript.service, it doesn't appear to be waiting.
Had to modify your script slightly to ( !(ps aux | grep -ci -m1 '[X]11') ) it works! :-D
Didn't see the desktop before the video started to play, feels good hehe.

Thanks again!
Post Reply