Skip to main content
Topic: SSHD Init Script (Read 825 times) previous topic - next topic
0 Members and 1 Guest are viewing this topic.

SSHD Init Script

I made this script but I'm not absolutely happy because it doesn't kill the whole chain of sshd services that are already open.  It only kills the  top

Code: [Select]
# Copyright 1999-2015 Gentoo Foundation
# Distributed under the terms of the GNU General Public License v2


: ${SSHD_CONFDIR:=/etc/ssh}
: ${SSHD_CONFIG:=${SSHD_CONFDIR}/sshd_config}
: ${SSHD_PIDFILE:=/run/${SVCNAME}.pid}
: ${SSHD_BINARY:=/usr/bin/sshd}

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

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

        if [ ! -e "${SSHD_CONFIG}" ] ; then
                eerror "You need an ${SSHD_CONFIG} file to run sshd"
                eerror "There is a sample file in /usr/share/doc/openssh"
                return 1

        ssh-keygen -A || return 1

        [ "${SSHD_PIDFILE}" != "/run/" ] \
                && SSHD_OPTS="${SSHD_OPTS} -o PidFile=${SSHD_PIDFILE}"
        [ "${SSHD_CONFIG}" != "/etc/ssh/sshd_config" ] \
                && SSHD_OPTS="${SSHD_OPTS} -f ${SSHD_CONFIG}"

        "${SSHD_BINARY}" -t ${SSHD_OPTS} || return 1
stop() {
        ebegin "Stopping ${SVCNAME}"
        echo "start-stop-daemon --stop --exec ${SSHD_BINARY}  --pidfile ${SSHD_PIDFILE} --quiet"
        start-stop-daemon --stop --exec "${SSHD_BINARY}"  --pidfile "${SSHD_PIDFILE}" --quiet
        eend $?

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

now the binary sshd does not have a shutdown so I'm not sure what to do here.  I can run it in the foreground and force it to the background.

Re: SSHD Init Script

Reply #1
Please delete this, it was meant to be posted on another thread but it moved here at some point  >:(