mirror of
https://github.com/unraid/webgui.git
synced 2026-05-03 16:29:45 -05:00
smarter restarting of access services
- restart ssh daemon only when changes are present - restart telnet daemon only when changes are present
This commit is contained in:
@@ -1,13 +1,12 @@
|
||||
#!/bin/bash
|
||||
|
||||
SSHD=/usr/sbin/sshd
|
||||
CONF=/etc/ssh/sshd_config
|
||||
INET=/etc/inetd.conf
|
||||
SERV=/etc/services
|
||||
|
||||
# read settings
|
||||
if [[ -a /boot/config/ident.cfg ]]; then
|
||||
source <(/usr/bin/fromdos < /boot/config/ident.cfg)
|
||||
fi
|
||||
[[ -e /boot/config/ident.cfg ]] && . <(/usr/bin/fromdos </boot/config/ident.cfg)
|
||||
|
||||
# preset default values
|
||||
[[ -z $USE_TELNET ]] && USE_TELNET=no
|
||||
@@ -16,22 +15,28 @@ fi
|
||||
[[ -z $PORTSSH ]] && PORTSSH=22
|
||||
[[ -z $USE_UPNP ]] && USE_UPNP=no
|
||||
|
||||
# update SSH listening port
|
||||
if [[ $PORTSSH == 22 ]]; then
|
||||
sed -ri 's/^#?Port [0-9]+$/#Port 22/' $CONF
|
||||
else
|
||||
sed -ri "s/^#?Port [0-9]+\$/Port ${PORTSSH}/" $CONF
|
||||
# update ssh daemon listening port
|
||||
CURRENT=$(grep -Pom1 '^#?Port \K\d+$' $CONF)
|
||||
if [[ $PORTSSH != $CURRENT ]]; then
|
||||
if [[ $PORTSSH == 22 ]]; then
|
||||
sed -ri 's/^#?Port [0-9]+$/#Port 22/' $CONF
|
||||
else
|
||||
sed -ri "s/^#?Port [0-9]+\$/Port $PORTSSH/" $CONF
|
||||
fi
|
||||
fi
|
||||
|
||||
# enable/disable SSH service
|
||||
if [[ $USE_SSH == yes ]]; then
|
||||
if [[ -r /var/run/sshd.pid ]]; then
|
||||
/etc/rc.d/rc.sshd restart >/dev/null
|
||||
if [[ ! $(pgrep --ns $$ -cf $SSHD) -gt 0 ]]; then
|
||||
# start non-running ssh daemon
|
||||
/etc/rc.d/rc.sshd start
|
||||
else
|
||||
/etc/rc.d/rc.sshd start >/dev/null
|
||||
# restart when port has changed
|
||||
[[ $PORTSSH != $CURRENT ]] && /etc/rc.d/rc.sshd restart
|
||||
fi
|
||||
else
|
||||
/etc/rc.d/rc.sshd stop >/dev/null
|
||||
elif [[ $(pgrep --ns $$ -cf $SSHD) -gt 0 ]]; then
|
||||
# stop running ssh daemon
|
||||
/etc/rc.d/rc.sshd stop
|
||||
fi
|
||||
|
||||
# enable/disable UPnP function
|
||||
@@ -42,16 +47,21 @@ else
|
||||
fi
|
||||
|
||||
# update TELNET listening port
|
||||
sed -ri "s/^(telnet\s+)[0-9]+\/(tcp|udp)\$/\1${PORTTELNET}\/\2/" $SERV
|
||||
CURRENT=$(grep -Pom1 '^telnet\s+\K\d+' $SERV)
|
||||
[[ $PORTTELNET != $CURRENT ]] && sed -ri "s/^(telnet\s+)[0-9]+\/(tcp|udp)\$/\1$PORTTELNET\/\2/" $SERV
|
||||
|
||||
# bind/unbind TELNET service
|
||||
if [[ -n $IPV4 ]]; then
|
||||
BIND="$IPV4:"
|
||||
fi
|
||||
# enable/disable TELNET service
|
||||
if [[ $USE_TELNET == yes ]]; then
|
||||
sed -ri "s/^#?(.+:)?(telnet\s.+telnetd\$)/${BIND}\2/" $INET
|
||||
else
|
||||
sed -ri 's/^#?(.+:)?(telnet\s.+telnetd$)/#\2/' $INET
|
||||
if [[ -n $(grep -o '^#telnet' $INET) ]]; then
|
||||
# restart inet with telnet enabled
|
||||
sed -ri "s/^#(telnet\s.+telnetd\$)/\1/" $INET
|
||||
/etc/rc.d/rc.inetd restart
|
||||
elif [[ $PORTTELNET != $CURRENT ]]; then
|
||||
# restart when port has changed
|
||||
/etc/rc.d/rc.inetd restart
|
||||
fi
|
||||
elif [[ -n $(grep -o '^telnet' $INET) ]]; then
|
||||
# restart inet with telnet disabled
|
||||
sed -ri 's/^(telnet\s.+telnetd$)/#\1/' $INET
|
||||
/etc/rc.d/rc.inetd restart
|
||||
fi
|
||||
/etc/rc.d/rc.inetd restart >/dev/null
|
||||
|
||||
Reference in New Issue
Block a user