Calling a Legato App from a Startup Script

I am trying to run a bash startup script that will run on startup and then will start a few Legato services as needed based on a scheduler.

From Command line: app start myapp - works fine

From command line using script: subprocess.call(‘app start myapp’, shell=True) when run inside script - works fine

Same script when run during startup - does nothing, just doesn’t start the service, no error, nothing

I tried changing out the subprocess call to: subprocess.call(‘/legato/systems/current/apps/appName/read-only/bin/appName’, shell=True) but it seems like it tries to run, but errors out instead of running like normal.

What is the proper way to call a Legato app from a script?

If you have an example app, that would be awesome as well.

you can set the .adef to let the application auto-start

You can also run a script in a unsandboxed application:

Yes, I understand that. I have done both of those already, but I am trying to do it the other way around.

I want to call an app from a script.

For example, I want to poll GPS location every X hours from my script. I need the ability to call ‘app start myGPSapp’ from my script. That works fine when I run ‘app start myGPSapp’. It also works fine when I put it in my script and run the script manually from the command line. When I try to run it as a startup script, the startup script starts just fine, the time comes for the ‘app start myGPSapp’ to be called, but nothing ever happens.

I am thinking it may be a path issue. I only have a root user, so I don’t think it is permission issue.

how did you set up your startup script?

did you modify /etc/init.d/startlegato.sh?
If yes, did you add some delay on the script with a new process (i.e. sh /home/root.test.sh &")as the legato framework might not start completely at this timeslot?

I am using the pyRTE app (python app developed by the Sierra guys in Australia )
https://bitbucket.org/m2mconnectivity/pyrtedoc/wiki/Home

It allows you to run Python and python libraries on the FX30. Really slick code.

In the setup, if you put your bash script in /home/root/myapp/start.sh it will automatically run at boot.
It works great. I wrote a python scheduler and it will run processes every x seconds, x minutes, x hours, etc.

All the python code and functions work fine. I just can’t figure out how to call the Legato apps that I need to call periodically.

then in your python script, can it call a shell to run a script which is going to start the legato application?
if yes, then if you modify /etc/init.d/startlegato.sh, can it call the python script above?

then in your python script, can it call a shell to run a script which is going to start the legato application?

If my python script is run from the command line, it will start the legato application just fine using subprocess which is the way python runs command line calls. ie. subprocess.call(‘app start myapp’, shell=True)

When I run it as startup script, ALL the python functionality works, but the legato call does not work.

if yes, then if you modify /etc/init.d/startlegato.sh, can it call the python script above?

I don’t think I need to use startlegato.sh as the startup.sh starts the python scheduler just fine. It is the calls to ‘app start myGPSapp’ that don’t seem to work.

since your python script is OK to be run from the command line to call legato app, you can create a bash script to start your python script to start legato app

After that you can modify /etc/init.d/startlegato.sh to call this bash script with a new shell

since your python script is OK to be run from the command line to call legato app, you can create a bash script to start your python script to start legato app

If you are saying have my python scheduler (which is started in the bash startup script) , call a 2nd script which contains the subprocess call to the legato app, I tried that and it did not work.

After that you can modify /etc/init.d/startlegato.sh to call this bash script with a new shell

How do I do this and what will this accomplish?

Thinking about this another way…

How do people normally call the GPS app to get periodic updates?

Should I just change myGPSapp to start automatically and then create a while loop that sleeps for an hour and then gets the current GPS location?

Seems like running a program forever unnecessarily when a call to the Legato application should be available to a script.

I have tried the following in WP76 FW R16:

  1. adding support of python3
  2. create a script /home/root/python_test2.py
import subprocess
subprocess.call(["/mnt/legato/system/bin/app", "start","voiceCallService"])
  1. compile a unsandboxed legato application with the following code:
COMPONENT_INIT
{
   
	sleep(90);
	system("python3.5 /home/root/python_test2.py");

    LE_INFO("Hello, world.");
    
}
  1. after boot up, the legato application will be run automatically, and then after 90 seconds, it can start the legato application voiceCallService

subprocess.call([“/mnt/legato/system/bin/app”, “start”,“voiceCallService”])

This is what I was needing. It was a path issue to the app command.

Thank you!!