Skip to main content
Topic: start-stop-daemon  (Read 802 times) previous topic - next topic
0 Members and 1 Guest are viewing this topic.

start-stop-daemon

I've tried to write init scripts for openrc which involve, obviously, using the start-stop dameon, and I alway find myself guessing exactly how it works. 

for apache, I want to start it with the apache start stripts, normally under /usr/local/apache/bin/apachectl

I can't seem to get openrc to work seemlessly with this, especially the pid accounting.  Nor do I understand how the options are passed to the start-stop-daemon scripts

I have

Code: [Select]
#!/usr/bin/openrc-run
# Distributed under the terms of the GNU General Public License v2
echo "Hello"
#extra_commands="checkconfig"
#extra_started_commands="reload"

: ${APACHE_CONFDIR:=/usr/local/apache2/conf}
: ${APACHE_CONFIG:=${APACHE_CONFDIR}/httpd.conf}
: ${APACHE_PIDFILE:=/usr/local/apache2/logs/${SVCNAME}.pid}
: ${APACHE_BINARY:=/usr/local/apache2/bin/apachectl}

        echo "PIDFILE ${APACHE_PIDFILE}"
depend() {
        use logger dns
        if [ "${rc_need+set}" = "set" ] ; then
                : # Do nothing, the user has explicitly set rc_need
        else
                local x warn_addr
                for x in $(awk '/^ListenAddress/{ print $2 }' "$APACHE_CONFIG" 2>/dev/null) ; do
                        case "${x}" in
                                0.0.0.0|0.0.0.0:*) ;;
                                ::|\[::\]*) ;;
                                *) warn_addr="${warn_addr} ${x}" ;;
                        esac
                done
                if [ -n "${warn_addr}" ] ; then
                        need net
                        ewarn "You are binding an interface in ListenAddress statement in your httpd_config!"
                        ewarn "You must add rc_need=\"net.FOO\" to your /usr/local/apache2/conf/httpd.conf"
                        ewarn "where FOO is the interface(s) providing the following address(es):"
                        ewarn "${warn_addr}"
                fi
        fi
}

checkconfig() {
        if [ ! -d /var/empty ] ; then
                mkdir -p /var/empty || return 1
        fi

        if [ ! -e "${APACHE_CONFIG}" ] ; then
                eerror "You need an ${APACHE_CONFIG} file to run apache"
                return 1
        fi

}


start() {
        checkconfig || return 1

        ebegin "Starting ${SVCNAME}"
        echo "PIDFILE ${APACHE_PIDFILE}"
        echo "Command start-stop-daemon --start ${APACHE_BINARY}  start"
        start-stop-daemon --start "${APACHE_BINARY}"  "start"
        eend $?
}

stop() {
        ebegin "Stopping ${SVCNAME}"
        start-stop-daemon --stop "${APACHE_BINARY}" "stop"
        eend $?
}

reload() {
        checkconfig || return 1
        ebegin "Reloading ${SVCNAME}"
        start-stop-daemon --signal HUP \
            --exec "${APACHE_BINARY}"  --"restart"
        eend $?
}



It starts apache, but it just doesn't find the process to kill it or to restart it.  If I run httpd from apachtctl now, it dies when I exit the shell.


Re: start-stop-daemon

Reply #2
Isn't the default apache script sufficient?

Code: [Select]
rc-service httpd start 

works pretty much out of the box.

Re: start-stop-daemon

Reply #3
Isn't the default apache script sufficient?

Code: [Select]
rc-service httpd start 

works pretty much out of the box.
it doesn't work.  Apache set ups are not stock out of the box.  Mopre importantly, I want to understand how it works ;)



Re: start-stop-daemon

Reply #6
FFS!
Read properly. I hate your one liners btw.

I don't know why.  When you converse freely with someone, how often do you say more than one line at a time and then wait for a response.  Is that not how conversation happens in your area of residence or culture?

Aside from the obvious typo, it still doesn't exist.  I was going to look at it as a working reference:

Code: [Select]
[[email protected] ~]$ rc-service httpd
 * rc-service: service `httpd' does not exist

I am wondering what this variable is and where it comes from:

Code: [Select]
 13 depend() {
 14         use logger dns
 15         if [ "${rc_need+set}" = "set" ] ; then
 16                 : # Do nothing, the user has explicitly set rc_need

Re: start-stop-daemon

Reply #7
set is a shell builtin:
If no options or arguments are supplied, set displays the names and values of all shell variables and functions, sorted according to the current locale, in a format that may be reused as input for setting or resetting the currently-set variables. Read-only variables cannot be reset. In POSIX mode, only shell variables are listed.
https://www.gnu.org/software/bash/manual/html_node/The-Set-Builtin.html
The --pidfile option to start-stop-daemon is not given, it might help your script. The current openrc source in it's entirety can be a useful reference, it contains some extra documentation too.

Re: start-stop-daemon

Reply #8
set is a shell builtin:
If no options or arguments are supplied, set displays the names and values of all shell variables and functions, sorted according to the current locale, in a format that may be reused as input for setting or resetting the currently-set variables. Read-only variables cannot be reset. In POSIX mode, only shell variables are listed.
https://www.gnu.org/software/bash/manual/html_node/The-Set-Builtin.html
The --pidfile option to start-stop-daemon is not given, it might help your script. The current openrc source in it's entirety can be a useful reference, it contains some extra documentation too.


I don't see how this line is releated to set.  set is not being called

Code: [Select]
  1 #!/bin/sh 
  2
  3 echo ${rc_need+set}
  4
~           

[[email protected] ~]$ vim test.sh
[[email protected] ~]$ ./test.sh


Re: start-stop-daemon

Reply #9
The --pidfile option to start-stop-daemon is not given, it might help your script. The current openrc source in it's entirety can be a useful reference, it contains some extra documentation too.

That became a problem and I am considering what to do about it.  apachectl creates its own pidfile under /usr/local/apache/ instead of /var/run and /var/run has been a PIA with other scripts because the OS is not creating the needed ram direcectories.  I'm sure it is because of my own ignorance about how the system works.  With mariabd, I always need to make the darn /var/run by hand and blow open the file permisions to get it to work.

I just don't understand how this OS is creating /var/run enteries and what I have tried consistantly fails.

Re: start-stop-daemon

Reply #10
The logic still works if set is nothing, and I think it would work without the set. You found something interesting there.  :o
I thought you might try adding something like this to the start-stop-daemon lines:
start-stop-daemon --start "${APACHE_BINARY}"  "start" --pidfile "${APACHE_PIDFILE}"
but will the :'s be commenting out the variables in your script? I suppose this script is something you are working on.
A lot of times you can just put a pidfile= line near the top of the script somewhere too I think.


Code: [Select]

#!/bin/bash

VAR=1
echo "${VAR}"
echo "${set}"

rc_need=1234
if [ "${rc_need+set}" = "set" ] ; then
        echo "yes"
else
        echo "no"
fi

if [ "${rc_need}" ] ; then
        echo "yes again"
else
        echo "no again"
fi

if [ "${set}" ] ; then
        echo "set is something"
else
        echo "set is nothing"
fi

if [ "${VAR}" ] ; then
        echo "VAR is something"
else
        echo "VAR is nothing"
fi


Re: start-stop-daemon

Reply #11
fine but what is rc_need and how is it set?  set is not a variable, BTW, but a builtin command like 'ls' is on bash

Re: start-stop-daemon

Reply #12
ls is a small c program, not a BASH builtin, part of the coreutils package, and one of the authors is Richard Stallman, head GNU btw.
$ pacman -Qo /usr/bin/ls
/usr/bin/ls is owned by coreutils 8.30-1
The script tells you where to define rc_need:
ewarn "You must add rc_need=\"net.FOO\" to your /usr/local/apache2/conf/httpd.conf"

If you're writing  your own init scripts they can often be simple, just define a few variables and let openrc do all the work. That start-stop-daemon stuff is legacy support iirc. Something like this (but bear in mind I don't use apache)
Code: [Select]
#!/usr/bin/openrc-run

        command="/usr/bin/apache"
        command_args="--somearg"
        pidfile="/usr/local/apache2/logs/${SVCNAME}.pid}"
        start_stop_daemon_args="--quiet"
        name="apache"
        description="Apache hunts buffalo"

depend()
{
        need horse
        before paleface               
        keyword -wigwam
}


Re: start-stop-daemon

Reply #13
ls is a small c program, not a BASH builtin, part of the coreutils package, and one of the authors is Richard Stallman, head GNU btw.

FWIW - it/ can be is both.
https://www.gnu.org/software/bash/manual/html_node/Bash-Builtins.html

This is one of the reasons why using bash for a rescue disk is problematic.  It depends on external libraries.



FWIW, Richand and I are decent friends...
https://web.archive.org/web/20040214234910/http://www.nylxs.com/events/gnome/index.html#schedule

Re: start-stop-daemon

Reply #14
ls is a small c program, not a BASH builtin, part of the coreutils package, and one of the authors is Richard Stallman, head GNU btw.
$ pacman -Qo /usr/bin/ls
/usr/bin/ls is owned by coreutils 8.30-1
The script tells you where to define rc_need:

ewarn "You must add rc_need=\"net.FOO\" to your /usr/local/apache2/conf/httpd.conf"




but I am so stupid I don't know what this means!