Bundling Init Script with Legato Installation

Greetings everyone.

Is there a way to automatically run a script upon booting a device? More specifically, is there a way to bundle said script with the Legato platform installation?

I’m using cURL in my application, and it needs to bind against /etc/resolv.conf. The issue is that resolv.conf isn’t created until a data connection is established, so my app ends up faulting because there’s nothing to bind to. Then my app can’t establish a data connection as it can’t start in the first place. Bit of a catch-22.

I figured I would just make a shell script that creates a blank resolv.conf which will then get updated when my app establishes a data connection. But, this is for a production device, so I can’t be manually creating init.d scripts; I need it to be automatically added when I install the Legato platform. This is the part I’m stuck on.

Is this possible? Or is there perhaps a better way of reasoning about this problem? Thank you very much in advance for any help/advice!

Well you should be able to add the script in a .adef file and mark it to be executed when legato starts. I have, however, tried this myself for an external application that I would like to bundle into my legato installation and thereby make it an external .cwe file from the yocto installation. However, for me the limitations that legato puts on a script running in that context, even if it is marked as non-sandboxed, made it a dealbreaker for me and I did therefore add it into the yocto image with in init script instead

Hi andcor, thank you so much for your response! It gave me inspiration for how to proceed.

I tried adding (touch /etc/resolv.conf) to my project’s .adef under processes: { run: { ... } }, but since it tries to link everything before running the processes I run into the same issue. I even tried moving the resolv.conf file link from the application’s .adef to the component’s .cdef, but that had the same issue.

Instead what I ended up doing is creating a separate app that functions as a launcher.

The first thing it does is creates resolv.conf if it doesn’t exist, like so:
system("touch /etc/resolv.conf");

Afterwards, it starts the main app:
le_result_t result = le_appCtrl_Start("mainApp");

Then I kill the launcher since I don’t need it anymore:

And that’s it! Seems to work like a charm.

Also, another bit of semi-related info in case it helps anyone: I also needed to check if a particular process is running first. This can be done via le_appInfo_GetState(const char * appName), which can then be compared against LE_APPINFO_STOPPED and LE_APPINFO_RUNNING. I wanted to add this since it took me a moment of searching to actually find this.