Friday, January 31, 2020

Re: FreeBSD daemon(8)-like command for OpenBSD

The list might not like this but:
Under your circumstances, I would collect the various ideas in this
thread (including scripting possibly with nohup and/or bash's disown),
the "pgrep || <restart>" idea somebody wrote, and whatever else is
useful from the thread, and just make it work with careful testing of
different failure scenarios. I found that when writing a cron job I had
to test very carefully if different things failed about it, before I
actually got it right. Logs can be done with things like
<commands...> > somefile.log 2>&1
...or variations, and if you then check it occasionally to see that it
is working, learn, move on, things can probably work out.

Then if it is ever rewritten in a way that allows doing the things Ingo
suggests, use his suggestions. In the meantime, isolate it well to
prevent security breaches from affecting other things (ie, considering
what could be affected if/when it is compromised, make sure those other
things are minimized).

Sometimes the cost/benefit realities (or employers) force choices upon us.

--
Please pray for our country(ies) and leaders, at this important time.
More on this and other topics (a simple site w/o sales):
http://lukecall.net (updated 2020-01-23)


On 01-30 21:05, Patrick Kristiansen wrote:
> Hi Ingo,
>
> On Thu, Jan 30, 2020, at 18:35, Ingo Schwarze wrote:
> > Hi Patrick,
> >
> > Patrick Kristiansen wrote on Tue, Jan 28, 2020 at 09:29:20AM +0100:
> >
> > > But another use for daemon(8) is for its ability to detach the child
> > > process from the controlling terminal and furthermore redirect its
> > > stdout/stderr to syslog. Is there some mechanism to do that from the
> > > shell? Perhaps a combination of nohup and starting a background job?
> >
> > That doesn't strike me as a particularly bright idea either.
> >
> > Properly starting up a daemon process requires several steps, often
> > involving unveil(2), pledge(2), chroot(2), prviledge dropping,
> > sometimes fork+exec for privilege separation, and so on. Typically,
> > these steps need to be intermixed in exactly the right order with
> > option parsing, environment parsing, parsing of configuration files
> > and various kinds of initialization.
>
> The process I need to run is written in Clojure and thus runs on the
> Java Virtual Machine. Do you have any suggestions on how to best go
> about making it "daemon-like"? I am not sure that I can call unveil(2),
> pledge(2) and chroot(2) from Clojure without some strange sorcery. I
> read in some blog post, that the way to detach from the controlling
> terminal is by closing stdin, stdout and stderr, which I admittedly
> haven't tried.
>
> > Writing wrappers usually just doesn't work, and it seems doubtful to
> > me whether daemon(8) is up to what is usually needed.
>
> If I were writing my program in C, I could fairly easily call daemon(3),
> I guess, but I am not. I am starting to think that tmux(1) would be the
> easiest way to go about it on OpenBSD... but it feels wrong.
>
> Best regards,
> Patrick
>

No comments:

Post a Comment