> Hi!
>
> I’m trying to create a minimal rc.d script for a service, and
> discovered that using /usr/sbin/daemon with the -p flag creates a
> pidfile which is not readable by /etc/rc.subr. The pidfile is created
> without a newline, in which case all the service commands stop
> working. That means, running “stop” or “status” prints nothing. If I
> add a newline to the file after the fact, they all start working
> again. Running the service script with debug output, shows the ‘read’
> builtin halting the execution of the script when trying to read the
> pidfile.
This is strange because powerd.pid works without a newline.
I wouldn't have expected it to work at all because you've set
command=yes
I don't know if there's a reason for that, but AFAIK either command or
procname is needed in addition to the pid to verify it's the correct
process - they're matched against the output of ps.
_______________________________________________
freebsd-...@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/freebsd-questions
To unsubscribe, send any mail to "freebsd-questi...@freebsd.org"
> On Wed, 25 May 2016 11:51:31 +0200
> Adam Lindberg wrote:
>
> > Hi!
> >
> > I’m trying to create a minimal rc.d script for a service, and
> > discovered that using /usr/sbin/daemon with the -p flag creates a
> > pidfile which is not readable by /etc/rc.subr. The pidfile is
> > created without a newline, in which case all the service commands
> > stop working. That means, running “stop” or “status” prints
> > nothing. If I add a newline to the file after the fact, they all
> > start working again. Running the service script with debug output,
> > shows the ‘read’ builtin halting the execution of the script when
> > trying to read the pidfile.
>
>
>
> This is strange because powerd.pid works without a newline.
Actually on closer inspection it appears that rc.d/powerd doesn't
define a pidfile - it's getting shutdown based on the command name. I
think you should submit a PR.
I don’t know what powerd is and how it factors into this. :-)
We’re trying to create a service script for our own program (an Erlang VM) and hit this “weird behavior”. We were using command=yes as a way to get some program running in the background with daemon wrapped around it. We were able to reproduce the problem with just this minor rc.d script and running ‘yes’ (the executable) as our service. This problem happens no matter what the command is, as far as we can tell.
Cheers,
Adam
--
Adam Lindberg | Backend Engineer
Wooga GmbH | Saarbrücker Str. 38 | D-10405 Berlin
Place of business: Berlin
Registered at the local court Berlin-Charlottenburg, HRB 117846 B
Managing Directors: Jens Begemann, Philipp Möser, Jan Miczaika
> Hi,
>
> I don’t know what powerd is and how it factors into this. :-)
It's an example of a daemon that generates a pid file without a
newline, and yet "stop" and "status" work.
It turns out that /etc/rc.d/powerd doesn't define pidfile, in which
case rc.subr finds the pid from the output of ps. So it's not a
counter-example and it does appear to be a bug that rc.subr can't cope
with a pid file without a newline.
You could use the same method, but using sed seems safer.
1. Is the sed “hack” okay for now? Are there any risks with modifying the pid file after it’s been created (too early, too late etc.)?
2. If this is a bug in /etc/rc.subr, how do I report it? I’m new to FreeBSD. :-)
Cheers,
Adam
--
Adam Lindberg | Backend Engineer
Wooga GmbH | Saarbrücker Str. 38 | D-10405 Berlin
Place of business: Berlin
Registered at the local court Berlin-Charlottenburg, HRB 117846 B
Managing Directors: Jens Begemann, Philipp Möser, Jan Miczaika
What we observed was that the `read _pid _junk < $_pidfile` line did indeed work on the command line, after sourcing /etc/rc.subr. For some strange reason it seems not to work from inside the service script for us.
Cheers,
Adam
--
Adam Lindberg | Backend Engineer
Wooga GmbH | Saarbrücker Str. 38 | D-10405 Berlin
Place of business: Berlin
Registered at the local court Berlin-Charlottenburg, HRB 117846 B
Managing Directors: Jens Begemann, Philipp Möser, Jan Miczaika
My experience is also that read works in all cases without a newline, except from inside the rc script. That I cannot explain.
Cheers,
Adam
--
Adam Lindberg | Backend Engineer
Wooga GmbH | Saarbrücker Str. 38 | D-10405 Berlin
Place of business: Berlin
Registered at the local court Berlin-Charlottenburg, HRB 117846 B
Managing Directors: Jens Begemann, Philipp Möser, Jan Miczaika