From owner-freebsd-questions@freebsd.org Fri Jun 2 10:02: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 B91D5BF3E96 for ; Fri, 2 Jun 2017 10:02:28 +0000 (UTC) (envelope-from bblister@gmail.com) Received: from mwork.nabble.com (mwork.nabble.com [162.253.133.43]) by mx1.freebsd.org (Postfix) with ESMTP id A7AD681E30 for ; Fri, 2 Jun 2017 10:02:28 +0000 (UTC) (envelope-from bblister@gmail.com) Received: from static.162.255.23.37.macminivault.com (unknown [162.255.23.37]) by mwork.nabble.com (Postfix) with ESMTP id 2B42C46A96B84 for ; Fri, 2 Jun 2017 03:02:28 -0700 (MST) Date: Fri, 2 Jun 2017 03:02:28 -0700 (MST) From: BBlister To: freebsd-questions@freebsd.org Message-ID: <1496397748172-6189171.post@n6.nabble.com> Subject: Wrong Handling of pid files (example: fcgiwrap) forces single user mode. Am I correct? MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit 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:02:28 -0000 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. Took me a while to debug it and found the solution, and I post it here to help future admins... -- View this message in context: http://freebsd.1045724.x6.nabble.com/Wrong-Handling-of-pid-files-example-fcgiwrap-forces-single-user-mode-Am-I-correct-tp6189171.html Sent from the freebsd-questions mailing list archive at Nabble.com.