From owner-freebsd-questions@freebsd.org Thu Nov 9 03:05:04 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 04489E67343 for ; Thu, 9 Nov 2017 03:05:04 +0000 (UTC) (envelope-from freebsd@edvax.de) Received: from mailrelay14.qsc.de (mailrelay14.qsc.de [212.99.163.154]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client CN "*.antispameurope.com", Issuer "TeleSec ServerPass Class 2 CA" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 6AD5274857 for ; Thu, 9 Nov 2017 03:05:02 +0000 (UTC) (envelope-from freebsd@edvax.de) Received: from mx01.qsc.de ([213.148.129.14]) by mailrelay14.qsc.de; Thu, 09 Nov 2017 04:04:54 +0100 Received: from r56.edvax.de (port-92-195-23-159.dynamic.qsc.de [92.195.23.159]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by mx01.qsc.de (Postfix) with ESMTPS id 1A87D3CBF9; Thu, 9 Nov 2017 04:04:52 +0100 (CET) Received: from r56.edvax.de (localhost [127.0.0.1]) by r56.edvax.de (8.14.5/8.14.5) with SMTP id vA934qvZ006250; Thu, 9 Nov 2017 04:04:52 +0100 (CET) (envelope-from freebsd@edvax.de) Date: Thu, 9 Nov 2017 04:04:52 +0100 From: Polytropon To: Edgar Pettijohn Cc: Ernie Luzar , Ian Smith , freebsd-questions@freebsd.org Subject: Re: Need help with rc.d script Message-Id: <20171109040452.d3c25fe2.freebsd@edvax.de> In-Reply-To: <20171109013818.GA31584@FreeBSD> References: <20171108021900.W9710@sola.nimnet.asn.au> <20171108043726.N72828@sola.nimnet.asn.au> <5A01F758.1050706@gmail.com> <20171109005843.E72828@sola.nimnet.asn.au> <5A0332D1.90509@gmail.com> <20171109013818.GA31584@FreeBSD> Reply-To: Polytropon Organization: EDVAX X-Mailer: Sylpheed 3.1.1 (GTK+ 2.24.5; i386-portbld-freebsd8.2) Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit X-cloud-security-sender: freebsd@edvax.de X-cloud-security-recipient: freebsd-questions@freebsd.org X-cloud-security-Virusscan: CLEAN X-cloud-security-disclaimer: This E-Mail was scanned by E-Mailservice on mailrelay14.qsc.de with EEF27683430 X-cloud-security-connect: mx01.qsc.de[213.148.129.14], TLS=1, IP=213.148.129.14 X-cloud-security: scantime:.1508 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: Thu, 09 Nov 2017 03:05:04 -0000 On Wed, 8 Nov 2017 19:42:36 -0600, Edgar Pettijohn wrote: > On Wed, Nov 08, 2017 at 11:37:37AM -0500, Ernie Luzar wrote: > > Ian Smith wrote: > > > On Tue, 7 Nov 2017 13:11:36 -0500, Ernie Luzar wrote: > > > > > > > Thanks Ian, > > > > Ending the while loop with "done &" worked. > > > > > > The one with or without the enclosing ( and ) to force a subshell? > > > > > > > When I issue dynip from the command line it runs as a daemon but I have to > > > > use the kill command to stop it. > > > > > > > > This is my rc.d script for dynip script. issuing "service dynip start" works > > > > but "service dynip stop" gives message saying > > > > dynip not running? (Check /var/run/dynip.pid). Well ps ax shows it is running > > > > and I have to use the kill command to stop it. > > > > > > Things to check: > > > > > > . after 'start' does /var/run/dynip.pid exist while it's running?? > > > . if so, does it contain the same PID as 'ps ax' shows for dynip? > > > . does 'ps ax' show a different PID for the subshell, if there is one? > > > . Does /var/run/dynip.pid still exist after running 'stop'? > > > > > > i.e. is the PID needed for kill the same as that in /var/run/dynip.pid? > > > > > > > Here is my rc.d script. What am I missing to populate the dynip.pid file so > > > > "service dynip stop" command will work? > > > > > > > > #!/bin/sh > > > > # > > > > # > > > > # PROVIDE: dynip > > > > # REQUIRE: LOGIN > > > > # KEYWORD: nojail shutdown > > > > # > > > > # Add the following line to /etc/rc.conf to enable dynip: > > > > # > > > > # dynip_enable="YES" > > > > # > > > > > > > > . /etc/rc.subr > > > > name="dynip" > > > > rcvar=dynip_enable > > > > command="/usr/local/sbin/${name}" > > > > pidfile="/var/run/${name}.pid" > > > > load_rc_config ${name} > > > > run_rc_command "$1" > > > > > > I've very little knowledge of the detailed behaviour of the rc system. > > > Let's see how the above questions might inform before speculating .. > > > > > > cheers, Ian > > > > > > > I tested with and without the enclosing ( and ) on the while loop and it > > made no difference. No pidfile exists before the "service dynip start" > > is issued and non exists afterwards. > > > > I don't believe the rc system can write a pidfile for you. Most of if not all > of the services being started by the rc system are written in c and take care > of writing their own pidfile. I suspect you could overcome this by writing a c > program that does so and executes your script every 10 minutes. Or some form of > pgrep perhaps. It's easy to create a pidfile from within the shell script for the shell itself (and its subshells) as well as for an invoked external program: echo $$ > /var/run/${0##*/}.pid myprog -foo -bar baz -meow echo $! > /var/run/myprog.pid The documentation says: $$ Expands to the process ID of the invoked shell. A subshell retains the same value of $ as its parent. $! Expands to the process ID of the most recent background command executed from the current shell. For a pipeline, the process ID is that of the last command in the pipeline. See "man sh", section "Special Parameters", for details -- Polytropon Magdeburg, Germany Happy FreeBSD user since 4.0 Andra moi ennepe, Mousa, ...