From owner-freebsd-questions@freebsd.org Fri Jun 2 10:15:28 2017 Return-Path: Delivered-To: freebsd-questions@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id B7D4ABF42C2 for ; Fri, 2 Jun 2017 10:15:28 +0000 (UTC) (envelope-from jim@mailman-hosting.com) Received: from maurice.jlkmail.com (maurice.jlkmail.com [23.111.151.218]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 8C1AB82307 for ; Fri, 2 Jun 2017 10:15:28 +0000 (UTC) (envelope-from jim@mailman-hosting.com) Received: from maurice.jlkmail.com (localhost [127.0.0.1]) by maurice.jlkmail.com (Postfix) with ESMTP id B9E3919401EF for ; Fri, 2 Jun 2017 06:15:20 -0400 (EDT) Authentication-Results: maurice.jlkmail.com (amavisd-new); dkim=pass (1024-bit key) reason="pass (just generated, assumed good)" header.d=mailman-hosting.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d= mailman-hosting.com; h=content-transfer-encoding:mime-version :x-mailer:content-type:content-type:references:in-reply-to:date :date:to:from:from:subject:subject:message-id; s=dkim; t= 1496398519; x=1497262520; bh=6EN77+t/m0ovMJkUWRq+WoM8OFMIzVT3s2t 0+cVvHko=; b=MJ6hzocZrvlhgWWUTTr3cTYm10+HoQlxB8RqItCaTviIzf5+AT5 G17KdqVtJVn0Nb+BX10uFuVkrf8Gloq1I8ioFXhqmpy+CjqcUrMhEm04SOJlwzaT vFkJ5/iJLsgX1+8QugKCer4KGXNd6qzf6L3+U4P4qIHdJ/2CSQsyucDI= X-Virus-Scanned: Debian amavisd-new at maurice.jlkmail.com X-Spam-Flag: NO X-Spam-Score: 4.296 X-Spam-Level: **** X-Spam-Status: No, score=4.296 tagged_above=-9999 required=6.31 tests=[ALL_TRUSTED=-1, RAZOR2_CF_RANGE_51_100=0.365, RAZOR2_CF_RANGE_E8_51_100=2.43, RAZOR2_CHECK=2.5, URIBL_BLOCKED=0.001] autolearn=no autolearn_force=no Received: from maurice.jlkmail.com ([127.0.0.1]) by maurice.jlkmail.com (maurice.jlkmail.com [127.0.0.1]) (amavisd-new, port 10026) with ESMTP id rKJiCkzeSEch for ; Fri, 2 Jun 2017 06:15:19 -0400 (EDT) Received: from yertle.fios-router.home (static-70-104-198-154.nrflva.fios.verizon.net [70.104.198.154]) by maurice.jlkmail.com (Postfix) with ESMTPSA id B040518806A0; Fri, 2 Jun 2017 06:15:18 -0400 (EDT) Message-ID: <1496398510.1994.2.camel@mailman-hosting.com> Subject: Re: Wrong Handling of pid files (example: fcgiwrap) forces single user mode. Am I correct? From: Jim Ohlstein To: BBlister , freebsd-questions@freebsd.org Date: Fri, 02 Jun 2017 06:15:10 -0400 In-Reply-To: <1496397748172-6189171.post@n6.nabble.com> References: <1496397748172-6189171.post@n6.nabble.com> Content-Type: text/plain; charset="UTF-8" X-Mailer: Evolution 3.18.5.2-0ubuntu3.2 Mime-Version: 1.0 Content-Transfer-Encoding: 8bit X-BeenThere: freebsd-questions@freebsd.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: User questions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 02 Jun 2017 10:15:28 -0000 On Fri, 2017-06-02 at 03:02 -0700, BBlister wrote: > Hello, > > One of my servers (running 10.3-RELEASE-p18) faced a serious problem > out of > the blue. It booted normally multiuser, but after a while it switched > to > single user only, terminating all networking sevices (like SSHD). > This was > done automatically. I was able to access it only via remote serial > port.  > > I found out the culprit: > In my setup I have all the services disable in /etc/rc.conf to speed > up the > booting process, and when the system is up, then a crontab entry for > every > service like "@reboot (delay 120;/usr/local/etc/rc.d/fcgiwrap > onerestart )"   > issues the command to initiate the specific service. > > All the services start from @reboot entries at crontab. But I > discovered > that the init script for fcgiwrap  (and possible other ports that use > similar rc files) has a serious bug, when the command 'onerestart' is > applied. > > If the command line parameter onerestart is used, then this script > first > tries to terminate the process and then restarts it. The problem is > that in > the termination function has this code: > > ... > fcgiwrap_stop() { >         fcgiwrap_pgrp=$(/bin/ps -o ppid= $(cat ${pidfile})) >  ... > > The problem is that if the ${pidfile} does not exist then this > command > returns the PID 1 among other PIDS, like this: > > /bin/ps -o ppid= $(cat /var/run/fcgiwrap/fcgiwrap.pid) > > cat: /var/run/fcgiwrap/fcgiwrap.pid: No such file or directory > 72303 >     1 > 71730 > 72092 >     1 >     1 >     1 >   > and then using a command  kill -TERM -- -${fcgiwrap_pgrp} > terminates all these pids. > > But, PID 1 is the /sbin/init  and according to init(8)  > ...init will signal the original (PID 1) init as follows: > .... > 1            SIGTERM    Go to single-user mode > > > So the fastcgiwrap sends SIGTERM to /sbin/init and then systems > reverts to > single user mode. > > > The fix is to first check the existance of the file, like > > if [ -f  ${pidfile} ] ; then .... > > > and not just 'cat' and 'kill' whatever it returns. Does the same thing happen if you use 'onestart' instead of 'one restart'? > > > Took me a while to debug it and found the solution, and I post it > here to > help future admins... > -- Jim Ohlstein Professional Mailman Hosting https://mailman-hosting.com/