How does :kill work?

The :kill method token is kind of cool. Rather than maintaining a pid file or using some grungy invocation of pkill (which almost always is incorrect for services that may run on a system with zones) to find all the processes required to stop your service, you can use the :kill token in your method to simply say "kill off all the processes in this service". Works great with contract type services in startd (but not so much with transient services). You can see smf_method(5) and the developer intro for more details about :kill from the service developer's point of view.

I found out recently that I didn't talk about how the :kill method token works when I talked about general fault isolation in smf(5). It's just so simple that I forgot to mention it. But still, you need to know the key...

Since contracts already take care of grouping the processes for us into services, and extended the appropriate kernel interfaces to allow operations on contracts, we can actually just send a signal to all processes in the contract easily with sigsend(2). So, the contract kill function in svc.startd(1M) is mind-bogglingly simple. All you need is a contract id.

int
contract_kill(ctid_t ctid, int sig, const char \*fmri)
{
        if (sigsend(P_CTID, ctid, sig) == -1 && errno != ESRCH) {
                log_error(LOG_WARNING,
                    "%s: Could not signal all contract members: %s\\n", fmri,
                    strerror(errno));
                return (-1);
        }

        return (0);
}

Nice, huh? Having contracts as a well-supported kernel feature makes some previously impossible things now possible, and generally makes the life of the restarter author easier. This is, to me, one of the truly significant benefits of having a kernel that evolves in concert with its userland tools.

Technorati Tags: , , and .

Comments:

How does :kill method work for transient services, especially the ones which do an ifconfig(1M)? Are you expected to write stop methods which "down" the interface?

Posted by PJ on August 25, 2005 at 11:46 PM PDT #

I think you're actually referring to the "stop" method. :kill is a token you can specify for the stop method to request specific action. For a service where you want a different action, such as unplumbing an interface when the service is disabled, you'd write a method script which did what you wanted and invoke it as your stop method instead of :kill. Essentially, :kill makes no real sense for transient services. As startd does no tracking of processes for transient services, there's nothing for it to kill. :kill is a no-op for transient services.

Posted by Liane Praza on August 26, 2005 at 07:36 AM PDT #

Tomcat services are depolyed on sites I work for. These services sometimes hang, that is to say, no response to the web requests but the tomcat processes exist. I want to know whether smf(5) could detect this fault(service hangs but process exists) as service fail and to restart automatically it. If yes, how to reflect this in the manifest? If no, when will smf(5) handle this circumstance or no such a schedual at all?

Posted by vincetang on December 19, 2005 at 11:26 PM PST #

Post a Comment:
  • HTML Syntax: NOT allowed
About

Liane Praza

Search

Categories
Archives
« May 2015
SunMonTueWedThuFriSat
     
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
      
Today