diff mbox series

Add service recovery options for QGA on windows

Message ID 20211115022122.2303184-1-yshxxsjt715@gmail.com
State New
Headers show
Series Add service recovery options for QGA on windows | expand

Commit Message

yshxxsjt715@gmail.com Nov. 15, 2021, 2:21 a.m. UTC
From: shenjiatong <yshxxsjt715@gmail.com>

Add default recovery options for QGA on windows. Previously, QGA
on windows will not try to restart service if it is down. This PS
add some default options for the first, second and other failures,
with an interval of 1min. Failure counter will reset after 1 day.

Signed-off-by: shenjiatong <yshxxsjt715@gmail.com>
---
 qga/service-win32.c | 13 +++++++++++++
 1 file changed, 13 insertions(+)

Comments

Konstantin Kostiuk Dec. 30, 2021, 10:28 a.m. UTC | #1
Hi,

On Mon, Nov 15, 2021 at 4:30 AM <yshxxsjt715@gmail.com> wrote:

> From: shenjiatong <yshxxsjt715@gmail.com>
>
> Add default recovery options for QGA on windows. Previously, QGA
> on windows will not try to restart service if it is down. This PS
> add some default options for the first, second and other failures,
> with an interval of 1min. Failure counter will reset after 1 day.
>
> Signed-off-by: shenjiatong <yshxxsjt715@gmail.com>
> ---
>  qga/service-win32.c | 13 +++++++++++++
>  1 file changed, 13 insertions(+)
>
> diff --git a/qga/service-win32.c b/qga/service-win32.c
> index fd434e3f49..0fc93d38c3 100644
> --- a/qga/service-win32.c
> +++ b/qga/service-win32.c
> @@ -105,6 +105,18 @@ int ga_install_service(const char *path, const char
> *logfile,
>      GString *esc;
>      GString *cmdline;
>      SERVICE_DESCRIPTION desc = { (char *)QGA_SERVICE_DESCRIPTION };
> +    SC_ACTION sa[] = {
> +        { SC_ACTION_RESTART, 60000},
> +        { SC_ACTION_RESTART, 60000},
> +        { SC_ACTION_RESTART, 60000}
> +    };
> +    SERVICE_FAILURE_ACTIONS sfa = {
> +        864000, // in seconds,
>

864000 seconds is 10 days, not 1 day.



> +        NULL,
> +        NULL,
> +        sizeof(sa) / sizeof(*sa),
> +        sa
> +    };
>
>      if (GetModuleFileName(NULL, module_fname, MAX_PATH) == 0) {
>          printf_win_error("No full path to service's executable");
> @@ -146,6 +158,7 @@ int ga_install_service(const char *path, const char
> *logfile,
>      }
>
>      ChangeServiceConfig2(service, SERVICE_CONFIG_DESCRIPTION, &desc);
> +    ChangeServiceConfig2(service, SERVICE_CONFIG_FAILURE_ACTIONS, &sfa);
>      fprintf(stderr, "Service was installed successfully.\n");
>      ret = EXIT_SUCCESS;
>      CloseServiceHandle(service);
> --
> 2.25.1
>
>
diff mbox series

Patch

diff --git a/qga/service-win32.c b/qga/service-win32.c
index fd434e3f49..0fc93d38c3 100644
--- a/qga/service-win32.c
+++ b/qga/service-win32.c
@@ -105,6 +105,18 @@  int ga_install_service(const char *path, const char *logfile,
     GString *esc;
     GString *cmdline;
     SERVICE_DESCRIPTION desc = { (char *)QGA_SERVICE_DESCRIPTION };
+    SC_ACTION sa[] = {
+        { SC_ACTION_RESTART, 60000},
+        { SC_ACTION_RESTART, 60000},
+        { SC_ACTION_RESTART, 60000}
+    };
+    SERVICE_FAILURE_ACTIONS sfa = {
+        864000, // in seconds,
+        NULL,
+        NULL,
+        sizeof(sa) / sizeof(*sa),
+        sa
+    };
 
     if (GetModuleFileName(NULL, module_fname, MAX_PATH) == 0) {
         printf_win_error("No full path to service's executable");
@@ -146,6 +158,7 @@  int ga_install_service(const char *path, const char *logfile,
     }
 
     ChangeServiceConfig2(service, SERVICE_CONFIG_DESCRIPTION, &desc);
+    ChangeServiceConfig2(service, SERVICE_CONFIG_FAILURE_ACTIONS, &sfa);
     fprintf(stderr, "Service was installed successfully.\n");
     ret = EXIT_SUCCESS;
     CloseServiceHandle(service);