maemo.org - Talk

maemo.org - Talk (https://talk.maemo.org/index.php)
-   Development (https://talk.maemo.org/forumdisplay.php?f=13)
-   -   How to autostart application on boot? (https://talk.maemo.org/showthread.php?t=50094)

rachol 2010-04-15 12:50

How to autostart application at boot?
 
Hi,

I am struggling now for over 12 hours with a problem of starting my application after the boot.

I have created scripts and saved them in following locations:

/etc/init.d/imhere
/etc/init.d/imhere_run_later

then I have used "ln -s" command to create a link to /etc/init.d/imhere from /etc/rc2.d/S99imhere

Unfortunately my application did not start. I started playing around with those files in init.d and finally ended up with following:

/etc/init.d/imhere:
Code:

#!/bin/sh

echo "IMHERE INIT CALLED" >> /home/user/startuplog

case "$1" in
  start)
    echo "IMHERE INIT START CALLED" >> /home/user/startuplog
    /etc/init.d/imhere_run_later &
        ;;
  *)
esac

echo "IMHERE INIT EXITING" >> /home/user/startuplog
exit 0

/etc/init.d/imhere_run_later:
Code:

echo "ENTERED RUN_LATER" >> /home/user/startuplog
sleep 1
echo "SLEPT 1" >> /home/user/startuplog
sleep 1
echo "SLEPT 2" >> /home/user/startuplog
sleep 1
echo "SLEPT 3" >> /home/user/startuplog
sleep 1
echo "SLEPT 4" >> /home/user/startuplog
sleep 1
echo "SLEPT 5" >> /home/user/startuplog
sleep 1
echo "SLEPT 6" >> /home/user/startuplog
sleep 1
echo "SLEPT 7" >> /home/user/startuplog
sleep 1
echo "SLEPT 8" >> /home/user/startuplog
sleep 1
echo "SLEPT 9" >> /home/user/startuplog
sleep 1
echo "SLEPT 10" >> /home/user/startuplog
sleep 10
echo "SLEPT 20" >> /home/user/startuplog
sleep 10
echo "SLEPT 30" >> /home/user/startuplog
sleep 10
echo "SLEPT 40" >> /home/user/startuplog
sleep 10
echo "SLEPT 50" >> /home/user/startuplog
sleep 10
echo "SLEPT 60" >> /home/user/startuplog
sleep 10
echo "SLEPT 70" >> /home/user/startuplog
sleep 10
echo "SLEPT 80" >> /home/user/startuplog
sleep 10
echo "SLEPT 90" >> /home/user/startuplog
sleep 10
echo "SLEPT 100" >> /home/user/startuplog
sleep 10
echo "SLEPT 110" >> /home/user/startuplog
sleep 10
echo "SLEPT 120" >> /home/user/startuplog
sleep 30
echo "SLEPT 150" >> /home/user/startuplog
sleep 30
echo "SLEPT 180" >> /home/user/startuplog
echo "NOT SLEEPING ANYMORE" >> /home/user/startuplog
/usr/bin/imhere &
echo "APP SHOULD BE STARTED BY NOW" >> /home/user/startuplog
exit 0

I created symbolic links for ever /etc/rc?.d/ folder

I have modified also /etc/init.d/hulda by adding at the beggining of the file following piece of code:
Code:

echo "HULDA INIT" >> /home/user/startuplog
After emptying /home/user/startuplog and rebooting my device the file /home/user/startuplog contains only text "HULDA INIT".

If I run myself the script /etc/init.d/imhere from terminal, the startuplog file will fill up with "SLEPT..." and the other echoed text as expected and /usr/bin/imhere starts running.

Question is: Why my own scripts are not called/executed at startup?

Thanks in advance.

krk969 2010-04-15 13:26

Re: How to autostart application on boot?
 
maemo uses upstart , did you try something like this ?

*EDIT*
more info about upstart => link

rachol 2010-04-15 14:20

Re: How to autostart application on boot?
 
Thanks, that was a very good advice. Indeed maemo uses upstart.

I have checked the post about batlevel and it helped a lot, finally my script starts at the startup time.

Now, I see I have some other problems also.

I want to start a Qt application and show the window to the user, the problem is, that the application does not want to start(is terminated?), though I have no problems to run it from applications menu or the command line.

I have heard, that I should split my code to 2 applications ( non graphical daemon, and the window app), but I would prefer having only one.

Any ideas?

krk969 2010-04-15 14:36

Re: How to autostart application on boot?
 
what app is it that you are trying to start ?
how do you start it ?
could you provide more details then somebody or myself could try and help, there isnt much info you have provided :) ?

rachol 2010-04-15 14:45

Re: How to autostart application on boot?
 
I am developing my own application, that listens to text messages and then executes different kind of actions depending on the text given in the message.

Usually the application runs hidden in the background, but it might be woken up (shown in FullScreen) by certain commands in the text messages.

The application is ready and working if it has been run after the reboot, but it does not want to start during startup.

Here is the main.cpp:
Code:

#include <QApplication>
#include "ConfigurationWizard.h"
#include "BackgroundTask.h"
#include "Settings.h"

int main(int argc, char *argv[])
{
    QApplication app(argc, argv);
    QApplication ::setOverrideCursor(QCursor(Qt::BlankCursor));
   
    Settings settings;
   
    ConfigurationWizard window(settings);
    BackgroundTask backgroundTask(settings);
   
    QObject::connect(&backgroundTask, SIGNAL(showConfig()), &window,  SLOT(showFullScreen()));

    return app.exec();
}

Settings and Background classes inherit QOBject, while ConfigurationWizard class inherits QMainWindow.

krk969 2010-04-15 15:04

Re: How to autostart application on boot?
 
what does your startup script in the event.d look like ?
and are you starting the above app in the startup file ?
do you see any error/trace ? or does the app not start at all ?

qwerty12 2010-04-15 15:10

Re: How to autostart application on boot?
 
I know nothing about Upstart, so all I can do is give lame hints.

You may need the D-Bus initialization routines from http://talk.maemo.org/showpost.php?p...9&postcount=16 and, also, have you tried making it start when hildon-desktop has done so? I believe it's something like "start on started hildon-desktop" (alternatively, "start on started xsession" may work for you) in your Upstart service definition.

rachol 2010-04-15 15:11

Re: How to autostart application on boot?
 
This is my /etc/event.d/imhere:
Code:

description "Starts the imhere application"

start on started hildon-desktop
exec /etc/init.d/imhere start
stop on starting shutdown

This is my current /etc.init.d/imhere:
Code:

#!/bin/sh

case "$1" in
  start)
    echo "IMHERE INIT CALLED" >> /home/user/startuplog
    /usr/bin/imhere
        ;;
  *)
esac

echo "IMHERE INIT EXITING" >> /home/user/startuplog
exit 0

after booting my device I get following output in startuplog:
Code:

MHERE INIT CALLED
IMHERE INIT EXITING


rachol 2010-04-15 15:15

Re: How to autostart application on boot?
 
Quote:

Originally Posted by qwerty12 (Post 612010)
I know nothing about Upstart, so all I can do is give lame hints.

You may need the D-Bus initialization routines from http://talk.maemo.org/showpost.php?p...9&postcount=16 and, also, have you tried making it start when hildon-desktop has done so? I believe it's something like "start on started hildon-desktop" (alternatively, "start on started xsession" may work for you) in your Upstart service definition.

I'll have to check D-Bus initialization routines

I have tried to run my application from a init.d script inlcuding:
Code:

echo "SOME TEXT"
sleep 180
echo "SOME TEXT"
/usr/bin/imhere
echo "SOME TEXT"

, so it would for sure have the xsession and hildon-desktop, but I have got only all of the echoed texts, but app did not start,
I have checked with ps -A | grep imhere from terminal

krk969 2010-04-15 15:16

Re: How to autostart application on boot?
 
Code:

start on started hildon-desktop
script
        /usr/bin/imhere
end script

can you try that script placed in the /etc/event.d ?

rachol 2010-04-15 15:21

Re: How to autostart application on boot?
 
Tried, didn't help... :(

b0unc3 2010-04-15 15:22

Re: How to autostart application on boot?
 
Hi,

try to put some printf in the application itself, there will be something that crash (maybe).

rachol 2010-04-15 16:12

Re: How to autostart application on boot?
 
Quote:

Originally Posted by b0unc3 (Post 612040)
Hi,

try to put some printf in the application itself, there will be something that crash (maybe).

Thx,

I have followed your advice, that brought me a bit closer to the soulution.

It crashes/quits/terminates in following line:
Code:

QApplication app(argc, argv)
Now this stuff gets tricky, it seems, that some environment variables or something like that are not set when the application is executed

krk969 2010-04-15 16:21

Re: How to autostart application on boot?
 
Quote:

Originally Posted by rachol (Post 612117)
It crashes/quits/terminates in following line:
Code:

QApplication app(argc, argv)
Now this stuff gets tricky, it seems, that some environment variables or something like that are not set when the application is executed

strange, but have you tried running with run_standalone.sh <your app> ?

rachol 2010-04-15 16:54

Re: How to autostart application on boot?
 
Hi,

I have got it working, thx to krk969 again :)

I have no idea of the reason why, but following file /etc/event.d/imhere didn't work:
Code:

start on started hildon-desktop
script
        run-standalone.sh /usr/bin/imhere
end script

So I tried to change it to:
Code:

start on started hildon-desktop
exec /etc/init.d/imhere start
stop on starting shutdown

Then I have edited /etc/init.d/imhere file to:
Code:

#!/bin/sh

case "$1" in
  start)
    run-standalone.sh /usr/bin/imhere
        ;;
  *)
esac

exit 0

And surprise, surprise it works!! Great! Thank you all, soon(day or two) I will upload an intresting app in extras-devel :)

tuminoid 2010-04-15 18:19

Re: How to autostart application on boot?
 
AFAIK your problem is trying to start Qt GUI app as root, which isn't gonna work as root cannot connect to X. This is demonstrated by segfault in QApplicatio init. For GUI app I'd suggest starting your app in Xsession, with su - user -c "/path/to/app" (cannot test exact syntax as posting this on the road).

rachol 2010-04-15 18:47

Re: How to autostart application on boot?
 
Just checked from curiosity,

su user -c "path" does not work in my case, I have just checked all the possible syntax combinations, none of them worked.

root does not have access to X? it somehow does not sound right... I thought root have access to anything :)

Anyway, I have been running qt applications as a root hundreds of times, it works.

Thanks anyway for a tip.

festivalnut 2010-04-15 18:57

Re: How to autostart application on boot?
 
i'm liking the sounds of this interesting app! any teasers? like if i receive a text with the phrase "i want sex" it will auto-reply "be there in ten mins" and set the satnav to the senders adress? :P

rachol 2010-04-15 18:58

Re: How to autostart application on boot?
 
Actually, it is doing that already :)

PeroMed 2010-07-29 10:55

Re: How to autostart application on boot?
 
this should also work

Quote:

start on started hildon-desktop
exec run-standalone.sh /usr/bin/imhere start
stop on starting shutdown
and if you want to run it as user not root:


Quote:

start on started hildon-desktop
exec run-standalone.sh su user -c /usr/bin/imhere start
stop on starting shutdown


All times are GMT. The time now is 22:24.

vBulletin® Version 3.8.8