1

I want to launch a 'Qt' app on my board during start-up. It's using systemd to start the processes and the graphics backend is wayland. Since it's using systemd, I wrote a simple service to start my app. PSB.

[Unit] 
Description=Qt App 
After=multi-user.target


[Service] 
Type=simple 
WorkingDirectory=/home/root 
ExecStart=/etc/init.d/qtapp start

[Install] 
WantedBy=multi-user.target

That '/etc/init.d/qtapp' script just sources the 'profile', sets the XDG_* envs and starts my Qt app. But with this setup, my app is not lauching at all. But when I checked the list of running process, it lists my app as well. So, it's running but I'm getting nothing on the screen.

If I start the app manually after board is up, it's running fine. I'm not sure why it's not launching from systemd.

Have anyone faced this issue? and any suggestions that I can try to make it working?

vraj010
  • 116
  • 1
  • 2
  • 8
  • Could be a permissions issue, did you try running the qtapp from command line using the same user as when it's executed at startup? – Marco Jul 13 '15 at 08:14
  • I used to login as root. I can run the same app from command line without any issue. After boot-up, I have checked systemctl status and I can see that my app is running, but nothing on the screen. – vraj010 Jul 13 '15 at 08:23
  • So you are sure that systemd is running your app as root? – Marco Jul 13 '15 at 11:44
  • I don't have much idea about systemd. So, I'm not sure if it's running my app as root. – vraj010 Jul 13 '15 at 12:14

2 Answers2

0

I had same problem in my work. I need to run my application 7/24 and application should rerun automatically when it crashes or user manually exit. For that purpose I created file in /etc/init.d/xxx for startup. However I am not running my application in here. It is just starting another bash script, which is checking running processes and using "grep" check whether my application is running or not. If it is not running it runs again. Why I am using like this;

  • I add all libraries, Qt, Opencv, and my other libs
  • Adding command will be easier, like showing which config file it needs to use and which debug level it should work
  • Storing log files from console output like (2>&1 etc..)

EDIT:

So you can create upstart script, which is starting your other app's bash script. Forexample;

Upstart script:

start on runlevel [2345]
stop on runlevel [016]

sleep 120

script
    exec /.1/MyApp/myApp.sh
end script

And here is myApp.sh:

    #!/bin/bash

    export QTDIR=/.1/MyApp/lib:/usr/local/Trolltech-4.8.2/
    export LD_LIBRARY_PATH=/.1/MyApp/lib:/usr/local/Trolltech-4.8.2/lib

    while true;do

    ps cax | grep myApp > /dev/null
    if [ $? -eq 0 ]; then
        echo "Application running " >> /.1/MyApp/bin/log/testUp.log
        sleep 10
    else
        echo "Application started " >> /.1/MyApp/bin/log/testUp.log
        cd /.1/MyApp/bin/
        /.1/MyApp/bin/myApp -c /.1/MyApp/conf/myApp.cfg -d 5  2>&1  > /.1/MyApp/bin/log/testUp.log

    fi

    done
goGud
  • 4,163
  • 11
  • 39
  • 63
0

It may be because, of deadlock situation here. You have given After=multi-user.target in [Unit] section of service file, which will start your service after multi-user.target is up and at the same time you have want this to start with multi-user.target in [Install] section of your service file by giving option WantedBy=multi-user.target

This is creating a deadlock type of dependency. To avoid this launch your service with different target in [Install] section. Or just remove "After=" option from [Unit] section (if you do not want any dependency)

Note: Do enable your service file before rebooting your system using systemctl enable your_service_file.service

Saturn
  • 966
  • 7
  • 14