Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CFE-3581: Graceful restart option #4503

Merged
merged 1 commit into from
Mar 25, 2021

Conversation

peckpeck
Copy link
Contributor

This PR is base on the systemd one #4499 because it uses the same autotools option for systemd.

@peckpeck
Copy link
Contributor Author

Before=cf-serverd.service

[Socket]
ListenStream = 5309
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
ListenStream = 5309
ListenStream = 5308

/* if we have a reload config requested but not yet processed
* it means we still have clients, let's do a graceful restart */
if(ReloadConfigRequested() && GRACEFUL != 0) {
Log(LOG_LEVEL_ERR, "Doing a Graceful restart");
Copy link
Contributor

@amousset amousset Feb 17, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Log(LOG_LEVEL_ERR, "Doing a Graceful restart");
Log(LOG_LEVEL_INFO, "Doing a graceful restart");

* If there is no systemd make sure alternative init restarts us. */
static void GracefulStop()
{
Log(LOG_LEVEL_ERR, "Stopping gracefully");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

probably not LOG_LEVEL_ERR, we should have one info log and the rest in verbose or debug.

@peckpeck
Copy link
Contributor Author

done

@peckpeck peckpeck force-pushed the graceful_restart_option branch from 812afbe to d7759ec Compare March 10, 2021 09:58
@peckpeck
Copy link
Contributor Author

peckpeck commented Mar 10, 2021

remove a 2s sleep on recent systemd

@peckpeck peckpeck force-pushed the graceful_restart_option branch from d7759ec to f03caf3 Compare March 10, 2021 15:01
@peckpeck
Copy link
Contributor Author

Rebased now that #4499 is merged

@olehermanse olehermanse changed the title Graceful restart option CFE-3581: Graceful restart option Mar 11, 2021
@vpodzime
Copy link
Contributor

Please rebase this again when #4536 is merged.

@vpodzime vpodzime self-requested a review March 11, 2021 10:04
@peckpeck
Copy link
Contributor Author

Done, rebase was not needed

Copy link
Contributor

@vpodzime vpodzime left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please squash the commits and add an explanation of what is being done, how and why to the commit message. Also please go through the code and make sure it follows the coding style and guidelines from CONTRIBUTING.md

@peckpeck peckpeck force-pushed the graceful_restart_option branch from f03caf3 to f9a3a39 Compare March 16, 2021 15:26
@peckpeck
Copy link
Contributor Author

Better ?

Copy link
Contributor

@vpodzime vpodzime left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! Just a few nitpicks and one question.

if (optarg == NULL)
{
GRACEFUL = 60;
} else
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

else should be on a separate line

@@ -540,14 +557,99 @@ static void PrepareServer(int sd)
WritePID("cf-serverd.pid"); /* Arranges for cleanup() to tidy it away */
}

/* Graceful Stop
* This runs a new main process that will die and that init can restart (as systemd can do).
* This this can prevent systemd from kill us it there is a problem.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

killing us if there is a problem

/* Graceful Stop
* This runs a new main process that will die and that init can restart (as systemd can do).
* This this can prevent systemd from kill us it there is a problem.
* But this makes it possible to finish kandling connections while systemd tries to restart us.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

handling

return;
}
#ifdef HAVE_SD_NOTIFY_BARRIER
int anything = 1;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This could be just an unsigned char.

}
/* if we have a reload config requested but not yet processed
* it means we still have clients, let's do a graceful restart */
if(ReloadConfigRequested() && GRACEFUL != 0)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing space after if

YieldCurrentLock(thislock);
int threads_left;

if(ReloadConfigRequested() && GRACEFUL != 0)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same here

cf-serverd/cf-serverd-functions.c Show resolved Hide resolved
@peckpeck peckpeck force-pushed the graceful_restart_option branch from f9a3a39 to 199b7db Compare March 17, 2021 10:13
@vpodzime vpodzime self-requested a review March 18, 2021 08:35
@peckpeck peckpeck force-pushed the graceful_restart_option branch from 199b7db to 87e91b1 Compare March 18, 2021 10:36
#if HAVE_SYSTEMD_SD_DAEMON_H
/* Graceful Stop
* This runs a new main process that will die and that init can restart (as systemd can do).
* This this can prevent systemd from kill us if there is a problem.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
* This this can prevent systemd from kill us if there is a problem.
* This can prevent systemd from killing us if there is a problem.

Copy link
Contributor

@vpodzime vpodzime left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice! Thanks! Please change the commit message title to Add a graceful detach option that can be used with systemd. Also please change the path in the commit message to /var/cfengine/bin/cf-serverd.

@peckpeck peckpeck force-pushed the graceful_restart_option branch from 87e91b1 to e9586fe Compare March 19, 2021 08:27
@peckpeck
Copy link
Contributor Author

indeed :)

@vpodzime
Copy link
Contributor

ExecStart=/var/cfengine/bin/cf-serverd --graceful-detach=600 --no-fork
Should be 60

When cf-serverd receives a SIGHUP, instead of reloading it detaches
itself from init (systemd) and continues to process existing
connections. At the same time systemd detects that the process has died
and restarts a new one to accept new connections.

It works by double forking (detach from parent) and by signaling to
systemd that the new process is now the main process. And then the new
process suddenly dies, to make systemd restart it.

This way you can implement a graceful restart if you have a unit with
following options :
ExecStart=/var/cfengine/bin/cf-serverd --graceful-detach=60 --no-fork
ExecReload=/bin/kill -HUP $MAINPID
Restart=always
NotifyAccess=main
KillMode=process

Ticket: CFE-3581
@peckpeck peckpeck force-pushed the graceful_restart_option branch from e9586fe to 9ccc646 Compare March 22, 2021 10:29
@peckpeck
Copy link
Contributor Author

done

@vpodzime
Copy link
Contributor

@cf-bottom jenkins, please

Copy link
Contributor

@vpodzime vpodzime left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great to me.

@cf-bottom
Copy link

@vpodzime
Copy link
Contributor

Build Status

Clouds... Retry: Build Status

@vpodzime vpodzime merged commit 9914e9c into cfengine:master Mar 25, 2021
@vpodzime
Copy link
Contributor

Clouds... Retry: Build Status

Only non-related failures. 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

5 participants