How to smooth restart of a C ++ program without shutting down a running program?

I have a server program that should work full time a day. If I want to change some of its parameters, is there a way, and not close, and then restart?

0
source share
2 answers

There are many ways to do this, including, but almost certainly not limited to:

  • You can maintain the parameters in a separate file so that the program periodically checks this file and updates its internal information.

  • Similar to (1), but you can send some kind of signal to the application to make it immediately re-read the file.

  • You can do (1) or (2), but using shared memory, not a configuration file.

  • Your program may be located on the server at the end of the IPC session so that the client can open a connection for it to provide new parameters. Everything from a simple message queue to a full-blown HTTP server and its related pages.

Of course, all of them, as a rule, need enough work in your program to make it look for new information.

You must take this into account when deciding. To date, the fastest solution for implementation is to simply (cleanly) kill the process at about 11:55 pm, and then immediately restart it. This is simpler because your code probably already has the ability to load information at startup, so it could be a simple single line cron .

Some people talk about laziness as bad, but this is not always the case :-)

+4
source

If the server supports many live connections from clients, the last way you should consider restarting the server process. In addition to reloading the configuration files, inserting a proxy process between clients and the server can be another way.

The proxy process is responsible for 2 things.

a. Maintaining client connections and forwarding packets to the server for processing.

b. Judging by the weather, the current server process (Server A) is alive, and if not, it automatically switches to another server (Server B).

Then you can change the settings using the reboot server without worrying about interrupting clients, as there are always two (or more) servers.

0
source

All Articles