when i reboot my system or shut it down and im connected to the pc with ssh the session gets stuck until the system comes up again (then its dropped) or the timeout is over (also dropped) therefor when the system goes down or reboots all sshd sessions should get killed to disconnect all users that are connected with ssh to the pc this is the modified stop routine for sshd to kill all sshd sessions when the system goes down or reboots ... stop() { if [ "${RC_CMD}" = "restart" ] ; then checkconfig || return 1 fi ebegin "Stopping ${SVCNAME}" if [ "`/sbin/runlevel|/bin/cut -c 3`" = "3" ]; then start-stop-daemon --stop --exec "${SSHD_BINARY}" \ --pidfile "${SSHD_PIDFILE}" --quiet else killall -q /usr/sbin/sshd fi eend $? } Reproducible: Always Steps to Reproduce: 1.start sshd 2.connect to sshd 3.reboot or shutdown pc 4.connection stucks until timeout is over or the pc is up again .... Expected Results: all clients should be disconnected when the pc goes down or reboots
updated version that uses SSHD_BINARY instead... stop() { if [ "${RC_CMD}" = "restart" ] ; then checkconfig || return 1 fi ebegin "Stopping ${SVCNAME}" if [ "`/sbin/runlevel|/bin/cut -c 3`" = "3" ]; then start-stop-daemon --stop --exec "${SSHD_BINARY}" \ --pidfile "${SSHD_PIDFILE}" --quiet else killall -q "${SSHD_BINARY}" fi eend $? }
to keep consistency use start-stop-daemon ... stop() { if [ "${RC_CMD}" = "restart" ] ; then checkconfig || return 1 fi ebegin "Stopping ${SVCNAME}" if [ "`/sbin/runlevel|/bin/cut -c 3`" = "1" ]; then start-stop-daemon --stop --exec "${SSHD_BINARY}" \ --pidfile "${SSHD_PIDFILE}" --quiet else start-stop-daemon --stop -n "${SSHD_BINARY}" --quiet fi eend $? }
test for runlevel 3 not 1 ... stop() { if [ "${RC_CMD}" = "restart" ] ; then checkconfig || return 1 fi ebegin "Stopping ${SVCNAME}" if [ "`/sbin/runlevel|/bin/cut -c 3`" = "3" ]; then start-stop-daemon --stop --exec "${SSHD_BINARY}" \ --pidfile "${SSHD_PIDFILE}" --quiet else start-stop-daemon --stop -n "${SSHD_BINARY}" --quiet fi eend $? }
yeah, we cant merge any of those. obviously the first one will kill too much when doing `/etc/init.d/sshd stop`, and the latter rely on sysvinit. i dont see this as being a real problem, and i'm not aware of any other distro that attempts to address this.
but there is no better way to find out if the service is stopped by the user or at reboot/shutdown?
atm, i dont think so. openrc doesnt provide differentiation between "shutting down" and "switching runlevels". simply switching between runlevels where the new one doesnt have sshd init.d in it should not kill sessions. i dont think `fuser` or a similar util can deduce the reason for an app using the network, so it couldnt just say "kill all processes with a network socket open" before bringing down the network.
Shouldn't services that need net be stopped before net goes down?
(In reply to comment #7) > Shouldn't services that need net be stopped before net goes down? As Mike pointed out in comment #6, OpenRC doesn't provide the ability to know that shut down is happening due to a runlevel change or the system going down.
*** Bug 452026 has been marked as a duplicate of this bug. ***
as it seems openrc intruduced this fix a long time ago kexec allready uses this the stop function for the openssh initscript should be changed to: stop() { if [ "${RC_CMD}" = "restart" ] ; then checkconfig || return 1 fi ebegin "Stopping ${SVCNAME}" if yesno $RC_REBOOT; then #rebooting start-stop-daemon --stop -n "${SSHD_BINARY}" --quiet else start-stop-daemon --stop --exec "${SSHD_BINARY}" \ --pidfile "${SSHD_PIDFILE}" --quiet fi eend $? }
this fix doesn't work as it just recognizes a reboot a shutdown is still unhandeld
Isn't this a dublicate of bug 259183?
*** This bug has been marked as a duplicate of bug 259183 ***