1
votes

I have a python script that starts a fullscreen animation when run - how do i set this to start at startup in ubuntu 16.04? Other answers to the "script on startup" problem don't work - because I'm assuming they're executed before the desktop environment has a chance to start up...

I have a script called "startup.sh" that reads as:

xrandr --output HDMI-0 -s 1280x1024

source activate demo

cd ~/demo/

python run.py

Where the first line sets the correct resolution - the second line activates an anaconda environment, the third line changes directory (parts of the script need it to be in that directory, and the 4th line finally runs the script that launches a fullscreen graphic (using pygame, if it matters.)

How can i set this to auto run after unity finishes setting up? Thanks so much... any help or comments at all are really appreciated...

EDIT: it looks like someone here had a similar problem: https://www.raspberrypi.org/forums/viewtopic.php?t=128602

They wanted to start a pygame script on startup - and were able to do so after their desktop environment loaded by putting a call to their program in ~/.config/lxsession/LXDE-pi/autostart - I'm not using LXDE - i'm on unity, so is there an equivalent?

1
I'm voting to close this question as off-topic because it might be a good question for Ask Ubuntu. Here the questions should be more programming related.Klaus D.
The X11 server is not running when the system boots. A script which runs properly at startup doesn't have access to your home directory. Do you mean you want to run this when you log in to your desktop?tripleee

1 Answers

-1
votes

Easiest way to run things at startup is to add them to the file /etc/rc.local.

But to do this properly, you should use the update-rc.d command. You may try it like this:

update-rc.d /path_to_script/script_name.sh start 2

Or use update-rc.d /path_to_script/script_name.sh defaults to create both startup and kill scripts all at once.

For more precise actions you can visit here for details information: http://manpages.ubuntu.com/manpages/xenial/man8/update-rc.d.8.html.