> On Nov 19, 2016, at 12:57 PM, Vanush Misha Paturyan <[email protected]> wrote: > > On Sat, 19 Nov 2016 at 19:46 The Lee-Man <[email protected] > <mailto:[email protected]>> wrote: > In this wonderful new world of systemd, I have an issue with stopping the > iscsid service when the daemon has died or been killed. > > My setup: > * I have an iscsid.socket unit file, which is enabled and started > * I have an iscsid.service unit file, which controls the iscsid daemon. This > is disabled and not started > > Normally, if I run a command like "iscsiadm -m discovery -t st -p > SOME-TARGET", systemd notices that iscsiadm is trying to talk to iscsid > through the socket, and it starts up iscsid. This is the cool part (IMHO) of > systemd socket activation. > > When I want to stop iscsid, I can just tell systemctl to do it via "systemctl > stop iscsid", and it runs the "ExecStop=" command in the service unit file, > which is "iscsiadm -k 0 2" before terminating the daemon process(es). > > [NOTE: the "2" here in this command actually does nothing and is ignored, but > I copied this from someplace else long ago, and the "2" was present there.] > > It is of importance, in this case, that the ExecStop command actually sends > an IPC message to the daemon (iscsid) requesting it to cleanly shut itself > down. Herein lies the rub. > > All of this works great until the daemon happens not to be running. You can > simulate this with "kill -TERM $(pidof iscsid)" when the daemon is running. > Now you are in a situation where systemd started the service and knows it is > now not running, so it seems to send the ExecStop command to cleanly shut it > down. This command hangs! It seems to be stuck in an infinite loop trying to > send the shutdown command to the daemon, waiting for it to timeout, then > trying again. The daemon starts up, sees an IPC error, and exits. > > While this clearly seems like a systemd issue, I have found a workaround that > looks clean. Well, as clean as the shutdown command is, anyway. This involves: > > How is this systemd's issue? From what you wrote above, it looks like isciadm > -k is trying to stop iscsid daemon without even checking if iscsid daemon is > running.
Systemd claims to be in charge of the service. Systemd knows whether or not the service is running. There should be no need to stop the service, in this case, since systemd knows it already is not running. > > * modifying the "iscsiadm -k" command to require passing in the PID of the > daemon to be killed > > is it possible to run more than one daemon on the same server? Maybe it will > be enough just to modify iscsiadm to check first if daemon is running before > trying to stop it? No, right now there is only one iscsid daemon, normally. Systemd has no concept of multiple daemons for iscsi. Normally it is the job of iscsiadm to send messages for this kind of thing to iscsid. Systemd normally starts iscsid if it is not running, so iscsiadm doesn’t normally need to worry about that. Plus, if systemd is not running iscsiadm has a configuration option to start iscsid manually, if needed. This handles every other case of iscsiadm talking to iscsid except this one. I have prototyped a patch that has iscsiadm check to see if iscsid is running before trying to kill it. It uses “kill(0)” but requires the caller to pass in the PID of iscsid. If you can think of a better and simpler way for iscsiadm to detect if iscsid is running, I’m open for a different approach. Perhaps I should post my patches? > > Misha > -- You received this message because you are subscribed to the Google Groups "open-iscsi" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To post to this group, send email to [email protected]. Visit this group at https://groups.google.com/group/open-iscsi. For more options, visit https://groups.google.com/d/optout.
