ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
I have written a daemon server. I would like to add the ability for the daemon to update itself. That is, it should be able to download the latest version of the code (when it receives a signal from a client) and then restart itself. I am stuck on getting the daemon to restart itself. The problem is killing the old daemon without killing the process that is starting the new daemon. In my latest attempt, the daemon that is updating itself runs a program in a subshell (using system) that starts a restarter daemon that runs the original daemon (again using system) with the restart command option. With the restart option, the new version of the daemon sends a terminate signal to the old version. Obviously, when I run the original daemon manually with the restart option, it restarts reliably. I figured that issuing the same restart command from a daemon would adequately isolate the process doing the restarting from the program being restarted. Using ps, I can see that the daemon does actually restart. However, the client locks. In fact, a few times, the OS locked and I had to reset. Debugging is very difficult because I cannot print from a daemon. Am I doing something obviously wrong? Is there a better way to solve this problem?
I may not have been clear that I intend for the update to be triggered by the user from the client. The client would check for updates of its own code and send a message to the servers to check for updates of their code. The main problem with using a cron job is that the client might update itself in a manner that requires the updated server code, but the servers would remain unupdated until the cron job runs. The only way to keep the client and server code synchronized would be to trigger updates to the client code from cron as well -- and to synchronize cron on multiple platforms. It's not out of the question, but there would be a period when updates could easily get out of sync. The same problems occur with the package manager. But I completely disagree that what I have implemented now is "a bit convoluted". It's absurdly convoluted. It's way beyond "a bit".
I thought about having a separate update program. The problem with simple scripts is that users do not operate on the platforms that run the servers, so getting the scripts to run would be problematic. The update program could be a daemon also that communicates with the same client. It would be responsible for downloading the new code and restarting the other daemons. The problem with this version of the idea is that I don't know what to do if the update daemon itself needs to be updated, though perhaps it would be simple enough that the need for an update would be unlikely.
The thought that I had last night when I should have been sleeping is that the servers will check for new code, download it if they find an update -- as they do now -- but then they will issue a reboot command. The servers are started by init.d, so the new code will run when the system reboots. This solution is inelegant, but I think it will work.
The "client" sets a flag (for example, writes a file that says "Hey! Update!"). The cron script looks for the flag, and takes the appropriate action(s). Including rebooting the server (why not, if it's the most direct way to insure everything is set to a "known good state"?)
I don't think your logic is ideal, a client/server architecture indicates that there may be more than one client so what would happen in this case ? How about having the server update itself via cron and include a version check in the client to trigger an update if it's version doesn't match the server version ?
I like your suggestion. I'm not sure that I want the updates to be fully automatic (some users prefer to stick with obsolete code that works rather than update and risk failure), but I will consider this approach. In the meantime, my reboot idea is working. Thanks for all the suggestions.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.