[Ubuntu] Cant run openframewoks app on startup using /etc/rc.local

I have an openframeworks app that I can run automatically using a shell script. I have put the script in the file etc/rc.local so that it can run on startup without password. But when I do that, the app does not start on startup and I see the following error in my log file

[ error ] ofAppGLFWWindow: couldn’t init GLFW

This error does not come when I run the app manually or through a script.
Any clues how I can overcome this?

Thank you

could be that it starts too early during startup and X is not yet fully up?

I think it is that because I remember seeing something that indicated X is not up {cant remember what it was]

How can I ensure it happens only after windowX is up?

you could try adding it in Startup Applications (find it via the Dash - windows key), presumably those only start after login and GUI start (but that’s just a guess, you have to try)

Alternatively, put an appropriate .desktop file in ~/.config/autostart (but that’s basically the same thing)

I just ran into the same problem. My approach was to create an upstart daemon (/etc/init) that should start the OF app on startup, but also restart it in case it crashes (respawn). When i try to activate the daemon manually (with sudo service APP start) it crashes and my last log line is:

[ error ] ofAppGLFWWindow: couldn't init GLFW

So, for me this is not related to restarting the computer and waiting for X, Y, Z to start up properly. It seems to be more a permission issue, to allow the process to open an opengl window?

Any chance you found a solution by now?

I also just posted on stack-exchange: http://askubuntu.com/questions/403630/is-it-possible-to-run-an-opengl-program-via-a-daemon

init daemos run outside the as root so they don’t have a display set, probably if you add:

export DISPLAY=:0

at the beginning of the script it should run once the xserver starts but the best would be to run the app inside the user session using the method bilderbuchi mentioned

Ok So I needed to run the application as root and realized that the error was due to windowX not startnig up. So I just put a sleep of 2 minutes in my script in etc/rc.local before starting the app and now it works.

This solves my problem for now but I would love to know if there is a better solution :smile:)

you can run it in the user session using sudo and add a rule in the sudoers file so executing that program doesn’t require password, don’t remember the exact syntax though, but that would be a better solution than trying to run a program with graphical output as an init daemon

Actually I want my program to run automatically everytime at startup with zero manual intervention. So upon googling I came across etc/rc.local as the script that is used to run scripts as root on startup.

Can you suggest an alternate way of doing this then?

what bilderbuchi suggested should work, just add the application in your start applications and set the desktop so it logs in directly to that user instead of asking for a password

Ok I tried that on my laptop and it works :smile:
I will try it on my installation PC today and let you know later.

I followed the suggestion i got on stackoverflow, to use daemontools and its function supervise. By calling supervise on startup, it starts your application and also restarts it within a second in case the app dies (regular ESC exit or crashes).

So far it is behaving exactly as it should, but i haven’t made extensive tests yet …


  1. Install daemontools
    $ apt-get install daemontools
    in case /etc/service its not created automatically:
    $ mkdir -p /etc/service
  2. Start daemontools on startup
    various methods: http://cr.yp.to/daemontools/start.html
    (note: instead of ‘/command/svscanboot’ use only ‘svscanboot’ - Ubuntu 12.04LT)
  3. Create directory with ‘run’ executable (linked to your app)
    $ mkdir ~/runApp
    $ ln -s ~/of/apps/myApps/xyz/bin/xyz ~/runApp/run
  4. Add supervise script to startup applications
    supervise /home/user/runApp
    (same command also works to start supervise manually, but make sure daemontools is already running)
  5. In case you want to terminate app and supervise manually:
    $ svc -t -x ~/runApp

i m trying to add startup script to my OdroidU3, and i’m facing the same issue, of course. i follow your 3 points @evsc if i run supervise from a terminal the app starrt and if i exit with ESC it restart automatically ( my app is located in /home/odroid/Desktop/runApp ) but if i put:

supervise /home/odroid/Desktop/runApp

in /etc/rc.local before exit0 the app not start automatically, where i must put this line?

I put it directly into the Startup Applications Preferences. You find that window by simply typing “Startup Applications” into the Ubuntu Search. Then you add a new startup program, input whatever name, and input “supervise /home/odroid/Desktop/runApp” as the command.

solved thank you @evsc! i forgot to delete the line added in /etc/rc,local

supervise /home/odroid/Desktop/runApp

but after deleting it and with your instruction works perfectly, i had a problem with the window of Update manager task appearing up my fullscreen but i disabled it from startup. was easy because i can open a terminal and run:

and enter in the Startup window, but how can i stop my fullscreen window if i run it with supervise? because i’can’t stop my app with ESC key…

yep, the secret is to know the keyboard shortcut to open a terminal (usually: ctrl + alt + T)

thank you for the magic secret @evsc! lol

this doesn’t work on Ubuntu 16.04. DaemonTools doesn’t start on boot. Any suggestion? I have found this guide, I’ll try to follow it