-
Notifications
You must be signed in to change notification settings - Fork 187
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
Conversation
misc/systemd/cf-serverd.socket
Outdated
Before=cf-serverd.service | ||
|
||
[Socket] | ||
ListenStream = 5309 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ListenStream = 5309 | |
ListenStream = 5308 |
cf-serverd/cf-serverd-functions.c
Outdated
/* 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"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Log(LOG_LEVEL_ERR, "Doing a Graceful restart"); | |
Log(LOG_LEVEL_INFO, "Doing a graceful restart"); |
cf-serverd/cf-serverd-functions.c
Outdated
* If there is no systemd make sure alternative init restarts us. */ | ||
static void GracefulStop() | ||
{ | ||
Log(LOG_LEVEL_ERR, "Stopping gracefully"); |
There was a problem hiding this comment.
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.
done |
812afbe
to
d7759ec
Compare
remove a 2s sleep on recent systemd |
d7759ec
to
f03caf3
Compare
Rebased now that #4499 is merged |
Please rebase this again when #4536 is merged. |
Done, rebase was not needed |
There was a problem hiding this 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
f03caf3
to
f9a3a39
Compare
Better ? |
There was a problem hiding this 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.
cf-serverd/cf-serverd-functions.c
Outdated
if (optarg == NULL) | ||
{ | ||
GRACEFUL = 60; | ||
} else |
There was a problem hiding this comment.
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
cf-serverd/cf-serverd-functions.c
Outdated
@@ -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. |
There was a problem hiding this comment.
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
cf-serverd/cf-serverd-functions.c
Outdated
/* 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. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
handling
cf-serverd/cf-serverd-functions.c
Outdated
return; | ||
} | ||
#ifdef HAVE_SD_NOTIFY_BARRIER | ||
int anything = 1; |
There was a problem hiding this comment.
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
.
cf-serverd/cf-serverd-functions.c
Outdated
} | ||
/* 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) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Missing space after if
cf-serverd/cf-serverd-functions.c
Outdated
YieldCurrentLock(thislock); | ||
int threads_left; | ||
|
||
if(ReloadConfigRequested() && GRACEFUL != 0) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same here
f9a3a39
to
199b7db
Compare
199b7db
to
87e91b1
Compare
cf-serverd/cf-serverd-functions.c
Outdated
#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. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
* 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. |
There was a problem hiding this 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.
87e91b1
to
e9586fe
Compare
indeed :) |
|
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
e9586fe
to
9ccc646
Compare
done |
@cf-bottom jenkins, please |
There was a problem hiding this 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.
Sure, I triggered a build: Jenkins: https://ci.cfengine.com/job/pr-pipeline/6254/ Packages: http://buildcache.cfengine.com/packages/testing-pr/jenkins-pr-pipeline-6254/ |
This PR is base on the systemd one #4499 because it uses the same autotools option for systemd.