Skip to main content
Topic: MAILMAN init.d script (Read 1758 times) previous topic - next topic
0 Members and 1 Guest are viewing this topic.

MAILMAN init.d script

I created this mailman script but the status doesn't work.  It always believes that it is crashed when you run status, whichis fustrating and I can't figure out how to fix it.  The example on gentoo don't even use start-stop-dameon

  [www3 ~]# cat /etc/init.d/mailman

Code: [Select]
#!/usr/bin/openrc-run
# Copyright 1999-2015 Gentoo Foundation
# Distributed under the terms of the GNU General Public License v2

extra_commands="checkconfig"
extra_started_commands="reload"

: ${MAILMAN_CONFDIR:=/usr/lib/mailman/Mailman}
: ${MAILMAN_CONFIG:=${MAILMAN_CONFDIR}/mm_cfg.py}
: ${MAILMAN_PIDFILE:=/var/lib/mailman/data/master-qrunner.pid}
: ${MAILMAN_BINARY:=/usr/lib/mailman/bin/mailmanctl}

depend() {
        need net
        use mta
        use logger

        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 }' "$MAILMAN_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 mailman_config!"
                        ewarn "You must add rc_need=\"net.FOO\" to your /etc/conf.d/mailmand"
                        ewarn "where FOO is the interface(s) providing the following address(es):"
                        ewarn "${warn_addr}"
                fi
        fi
}

checkconfig() {
        echo "Yo - go find ${MAILMAN_CONFIG}"
        if [ ! -e "${MAILMAN_CONFIG}" ] ; then
                eerror "You need an ${MAILMAN_CONFIG} file to run mailman"
                return 1
        fi


}

mailman_checkproc() {
    unset COLUMNS
    mailman_pslist=$(ps xao "%p %a"  | grep -E "/usr/bin/python.*/usr/lib/mailman/bin/mailmanctl" | grep -v grep | awk '{print $1}')
    if [ -n "$mailman_pslist" ]; then
        return 0
    else
        return 3
    fi
}

start() {
        echo "Go find the config"
        checkconfig || return 1

        ebegin "Starting ${SVCNAME}"
        echo "PIDFILE ${MAILMAN_PIDFILE}"
        start-stop-daemon -v --make-pid --pidfile="{MAILMAN_PIDFILE}" --start --exec "${MAILMAN_BINARY}" start
        #start-stop-daemon -v --background --pidfile="{MAILMAN_PIDFILE}" --make-pid --start --exec "${MAILMAN_BINARY}" start
        eend $?
}

status(){
        checkconfig || return 1
        ebegin "Status  ${SVCNAME}"
        mailman_checkproc;
        if [ $? -eq 0 ]; then
                ebegin "Mailman is Up";
        else
                eerror "stopped"
        fi
        eend $?
}

stop() {
        if [ "${RC_CMD}" = "restart" ] ; then
                checkconfig || return 1
        fi

        ebegin "Stopping ${SVCNAME}"
        start-stop-daemon --stop --exec "${MAILMAN_BINARY}" \
            --pidfile "${MAILMAN_PIDFILE}" --quiet
        eend $?
}

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

I wrote a work around but there has to be a better way with openrc and start-stop-daemon

Re: MAILMAN init.d script

Reply #1
Code: [Select]
start-stop-daemon -v --make-pid --pidfile="{MAILMAN_PIDFILE}" --start --exec "${MAILMAN_BINARY}" start 

This line should be:
Code: [Select]
start-stop-daemon -v --make-pid --pidfile="${MAILMAN_PIDFILE}" --start --exec "${MAILMAN_BINARY}" start 

And of course MAILMAN_PIDFILE must be configured in /etc/conf.d/mailman

Re: MAILMAN init.d script

Reply #2
[www3 ~]# Traceback (most recent call last):
  File "/usr/lib/mailman/bin/mailmanctl", line 556, in <module>
    main()
  File "/usr/lib/mailman/bin/mailmanctl", line 412, in main
    fp = open(mm_cfg.PIDFILE, 'w')
IOError: [Errno 13] Permission denied: '/var/lib/mailman/data/master-qrunner.pid'


:(
www3 ~]# ls -al /var/lib/mailman/
total 48
drwxrwsr-x 10 mailman mailman 4096 Oct 25  2015 .
drwxr-xr-x 28 root    root    4096 Oct  2 16:03 ..
drwxrwsr-x  4 root    mailman 4096 Oct  8  2014 archives
-rw-------  1 mailman mailman   27 Oct 25  2015 .bash_history
drwxrwsr-x  2 root    mailman 4096 Oct  6 15:47 data
drwxrwsr-x  5 root    mailman 4096 Apr  2  2017 lists
drwxrwsr-x  3 mailman mailman 4096 Oct 20  2015 .local
drwxrwsr-x  2 root    mailman 4096 Oct  6 15:50 locks
drwxrwsr-x  2 root    mailman 4096 Mar  5  2016 logs
drwxrwsr-x 12 root    mailman 4096 Jan  1  2016 qfiles
drwxrwsr-x  2 root    mailman 4096 Oct  8  2014 spam
-rw-------  1 mailman mailman  601 Oct 25  2015 .viminfo

permissions look right

Re: MAILMAN init.d script

Reply #3
Thank You!  Your debugging made me track down the problems in this script that have been nagging me.

Here is the new script, which now works without me needed an custom status function
Code: [Select]
#!/usr/bin/openrc-run
# Copyright ME
# Distributed under the terms of the GNU General Public License v2

extra_commands="checkconfig"
extra_started_commands="reload"

: ${MAILMAN_CONFDIR:=/usr/lib/mailman/Mailman}
: ${MAILMAN_CONFIG:=${MAILMAN_CONFDIR}/mm_cfg.py}
: ${MAILMAN_PIDFILE:=/var/lib/mailman/data/master-qrunner.pid}
: ${MAILMAN_BINARY:=/usr/lib/mailman/bin/mailmanctl}

depend() {
        need net
        use mta
        use logger

        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 }' "$MAILMAN_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 mailman_config!"
                        ewarn "You must add rc_need=\"net.FOO\" to your /etc/conf.d/mailmand"
                        ewarn "where FOO is the interface(s) providing the following address(es):"
                        ewarn "${warn_addr}"
                fi
        fi
}

checkconfig() {
        echo "Yo - go find ${MAILMAN_CONFIG}"
        if [ ! -e "${MAILMAN_CONFIG}" ] ; then
                eerror "You need an ${MAILMAN_CONFIG} file to run mailman"
                return 1
        fi


}

mailman_checkproc() {
    unset COLUMNS
    mailman_pslist=$(ps xao "%p %a"  | grep -E "/usr/bin/python.*/usr/lib/mailman/bin/mailmanctl" | grep -v grep | awk '{print $1}')
    if [ -n "$mailman_pslist" ]; then
        return 0
    else
        return 3
    fi
}


start() {
        echo "Go find the config"
        checkconfig || return 1

        ebegin "Starting ${SVCNAME}"
        ewarn "PIDFILE ${MAILMAN_PIDFILE}"
        ewarn "PIDFILE ${MAILMAN_BINARY}"
        ewarn "start-stop-daemon -v --pidfile=${MAILMAN_PIDFILE} --start --exec ${MAILMAN_BINARY} start"
        start-stop-daemon -v --pidfile="${MAILMAN_PIDFILE}" --start --exec "${MAILMAN_BINARY}" start
        #start-stop-daemon -v --background --pidfile="{MAILMAN_PIDFILE}" --make-pid --start --exec "${MAILMAN_BINARY}" start
        eend $?
}

#status(){
#       checkconfig || return 1
#       ebegin "Status  ${SVCNAME}"
#       mailman_checkproc;
#       if [ $? -eq 0 ]; then
#               ebegin "Mailman is Up";
#       else
#               eerror "stopped"
#       fi
#       eend $?
#}

stop() {
        if [ "${RC_CMD}" = "restart" ] ; then
                checkconfig || return 1
        fi

        ebegin "Stopping ${SVCNAME}"
        start-stop-daemon --stop --exec "${MAILMAN_BINARY}" \
            --pidfile "${MAILMAN_PIDFILE}" --quiet
        eend $?
}

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