My main question is: Is it possible to run an OPENGL program via a daemon (upstart script)? The program displays a window on the screen.

More details: I have an opengl program (done with openframeworks, C++) that i want to run with a daemon.

Manually i start my program in the terminal like this:

planeviz@planeviz:~/src/of/apps/myApps/planeEtoiles/bin$ ./planeEtoiles

Now i created an upstart script (/etc/init/myapp.conf), that should start the program when the computer boots, and make sure to restart it in case of crashes.

# job file
description "myapp"
author "eva"

# When to start the service
start on startup
start on runlevel [2345]

# When to stop the service
stop on runlevel [016]

# Automatically restart process if crashed

# Start the process
    sudo /home/planeviz/src/of/apps/myApps/planeEtoiles/bin/planeEtoiles
end script

Then i try to start the daemon via

sudo service myapp start

My application doesn't open. dmesg tell me:

planeviz@planeviz:/etc/init$ dmesg | grep "init:"
[ 5282.003496] init: myapp main process (8008) terminated with status 139

Termination status 139 seems to hint at a segmentation fault. Looking at the output of my program in the upstart log, i see the last error to be related to the creation of the opengl window.

planeviz@planeviz:/etc/init$ sudo tail /var/log/upstart/planeetoiles.log
[ error ] ofAppGLFWWindow: couldn't init GLFW

This makes me wonder if its even possible to run OPENGL programs with upstart, or if it is only meant to work with background processes?

  • Do you want the program to be displayed on your desktop? Or is it only using OpenGL to perform rendering and saving the output to a file? If the latter, does it rely on the GPU? Jan 10, 2014 at 21:15
  • Yes, i want it to display a window on the screen.
    – evsc
    Jan 10, 2014 at 21:18

1 Answer 1


Upstart is designed for system services. While you can (at least with recent versions) use it to monitor a command that runs during a user session, it's clumsy.

With Upstart, if you want to run a service that displays a GUI window, that service can only run while you're logged in. Rather than start and stop based on runlevels, you need to start and stop based on GUI login and logout events.

start on desktop-session-start
stop on desktop-shutdown

You also need the service to be able to reach your display. GUI applications use the DISPLAY environment variable to determine where to display. Under normal circumstances, your GUI session will be the display called :0.

env DISPLAY=:0

The application also needs to obtain permission to access the display. This permission takes the form of a “cookie” (a password) which is automatically generated when your GUI session starts and stored in the file .Xauthority in your home directory (or another file indicated by the XAUTHORITY environment variable, depending on your display manager). If your display manager uses ~/.Xauthority and you run the service as your user (which you should do anyway), you don't need to set XAUTHORITY. For more details, see Can I launch a graphical program on another user's desktop as root? and Open a window on a remote X display (why “Cannot open display”)?

setuid evsc

Instead of Upstart, you can use a supervision tool that only does supervision and not system service management. Ensure a process is always running lists several possibilities. Let's use supervise from daemontools. Create a directory somewhere, e.g. ~/.planeEtoiles. In this directory, create an executable called run which is the application you want to keep running:

mkdir ~/.planeEtoiles
ln -s /home/planeviz/src/of/apps/myApps/planeEtoiles/bin/planeEtoiles ~/.planeEtoiles/run

Add the command supervise ~/.planeEtoiles to the applications automatically started at login. To stop the service, use the svc command:

svc -t -x ~/.planeEtoiles

The last piece of the puzzle is running that svc command on logout. This feature seems to be missing, or if not it's very poorly documented. If you're using GDM, there's a workaround which is to run from /etc/gdm/PostSession/Default, but that file runs command as root, which is not a good solution, and doesn't apply to Lightdm. Monitor Script Execution at user logout (non root user) and How can I run a script during GNOME logout if I don't have admin privileges? for solutions.

  • i went with the 'supervise' solution, and it's doing exactly what i want it to do! thanks!
    – evsc
    Jan 14, 2014 at 21:30

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.