Archived

This forum has been archived. Please start a new discussion on GitHub.

stop the daemon

Hi,

what is the recommended way to stop an Ice daemon (on Linux) ?

If the answer is to send the SIGTERM signal then to which process the signal should be sent ?
To the first one ? To the third ? To all ?
Especially taking into account that my application also issues several threads.
The output of 'ps x' looks like this:

2765 pts/1 S 0:00 ./my_daemon --daemon
2766 pts/1 S 0:00 ./my_daemon --daemon
2767 pts/1 S 0:00 ./my_daemon --daemon
2768 pts/1 S 0:00 ./my_daemon --daemon
2769 pts/1 S 0:00 ./my_daemon --daemon
... ... ...

Thank you,
Nikolai (nsns)

Comments

  • benoit
    benoit Rennes, France
    Sorry for the late answer! I recommend to start your process with --Ice.PrintProcessId in addition to --daemon. This will cause the process id of the daemon to be printed on the standard output. You can store the pid in a file and later use it to shutdown the daemon with kill -SIGTERM <pid>.

    Benoit.
  • benoit
    benoit Rennes, France
    I should also mention that you should use kill -SIGTERM -<pid> (note the minus sign in front of the pid!) if you're using a Linux version without NPTL (to send the signal to the process group). For other Unix or Linux with NPTL this shouldn't be necessary.

    Hope this helps!

    Benoit.
  • I'd like to continue this thread. Sorry for the delay, I was on vacations.
    Your advice to use '-Ice.PrintProcessId ' does not help.
    It prints the pid of the top process and the top process ignores SIGTERM.
    Experimentally I found that SIGTERM should be sent to the 3rd process,
    e.g. if 'ps x' looks like this :

    2765 pts/1 S 0:00 ./my_daemon --daemon
    2766 pts/1 S 0:00 ./my_daemon --daemon
    2767 pts/1 S 0:00 ./my_daemon --daemon
    2768 pts/1 S 0:00 ./my_daemon --daemon
    2769 pts/1 S 0:00 ./my_daemon --daemon
    ... ... ...

    The --Ice.PrintProcessId prints
    2765
    but I have to do
    kill 2767
    to gracefully finish my application.

    Is there any general way to find the process id to which I should send SIGTERM ?

    Thank you, Nikolai
  • benoit
    benoit Rennes, France
    Hi Nikolai,

    Ice.PrintProcessId should work. I just tried on Linux Redhat 9 with Ice 1.5.1 with the icepacknode process and it worked fine.

    For example, without NPTL:
       $ cd Ice-1.5.1/demo/IcePack/simple
       $  icepacknode --Ice.Config=config --Ice.PrintProcessId --daemon --nochdir --noclose --nowarn
       9822
       $ kill -SIGTERM -9822
    

    With NPTL:
       $ cd Ice-1.5.1/demo/IcePack/simple
       $  icepacknode --Ice.Config=config --Ice.PrintProcessId --daemon --nochdir --noclose --nowarn
       9822
       $ kill -SIGTERM 9822
    

    Which Ice distribution do you use and on which Linux distribution? Could you try with the latest Ice if you're not already using it?

    Thanks!

    Benoit.
  • Hi,

    I reinstalled Ice and now it is 1.5.1.
    Used Linux kernels are 2.4.18 and 2.4.20.
    The problem is exactly the same.
    After invoking of my application with

    > a.out --daemon --Ice.PrintProcessId
    8765
    > ps x
    ...
    8765 ? S 0:00 a.out --daemon --Ice.PrintProcessId
    8766 ? S 0:00 a.out --daemon --Ice.PrintProcessId
    8767 ? S 0:00 a.out --daemon --Ice.PrintProcessId
    8768 ? S 0:00 a.out --daemon --Ice.PrintProcessId
    8769 ? S 0:00 a.out --daemon --Ice.PrintProcessId

    The command 'kill -TERM 8765' is ignored.
    The command 'kill -TERM 8767' terminates the daemon.

    Below is my simplified code,
    Nikolai

    //////////////////////////////////////////////////////////////////////////////////////////////
    // START OF THE CODE
    // file my.ice
    module MYAPPL {
    interface MY {
    void f();
    };
    };

    // file app.cc

    #include <Ice/Ice.h>
    #include <Ice/Service.h>
    #include "my.h"
    #include <sys/types.h>
    #include <unistd.h>
    #include <string.h>
    #include <netdb.h>
    #include <iostream>
    #include <string>
    using namespace std;

    //
    class MY_impl : public MYAPPL::MY {
    public:
    virtual void f(const Ice::Current &) {}
    };

    //
    class MYService : virtual public Ice::Service {
    public:

    protected:

    // from Ice::Service
    virtual bool start(int argc, char * argv[]);

    private: // functions

    static std::string get_FQDN();

    private: // data

    Ice::ObjectAdapterPtr adapter_;
    };


    //
    std::string MYService::get_FQDN()
    {
    char host[257];
    host[256] = 0;
    if ( gethostname(host, 256) != 0 ) {
    string msg = "get_FQDN() error:\n";
    msg += strerror(errno);
    throw msg;
    }

    struct hostent * he = gethostbyname(host);
    if ( he == 0 ) {
    string msg = "get_FQDN() error:\n";
    msg += hstrerror(h_errno);
    throw msg;
    }
    return he->h_name;
    }

    //
    bool MYService::start(int argc, char * argv[])
    {
    try {

    // Create and Activate the Servant

    Ice::CommunicatorPtr ic = communicator();

    string host = get_FQDN();
    string port = "11111";
    string my_addr = string("tcp -h ") + host + " -p " + port;
    adapter_ = ic->createObjectAdapterWithEndpoints("MYAdapter", my_addr);

    Ice::ObjectPtr object = new MY_impl;
    adapter_->add(object, Ice::stringToIdentity("MY"));

    cout << "MY server started on " << host << ". pid " << getpid() << endl;
    }
    catch ( const std::string & msg ) {
    cout << msg << endl;
    return false;
    }

    adapter_->activate();
    return true;
    }

    //
    int main(int argc, char *argv[])
    {
    MYService svc;
    return svc.main(argc, argv);
    }

    // END OF THE CODE
  • benoit
    benoit Rennes, France
    Yes, kill -SIGTERM 8765 won't work if you're using LinuxThreads. Did you try kill -SIGTERM -8765 (note the minus sign in front of the pid) as suggested in my previous posts?

    If you're using the old LinuxThreads thread library (you probably use it with the 2.4.18 kernel), you must put the minus sign in front of the pid otherwise I would expect the behavior you're seeing.

    Benoit.