Ubuntu: run script after xserver started



Question:

I have a script which I would love to run after xserver has started. This file is located at /home/karl/.scripts/startup/sensei-raw-startup.sh.

How to I invoke this file after xserver has started?


Solution:1

The cleanest solution might be to write an upstart job. Create a file in /etc/init/myjob.conf. That could look for example like this:

description     "My custom upstart job"    start on login-session-start    task    exec /path/to/script.sh  

  • The description defines a short explanation
  • The start on statement describes, at which event the job is executed. We don't need a stop on statement here, I think.
  • A task job is one which runs a short-running process, that is, a program which might still take a long time to run, but which has a definite lifetime and end state.
  • exec is the main part of the job. Take care what environment variables your script needs to be successful. I assume, since your script must run after an X server has started, you need proper environment variables such as $DISPLAY and $XAUTHORITY and maybe also $DBUS_SESSION_BUS_ADDRESS.
  • If you have trouble, take a look at /var/log/upstart/myjob.log where all output of your job goes.

Note:If u also have question or solution just comment us below or mail us on toontricks1994@gmail.com
Previous
Next Post »