Re: rc script problem - pidfile not being recognised

2015-09-14 Thread RW via freebsd-ports
On Sat, 12 Sep 2015 08:02:11 -0700 (PDT)
Roger Marquis wrote:

> RW via freebsd-ports wrote:
> > You'd rather an rc script fails at run-time and shuts down the wrong
> > daemon than fail when the script is being developed?
> 
> It's not so much where the script fails than that it fails in the
> first place.  Neither a pidfile nor a command_interpreter needs to be
> required for an rc scripts to work.  These are nice features but
> making them mandatory is at best a sort of premature optimization.

It's not mandatory; you only need to define it if you want to be
able to stop an interpreted  daemon using the default method.

If you have some other way of shutting down a daemon without knowing its
name and PID  then you can just supply a stop function to do it.



> The freebsd rc script environment is already far too OS-specific and
> un-editable, often containing no readable shell code at all.

That's not been my experience. Occasionally it might a bit harder to
customise the script, but that's outweighed by all the times an override
can be made cleanly in rc.conf, without having to modify an installed
script. I've found that practically all customizations can be done
through rc.conf, and the rest usually involve editing an existing
stop/start function.

And rcng make it easy to keep multiple copies of the same rc file, you
can keep separate config and switch between them from rc.conf.


> What if
> your interpreter changes from say python2.7 to python for example?
> Does that mean you have to reinstall all the associated packages or
> edit their rc scripts?

If the interpreter changes from python2.7 to python, you'd have to
change the shebangs anyway.

 
___
freebsd-ports@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/freebsd-ports
To unsubscribe, send any mail to "freebsd-ports-unsubscr...@freebsd.org"


Re: rc script problem - pidfile not being recognised

2015-09-14 Thread Jim Trigg

On 2015-09-14 13:32, RW via freebsd-ports wrote:

On Sat, 12 Sep 2015 08:02:11 -0700 (PDT)
Roger Marquis wrote:


RW via freebsd-ports wrote:
> You'd rather an rc script fails at run-time and shuts down the wrong
> daemon than fail when the script is being developed?

It's not so much where the script fails than that it fails in the
first place.  Neither a pidfile nor a command_interpreter needs to be
required for an rc scripts to work.  These are nice features but
making them mandatory is at best a sort of premature optimization.


It's not mandatory; you only need to define it if you want to be
able to stop an interpreted  daemon using the default method.

If you have some other way of shutting down a daemon without knowing 
its

name and PID  then you can just supply a stop function to do it.


One easy fix would be to have stoprc first check the entire process 
command and then shift it by one and check again... Then it would work 
for both binaries and scripts without a special variable for scripts.


Jim Trigg
___
freebsd-ports@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/freebsd-ports
To unsubscribe, send any mail to "freebsd-ports-unsubscr...@freebsd.org"


Re: rc script problem - pidfile not being recognised

2015-09-12 Thread RW via freebsd-ports
On Sat, 12 Sep 2015 01:46:23 +0200
Michelle Sullivan wrote:

> Roger Marquis wrote:
> > RW via freebsd-ports wrote:
> >> It needs both. It won't use just the pid file because the pid
> >> might have been reassigned to another process if the original
> >> daemon died without deleting its pid file.
> >
> > Why would this rc script *require* a command_interpreter variable
> > to use the pidfile variable?  I'm curious because this violates
> > KIS, the principle of least surprise and few rc scripts seem to
> > have this variable defined.
> >
> > Using command_interpreter is good to be sure, for for the reason
> > listed, but rc scripts should not fail if it is undefined.
> 
> +1 to that.

You'd rather an rc script fails at run-time and shuts down the wrong
daemon than fail when the script is being developed?
___
freebsd-ports@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/freebsd-ports
To unsubscribe, send any mail to "freebsd-ports-unsubscr...@freebsd.org"


Re: rc script problem - pidfile not being recognised

2015-09-12 Thread Roger Marquis

RW via freebsd-ports wrote:

You'd rather an rc script fails at run-time and shuts down the wrong
daemon than fail when the script is being developed?


It's not so much where the script fails than that it fails in the first
place.  Neither a pidfile nor a command_interpreter needs to be required
for an rc scripts to work.  These are nice features but making them
mandatory is at best a sort of premature optimization.

The freebsd rc script environment is already far too OS-specific and
un-editable, often containing no readable shell code at all.  What if
your interpreter changes from say python2.7 to python for example?  Does
that mean you have to reinstall all the associated packages or edit their
rc scripts?

Neither shouldn you have to parse who knows how many hundred of lines of
shell code included by /etc/rc.subr or rewrite an rc script from scratch
to make a simple change.  We appreciate the features this subsystem
provides and the work devs have put into it but not when it's made
mandatory.  The value of KIS needs to be emphasized here.

IMO,
Roger Marquis
___
freebsd-ports@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/freebsd-ports
To unsubscribe, send any mail to "freebsd-ports-unsubscr...@freebsd.org"


Re: rc script problem - pidfile not being recognised

2015-09-11 Thread Roger Marquis

RW via freebsd-ports wrote:

It needs both. It won't use just the pid file because the pid
might have been reassigned to another process if the original daemon
died without deleting its pid file.


Why would this rc script *require* a command_interpreter variable to use
the pidfile variable?  I'm curious because this violates KIS, the
principle of least surprise and few rc scripts seem to have this variable
defined.

Using command_interpreter is good to be sure, for for the reason listed,
but rc scripts should not fail if it is undefined.

IMO,
Roger Marquis
___
freebsd-ports@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/freebsd-ports
To unsubscribe, send any mail to "freebsd-ports-unsubscr...@freebsd.org"


Re: rc script problem - pidfile not being recognised

2015-09-11 Thread RW via freebsd-ports
On Fri, 11 Sep 2015 16:55:58 +0100 (BST)
Kevin Golding wrote:

> - Original Message -
> > From: "RW via freebsd-ports" 
> > Sent: Friday, 11 September, 2015 4:18:50 PM
> > 

> > did you set the command_interpreter variable, probably you need
> > 
> > command_interpreter=/usr/local/bin/python2.7
> 
> And that seems to have fixed it - thank you.
> 
> I still think there's an error in reading the pidfile since I think
> this means I'm using the process name rather than the pid but it does
> the job so I won't worry too much for today. 

It needs both. It won't use just the pid file because the pid
might have been reassigned to another process if the original daemon
died without deleting its pid file. 
___
freebsd-ports@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/freebsd-ports
To unsubscribe, send any mail to "freebsd-ports-unsubscr...@freebsd.org"


Re: rc script problem - pidfile not being recognised

2015-09-11 Thread RW via freebsd-ports
On Fri, 11 Sep 2015 09:46:31 -0700 (PDT)
Roger Marquis wrote:

> RW via freebsd-ports wrote:
> > It needs both. It won't use just the pid file because the pid
> > might have been reassigned to another process if the original daemon
> > died without deleting its pid file.
> 
> Why would this rc script *require* a command_interpreter variable to
> use the pidfile variable?  I'm curious because this violates KIS, the
> principle of least surprise and few rc scripts seem to have this
> variable defined.
> 
> Using command_interpreter is good to be sure, for for the reason
> listed, but rc scripts should not fail if it is undefined.

IIRC  the name is always checked. When an interpreted script is run
using a shebang the command in the output of ps doesn't match the
command used to start the script, so command_interpreter is needed to
get a match.
___
freebsd-ports@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/freebsd-ports
To unsubscribe, send any mail to "freebsd-ports-unsubscr...@freebsd.org"


Re: rc script problem - pidfile not being recognised

2015-09-11 Thread Michelle Sullivan
Kevin Golding wrote:
> I've been trying to work on a new port and it's my first that uses an rc 
> script so I've been expecting a few bumps, but there's one thing I can't seem 
> to fix and it's a blocker. I can't stop the daemon!
>
> It dopes create a pidfile so I have the following line in my script:
>
> pidfile="/var/run/${name}.pid"
>
> Alas...
>
> # service fuglu stop
> fuglu not running? (check /var/run/fuglu.pid).
> # cat /var/run/fuglu.pid
> 24013
>
> I don't get it. It is the right process ID:
>
> # ps -waux | grep fuglu
> nobody   24013   0.0  0.5 139532  37372  -  I 3:57PM 0:01.03 
> /usr/local/bin/python2.7 /usr/local/bin/fuglu --pidfile /var/r
> root 26179   0.0  0.0  18824   1976  0  S+4:30PM 0:00.00 grep 
> fuglu
>   

I'd take a bet as it's running as a user the process is being called to
shutdown and there is some permissions issue on the PID file (I see the
same thing with bucardo when running bucardo as non root)

Regards,

Michelle

-- 
Michelle Sullivan
http://www.mhix.org/

___
freebsd-ports@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/freebsd-ports
To unsubscribe, send any mail to "freebsd-ports-unsubscr...@freebsd.org"


Re: rc script problem - pidfile not being recognised

2015-09-11 Thread Michelle Sullivan
Roger Marquis wrote:
> RW via freebsd-ports wrote:
>> It needs both. It won't use just the pid file because the pid
>> might have been reassigned to another process if the original daemon
>> died without deleting its pid file.
>
> Why would this rc script *require* a command_interpreter variable to use
> the pidfile variable?  I'm curious because this violates KIS, the
> principle of least surprise and few rc scripts seem to have this variable
> defined.
>
> Using command_interpreter is good to be sure, for for the reason listed,
> but rc scripts should not fail if it is undefined.

+1 to that.

-- 
Michelle Sullivan
http://www.mhix.org/

___
freebsd-ports@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/freebsd-ports
To unsubscribe, send any mail to "freebsd-ports-unsubscr...@freebsd.org"


rc script problem - pidfile not being recognised

2015-09-11 Thread Kevin Golding
I've been trying to work on a new port and it's my first that uses an rc script 
so I've been expecting a few bumps, but there's one thing I can't seem to fix 
and it's a blocker. I can't stop the daemon!

It dopes create a pidfile so I have the following line in my script:

pidfile="/var/run/${name}.pid"

Alas...

# service fuglu stop
fuglu not running? (check /var/run/fuglu.pid).
# cat /var/run/fuglu.pid
24013

I don't get it. It is the right process ID:

# ps -waux | grep fuglu
nobody   24013   0.0  0.5 139532  37372  -  I 3:57PM 0:01.03 
/usr/local/bin/python2.7 /usr/local/bin/fuglu --pidfile /var/r
root 26179   0.0  0.0  18824   1976  0  S+4:30PM 0:00.00 grep fuglu

I'm at a loss as to what to try, I feel I'm missing something blindingly 
obvious but it's a mystery to me so if anyone can wave the big red arrow at my 
mistake I'd be a happy chappy!

Full fuglu.in below:

#!/bin/sh

# $FreeBSD$
#
# PROVIDE: fuglu
# REQUIRE: LOGIN
# KEYWORD: shutdown
#
# Add these lines to /etc/rc.conf.local or /etc/rc.conf
# to enable this service:
#
# fuglu_enable (bool):  Set to NO by default.
#   Set it to YES to enable fuglu.

. /etc/rc.subr

name="fuglu"
rcvar=fuglu_enable

load_rc_config $name
: ${fuglu_enable:=no}

command=%%PREFIX%%/bin/${name}
pidfile="/var/run/${name}.pid"

run_rc_command "$1"
___
freebsd-ports@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/freebsd-ports
To unsubscribe, send any mail to "freebsd-ports-unsubscr...@freebsd.org"


Re: rc script problem - pidfile not being recognised

2015-09-11 Thread Chris H
On Fri, 11 Sep 2015 15:42:18 +0100 (BST) Kevin Golding  wrote

> I've been trying to work on a new port and it's my first that uses an rc
> script so I've been expecting a few bumps, but there's one thing I can't seem
> to fix and it's a blocker. I can't stop the daemon! 
>
> It dopes create a pidfile so I have the following line in my script:
> 
> pidfile="/var/run/${name}.pid"
> 
> Alas...
> 
> # service fuglu stop
> fuglu not running? (check /var/run/fuglu.pid).
> # cat /var/run/fuglu.pid
> 24013
> 
> I don't get it. It is the right process ID:
> 
> # ps -waux | grep fuglu
> nobody   24013   0.0  0.5 139532  37372  -  I 3:57PM 0:01.03
> /usr/local/bin/python2.7 /usr/local/bin/fuglu --pidfile /var/r root 26179
>   0.0  0.0  18824   1976  0  S+4:30PM 0:00.00 grep fuglu 
>
> I'm at a loss as to what to try, I feel I'm missing something blindingly
> obvious but it's a mystery to me so if anyone can wave the big red arrow at
> my mistake I'd be a happy chappy! 
>
> Full fuglu.in below:
> 
> #!/bin/sh
> 
> # $FreeBSD$
> #
> # PROVIDE: fuglu
> # REQUIRE: LOGIN
> # KEYWORD: shutdown
> #
> # Add these lines to /etc/rc.conf.local or /etc/rc.conf
> # to enable this service:
> #
> # fuglu_enable (bool):Set to NO by default.
> #Set it to YES to enable fuglu.
> 
> . /etc/rc.subr
> 
> name="fuglu"
> rcvar=fuglu_enable
> 
> load_rc_config $name
> : ${fuglu_enable:=no}
> 
> command=%%PREFIX%%/bin/${name}
> pidfile="/var/run/${name}.pid"
> 
> run_rc_command "$1"
This question might have been better directed at freebsd-hackers@
but...

See if this get's it for you:

 /etc/rc.subr

name=fuglu
rcvar=fuglu_enable

load_rc_config $name

: ${fuglu_enable="NO"}
: ${fuglu_pidfile="/var/run/${name}.pid"}

command="/usr/local/sbin/${name}"
pidfile="${fuglu_pidfile}"

run_rc_command $*


--Chris
> ___
> freebsd-ports@freebsd.org mailing list
> https://lists.freebsd.org/mailman/listinfo/freebsd-ports
> To unsubscribe, send any mail to "freebsd-ports-unsubscr...@freebsd.org"


___
freebsd-ports@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/freebsd-ports
To unsubscribe, send any mail to "freebsd-ports-unsubscr...@freebsd.org"


Re: rc script problem - pidfile not being recognised

2015-09-11 Thread Kevin Golding


- Original Message -
> From: "Michelle Sullivan" <miche...@sorbs.net>
> To: "Kevin Golding" <k...@caomhin.org>
> Cc: freebsd-ports@freebsd.org
> Sent: Friday, 11 September, 2015 3:58:58 PM
> Subject: Re: rc script problem - pidfile not being recognised
> 
> Kevin Golding wrote:
> > It dopes create a pidfile so I have the following line in my
> > script:
> >
> > pidfile="/var/run/${name}.pid"
> >
> > Alas...
> >
> > # service fuglu stop
> > fuglu not running? (check /var/run/fuglu.pid).
> > # cat /var/run/fuglu.pid
> > 24013
> >
> > I don't get it. It is the right process ID:
> >
> > # ps -waux | grep fuglu
> > nobody   24013   0.0  0.5 139532  37372  -  I 3:57PM
> > 0:01.03 /usr/local/bin/python2.7 /usr/local/bin/fuglu
> > --pidfile /var/r
> > root 26179   0.0  0.0  18824   1976  0  S+4:30PM
> > 0:00.00 grep fuglu
> >   
> 
> I'd take a bet as it's running as a user the process is being called
> to 
> shutdown and there is some permissions issue on the PID file (I see
> the
> same thing with bucardo when running bucardo as non root)

I did wonder about that but the pidfile is world readable:

-rw-r--r--  1 root wheel6 Sep 11 15:57 /var/run/fuglu.pid

And certainly the process's user can read the file

 # sudo -u nobody cat /var/run/fuglu.pid
24013

Which isn't to say that isn't the problem, just that if it is I think I'm even 
more confused.
___
freebsd-ports@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/freebsd-ports
To unsubscribe, send any mail to "freebsd-ports-unsubscr...@freebsd.org"


Re: rc script problem - pidfile not being recognised

2015-09-11 Thread RW via freebsd-ports
On Fri, 11 Sep 2015 15:42:18 +0100 (BST)
Kevin Golding wrote:

> I've been trying to work on a new port and it's my first that uses an
> rc script so I've been expecting a few bumps, but there's one thing I
> can't seem to fix and it's a blocker. I can't stop the daemon!
> 
> It dopes create a pidfile so I have the following line in my script:
> 
> pidfile="/var/run/${name}.pid"
> 
..
> # ps -waux | grep fuglu
> nobody   24013   0.0  0.5 139532  37372  -  I 3:57PM
> 0:01.03 /usr/local/bin/python2.7 /usr/local/bin/fuglu

did you set the command_interpreter variable, probably you need

command_interpreter=/usr/local/bin/python2.7
___
freebsd-ports@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/freebsd-ports
To unsubscribe, send any mail to "freebsd-ports-unsubscr...@freebsd.org"


Re: rc script problem - pidfile not being recognised

2015-09-11 Thread Kevin Golding
- Original Message -
> From: "RW via freebsd-ports" 
> Sent: Friday, 11 September, 2015 4:18:50 PM
> 
> On Fri, 11 Sep 2015 15:42:18 +0100 (BST)
> Kevin Golding wrote:
> 
> > I've been trying to work on a new port and it's my first that uses
> > an
> > rc script so I've been expecting a few bumps, but there's one thing
> > I
> > can't seem to fix and it's a blocker. I can't stop the daemon!
> > 
> > It dopes create a pidfile so I have the following line in my
> > script:
> > 
> > pidfile="/var/run/${name}.pid"
> > 
> ..
> > # ps -waux | grep fuglu
> > nobody   24013   0.0  0.5 139532  37372  -  I 3:57PM
> > 0:01.03 /usr/local/bin/python2.7 /usr/local/bin/fuglu
> 
> did you set the command_interpreter variable, probably you need
> 
> command_interpreter=/usr/local/bin/python2.7

And that seems to have fixed it - thank you.

I still think there's an error in reading the pidfile since I think this means 
I'm using the process name rather than the pid but it does the job so I won't 
worry too much for today. Maybe I'll venture over to freebsd-hackers@ to solve 
that one when I feel I know my script a little better.
___
freebsd-ports@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/freebsd-ports
To unsubscribe, send any mail to "freebsd-ports-unsubscr...@freebsd.org"