Launch app with xinit on startup

Discussion in 'Scripting' started by Stannieman, Sep 11, 2015.

  1. Stannieman

    Stannieman MDL Guru

    Sep 4, 2009
    2,232
    1,800
    90
    #1 Stannieman, Sep 11, 2015
    Last edited by a moderator: Apr 20, 2017
    Hi,

    I've written a photo booth application in python to run on a raspberry pi. I have a minimal debian jessie running and the following script:
    Code:
    #! /bin/bash
    date -s "01 JAN 1999 00:00:00"
    service ntp stop
    timeout 10s ntpd -gq
    service ntp start
    xinit /usr/bin/python3.4 /root/Main.py $* -- :1
    This script does some time stuff + it starts X and the python program
    Now when the pi has booted, I log in as root and run the script, this works like a charm.
    However when I add
    Code:
    @reboot /root/startPhotoBooth.sh
    to /var/spool/cron/crontabs/root it doesn't work, whereas other things in the cron file like creating a testfile do work.

    Apparently it is quiet normal for xinit not to work in this way, but I'm not exactly sure how to fix it.
    Can anyone help me with this?

    Thanks!

    EDIT: I also added DESKTOP:=0 to the top of the cronfile but that doesn't work either.
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  2. Stannieman

    Stannieman MDL Guru

    Sep 4, 2009
    2,232
    1,800
    90
    #2 Stannieman, Sep 16, 2015
    Last edited by a moderator: Apr 20, 2017
    (OP)
    Ok I got it working but the problem evolved into something else...

    I now have an /etc/rc.local which looks like this:
    Code:
    su -l root -c \"exec /root/startPhotoBooth.sh
    exit 0
    Ans startPhotoBooth looks like this:
    Code:
    xinit /usr/bin/python3.4 /root/Main.py -nolisten tcp
    while [ ! -f /tmp/.X0-lock ]
    do
    sleep 0.1
    done
    export DISPLAY=:0
    xset -dpms
    xset s off
    xset s noblank
    This starts the app, and shows the GUI thing on the screen.
    But as you can see this isn't an ideal situation because:
    1. rc.local never exists, it only exits when startPhotoBooth.sh exits, which is after the application exits. Ideally the app should run in the background allowing rc.local to exit and the boot to finish completely.
    2. The xset commands never run because the xinit line needs to finish first, which it of course only does when the app stops.

    So a solution is to change the first line of startPhotoBooth to
    Code:
    xinit /usr/bin/python3.4 /root/Main.py -nolisten tcp &
    , but that doesn't work either because it results in the same problem as before because the rest of the script then runs on the current terminal and xinit has no screen anymore to show it's things on.

    EDIT:
    Got an ugly fix, startPhotoBooth looks like this now:
    Code:
    #! /bin/bash
    /root/disableDisplayTimeout.sh &
    xinit /usr/bin/python3.4 /root/Main.py -nolisten tcp
    
    with all other code moved to disableDisplayTimeout.sh.
    It works, but still prevents rc.local from properly terminating...
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...