Recompiling and restarting a daemon

0

I am developing a server daemon. I already have a functional version of this server running, but I've now compiled a new version of it. How do I replace the current process with the new one?

Can I just use service [daemon-name] restart? Does this stop the current process and start a new one from the same (now updated) executable? Or does it simply restart the same (now obsolete) binary?

Can I just start the new version and expect it to replace the old one? Or would they run in parallel (not my intention)?

Also (though this may be a different question altogether), I was able to launch the current server as a daemon on my account even though I'm not an administrator. I have tried stopping it, but that requests the root password. Is there a way of doing this without having to involve my network administrator?

Wasabi

Posted 2016-12-07T16:42:32.363

Reputation: 195

Answers

1

The service command is a wrapper used to run scripts in /etc/init.d. If you have written a daemon and want to use the service command, you will need to create a script that accepts start, stop, and restart arguments to manage your daemon, then place it in /etc/init.d. Its ability to start, stop, and restart would be defined within that script.

However, based on your question, it sounds like you don't have root access to the machine in question. In this case, you wouldn't use the service command. Instead, you can write your own wrapper for doing this, or just run it directly from the command line.

To answer your question on how to run the new version, you will first need to stop the one that's running. As long as it's running under your account you will be able to kill it without requiring root access. The easiest way to kill a running process by name is with the pkill command:

pkill -x mydaemon

Once down, just restart your daemon normally. If you want to put this in a script, you can put it in your ~/bin directory, or any other location you normally use for storing scripts and binaries. Your script might be as simple as this:

#!/bin/bash
pidof mydaemon >/dev/null && pkill -x mydaemon
/home/wasabi/bin/mydaemon

virtex

Posted 2016-12-07T16:42:32.363

Reputation: 1 129