Restart Legato framework from user application


#1

Hi
is it possible to execute “legato restart” command from a user application to restart the Legato framework?

Thanks


#2

Can I ask why you want to do this? Are you trying to work around another problem?

I think that in order for your app to have permissions to execute legato restart, it would have to run unsandboxed. Even then, I think you might run into another problem. As legato restart is executing, it will kill all of the processes that were started under legato. The problem is that you would have also spawned the legato restart process from within legato, so it might end up killing itself. I haven’t tried this myself, but I think you might find that is a problem.

Again, I’m curious why it is necessary to restart legato.


#3

Hi,
we are developing our own cloud server to monitor, control and manage WP8548 and for remote troubleshooting I want reboot option from our server similar to airvantage (find below image).

Thanks


#4

Hi @niladridm,

See le_framework_interface.

le_result_t le_framework_Restart(bool manualRestart) might be what you’re after.

It’d be wise to use with caution as @dfrey mentions. Haven’t used this myself either.

Cheers,
Raf


#5

I think what @Raf suggested about le_framework_Restart is a good idea, but I don’t think it will give you the result you want because it will just be restarting the legato framework and it won’t reboot the entire system.


#6

Thank you Raf and David.
I am trying with this api but having issue in my cdef. Here i have requires api “le_framework.api” and in adef I have bindings “myapp.myApp.le_framework -> .le_framework” but I am not able to build my code as it is throwing le_framework.api not found. Any suggestion.

Thanks


#7

Hi @niladridm.

Eventually, I would like to implement similar functionality (remote reboot without AirVantage) so I’m also looking for a solution.

The.adef bindings should look like this: myapp.myApp.le_framework -> <root>.le_framework
See http://legato.io/legato-docs/latest/c_framework.html

What version of Legato are you using? Are you using 16.7.x by any chance?
If so, le_framework.api isn’t included. It’s part of the latest version (16.10.x), though.

You can achieve the Legato restart in 16.7.x using le_sup_ctrl.api instead. However, this API is deprecated and will be removed in the future so I wouldn’t use it for anything other than only testing if the Legato Restart provides the functionality you’re after.

My recommendation would be to move to the latest Legato version and use le_framework.api instead.

Note that restarting the Legato framework and rebooting are not the same. I’m assuming you’re more after the latter (me too).

I’ve got a few ideas on how to achieve the reboot (not sure how ‘safe’ they are though).

One method is to run the app unsandboxed (sandboxed: false) and implement a function similar to this (error handling omitted for clarity):

static void SystemReboot(void)
{
	system("/sbin/reboot -f");
}

This should sync all filesystems, then reboot immediately. Make sure this doesn’t get executed automatically! Either force the app to be started manually or prevent this by some other means.
Again, this requires root privileges so it may leave the system vulnerable.

It would be nice to know how AirVantage implements it, or if/how we can implement this safely from user space.

Cheers,
Raf


#8

Hi,

I have a question, why not send a signal (like a SIGINT) from inside a sandboxed app and then let the supervisor take care of shutting down and restarting ? I mean, is there a reason not to do that, after all you can control exactly when and under what conditions to send your signal and the supervisor will handle the reboot in a clean fashion, or at least that’s how I understood it, is that wrong ?


#9

Thanks @happytuna.

Letting the supervisor handle it sounds like a much better and safer method.

I’ve implemented this by adding the following to an app (sandboxed):

myApp.adef

faultAction: reboot

myApp.cdef

cflags:
{
    -I$LEGATO_ROOT/framework/c/src/
}

myApp.c

#include "killProc.h"
.
.
.
static void Reboot(void)
{
    kill_SendSig(getpid(), SIGINT);
}

Note: kill_Hard(getpid()); will also work.