diff mbox series

mongoose, progress: resolve 'Restart System' from web UI IPC event

Message ID 20241102220028.254946-1-radian.dc@gmail.com
State New
Headers show
Series mongoose, progress: resolve 'Restart System' from web UI IPC event | expand

Commit Message

Adrian DC Nov. 2, 2024, 9:58 p.m. UTC
If 'swupdate-progress' service is used with its '-r' reboot mode,
and if 'globals : { postupdatecmd = "/sbin/reboot"; };' is not used,
the 'Restart System' button on the SWUpdate web UI has no effect.

An IPC event 'DONE' is sent upon '/restart' endpoint event,
however the 'swupdate-progress' only prints a log without rebooting.

Add a specific message info to request a reboot through IPC 'DONE'.
---

Related older discussions:
* 2021, Stefano BABIC: https://groups.google.com/g/swupdate/c/SeLdhS8Y8yw/m/JLJT0kpkAwAJ
* 2021, Stefan HERBRECHTSMEIER: https://groups.google.com/g/swupdate/c/SeLdhS8Y8yw/m/JLJT0kpkAwAJ
---

Signed-off-by: Adrian DC <radian.dc@gmail.com>
---
 mongoose/mongoose_interface.c | 8 ++++++--
 tools/swupdate-progress.c     | 3 +++
 2 files changed, 9 insertions(+), 2 deletions(-)

Comments

Stefano Babic Nov. 10, 2024, 10:14 a.m. UTC | #1
Hi adrian,

On 02.11.24 22:58, Adrian DC wrote:
> If 'swupdate-progress' service is used with its '-r' reboot mode,
> and if 'globals : { postupdatecmd = "/sbin/reboot"; };' is not used,
> the 'Restart System' button on the SWUpdate web UI has no effect.
>
> An IPC event 'DONE' is sent upon '/restart' endpoint event,
> however the 'swupdate-progress' only prints a log without rebooting.
>
> Add a specific message info to request a reboot through IPC 'DONE'.

These are currently different use cases :

- Update via Webserver and an operator is asked for a reboot. This
covers the use case when an automatic reboot is unsafe, and an operator
decides when it is a suitable time for restarting with new software.
swupdate-progress is started without "-r" and a postupdate command, that
can be more than just a reboot, is called after pressing the restart
button.

- Update is full automatic, no operator is asked for rebooting.
swupdate-progress gets the -r flag, and the restart button is disabled.
Because there is no one responsible for the decision, SWUpdate shouldn't
reboot in any case just via the Web rest API.

Best regards,
Stefano Babic

> ---
>
> Related older discussions:
> * 2021, Stefano BABIC: https://groups.google.com/g/swupdate/c/SeLdhS8Y8yw/m/JLJT0kpkAwAJ
> * 2021, Stefan HERBRECHTSMEIER: https://groups.google.com/g/swupdate/c/SeLdhS8Y8yw/m/JLJT0kpkAwAJ
> ---
>
> Signed-off-by: Adrian DC <radian.dc@gmail.com>
> ---
>   mongoose/mongoose_interface.c | 8 ++++++--
>   tools/swupdate-progress.c     | 3 +++
>   2 files changed, 9 insertions(+), 2 deletions(-)
>
> diff --git a/mongoose/mongoose_interface.c b/mongoose/mongoose_interface.c
> index 1d636cdf..98639a35 100644
> --- a/mongoose/mongoose_interface.c
> +++ b/mongoose/mongoose_interface.c
> @@ -344,8 +344,12 @@ static const char *get_source_string(unsigned int source)
>
>   static void restart_handler(struct mg_connection *nc, void *ev_data)
>   {
> -	struct mg_http_message *hm = (struct mg_http_message *) ev_data;
> -	ipc_message msg = {};
> +	struct mg_http_message* hm = (struct mg_http_message*)ev_data;
> +	ipc_message msg;
> +
> +	size_t size = sizeof(msg.data.procmsg.buf);
> +	snprintf(msg.data.procmsg.buf, size, "{\"reboot\": \"true\"}");
> +	msg.data.procmsg.len = strnlen(msg.data.procmsg.buf, size);
>
>   	if(mg_strcasecmp(hm->method, mg_str("POST")) != 0) {
>   		mg_http_reply(nc, 405, "", "%s", "Method Not Allowed\n");
> diff --git a/tools/swupdate-progress.c b/tools/swupdate-progress.c
> index 5e371627..6b70546e 100644
> --- a/tools/swupdate-progress.c
> +++ b/tools/swupdate-progress.c
> @@ -442,6 +442,9 @@ int main(int argc, char **argv)
>   			break;
>   		case DONE:
>   			fprintf(stdout, "\nDONE.\n\n");
> +			if (opt_r && strcasestr(msg.info, "\"reboot\": \"true\"")) {
> +				reboot_device();
> +			}
>   			break;
>   		case PROGRESS:
>   			/*
Adrian DC Nov. 11, 2024, 9:40 p.m. UTC | #2
Hi Stefano,

Thanks for the details.

However, I think there's a misunderstanding about the "Restart System" 
button,
and Daniel is in fact trying to address these reboot cases in his 
related topics.

The "Restart System" is accessible either way, but is a "no-op" when no 
"postupdatecmd" is set
and default "-r" swupdate-progress is used as detailed in the commit 
details.

This first-step and atomic patch adds an additional message info to the 
'DONE' event sent by the UI button IPC event,
which (if "-r" is used, hence "opt_r &&") will reboot the device per 
user's request (if he changed his mind, instead of automatically after 
an update).

This is useful for developers and clients to reboot to the "normal" 
system (runtime) if SWUpdate was accessed per request (rescue) but no 
update to perform.
The dead button was discovered during client demonstration hence 
resolved then upstreamed.

Thanks,

*Adrian DC*


On 10/11/2024 11:14, Stefano Babic wrote:
> Hi adrian,
>
> On 02.11.24 22:58, Adrian DC wrote:
>> If 'swupdate-progress' service is used with its '-r' reboot mode,
>> and if 'globals : { postupdatecmd = "/sbin/reboot"; };' is not used,
>> the 'Restart System' button on the SWUpdate web UI has no effect.
>>
>> An IPC event 'DONE' is sent upon '/restart' endpoint event,
>> however the 'swupdate-progress' only prints a log without rebooting.
>>
>> Add a specific message info to request a reboot through IPC 'DONE'.
>
> These are currently different use cases :
>
> - Update via Webserver and an operator is asked for a reboot. This
> covers the use case when an automatic reboot is unsafe, and an operator
> decides when it is a suitable time for restarting with new software.
> swupdate-progress is started without "-r" and a postupdate command, that
> can be more than just a reboot, is called after pressing the restart
> button.
>
> - Update is full automatic, no operator is asked for rebooting.
> swupdate-progress gets the -r flag, and the restart button is disabled.
> Because there is no one responsible for the decision, SWUpdate shouldn't
> reboot in any case just via the Web rest API.
>
> Best regards,
> Stefano Babic
>
>> ---
>>
>> Related older discussions:
>> * 2021, Stefano BABIC: 
>> https://groups.google.com/g/swupdate/c/SeLdhS8Y8yw/m/JLJT0kpkAwAJ
>> * 2021, Stefan HERBRECHTSMEIER: 
>> https://groups.google.com/g/swupdate/c/SeLdhS8Y8yw/m/JLJT0kpkAwAJ
>> ---
>>
>> Signed-off-by: Adrian DC <radian.dc@gmail.com>
>> ---
>>   mongoose/mongoose_interface.c | 8 ++++++--
>>   tools/swupdate-progress.c     | 3 +++
>>   2 files changed, 9 insertions(+), 2 deletions(-)
>>
>> diff --git a/mongoose/mongoose_interface.c 
>> b/mongoose/mongoose_interface.c
>> index 1d636cdf..98639a35 100644
>> --- a/mongoose/mongoose_interface.c
>> +++ b/mongoose/mongoose_interface.c
>> @@ -344,8 +344,12 @@ static const char *get_source_string(unsigned 
>> int source)
>>
>>   static void restart_handler(struct mg_connection *nc, void *ev_data)
>>   {
>> -    struct mg_http_message *hm = (struct mg_http_message *) ev_data;
>> -    ipc_message msg = {};
>> +    struct mg_http_message* hm = (struct mg_http_message*)ev_data;
>> +    ipc_message msg;
>> +
>> +    size_t size = sizeof(msg.data.procmsg.buf);
>> +    snprintf(msg.data.procmsg.buf, size, "{\"reboot\": \"true\"}");
>> +    msg.data.procmsg.len = strnlen(msg.data.procmsg.buf, size);
>>
>>       if(mg_strcasecmp(hm->method, mg_str("POST")) != 0) {
>>           mg_http_reply(nc, 405, "", "%s", "Method Not Allowed\n");
>> diff --git a/tools/swupdate-progress.c b/tools/swupdate-progress.c
>> index 5e371627..6b70546e 100644
>> --- a/tools/swupdate-progress.c
>> +++ b/tools/swupdate-progress.c
>> @@ -442,6 +442,9 @@ int main(int argc, char **argv)
>>               break;
>>           case DONE:
>>               fprintf(stdout, "\nDONE.\n\n");
>> +            if (opt_r && strcasestr(msg.info, "\"reboot\": 
>> \"true\"")) {
>> +                reboot_device();
>> +            }
>>               break;
>>           case PROGRESS:
>>               /*
>
diff mbox series

Patch

diff --git a/mongoose/mongoose_interface.c b/mongoose/mongoose_interface.c
index 1d636cdf..98639a35 100644
--- a/mongoose/mongoose_interface.c
+++ b/mongoose/mongoose_interface.c
@@ -344,8 +344,12 @@  static const char *get_source_string(unsigned int source)
 
 static void restart_handler(struct mg_connection *nc, void *ev_data)
 {
-	struct mg_http_message *hm = (struct mg_http_message *) ev_data;
-	ipc_message msg = {};
+	struct mg_http_message* hm = (struct mg_http_message*)ev_data;
+	ipc_message msg;
+
+	size_t size = sizeof(msg.data.procmsg.buf);
+	snprintf(msg.data.procmsg.buf, size, "{\"reboot\": \"true\"}");
+	msg.data.procmsg.len = strnlen(msg.data.procmsg.buf, size);
 
 	if(mg_strcasecmp(hm->method, mg_str("POST")) != 0) {
 		mg_http_reply(nc, 405, "", "%s", "Method Not Allowed\n");
diff --git a/tools/swupdate-progress.c b/tools/swupdate-progress.c
index 5e371627..6b70546e 100644
--- a/tools/swupdate-progress.c
+++ b/tools/swupdate-progress.c
@@ -442,6 +442,9 @@  int main(int argc, char **argv)
 			break;
 		case DONE:
 			fprintf(stdout, "\nDONE.\n\n");
+			if (opt_r && strcasestr(msg.info, "\"reboot\": \"true\"")) {
+				reboot_device();
+			}
 			break;
 		case PROGRESS:
 			/*