# container based xservers to prevent some gpu idling issue
description "docker x11 servers"
author "dnorton"

start on started docker
stop on runlevel [!2345]

# Automatically restart process if crashed (limit 3 times in 4 minutes)
respawn limit 3 240

pre-start script
    logger "waiting for gpu.."
    #TODO: theres probably a better way to wait for the gpu to be available but the upstart docs are kinda bad,
    # hoping systemd will come make things better.
    while [ ! \( -e /dev/tty41 && -e /dev/nvidiactl && -e /dev/nvidia-uvm && -e /dev/nvidia-uvm-tools \) ] ; do
        sleep 1
    done
    logger "starting x11 servers"
end script

chdir /etc/docker-compose/xserver/
exec docker-compose up --force-recreate > /dev/null

post-start script
    logger "x11 servers up"
end script

pre-stop script
    docker-compose stop
end script
