F #248: Restart syslog on hostname change

Closes #248
pull/252/head
Vlastimil Holer 3 years ago
parent bc0743fcf8
commit 5cb9f3aaa3
No known key found for this signature in database
GPG Key ID: EB549BADEFD07C53

@ -21,7 +21,7 @@ name="OpenNebula contextualization"
depend() { depend() {
use one-context-local net use one-context-local net
before sshd before sshd
use logger after logger
keyword -stop -shutdown keyword -stop -shutdown
} }

@ -15,13 +15,13 @@
# See the License for the specific language governing permissions and # # See the License for the specific language governing permissions and #
# limitations under the License. # # limitations under the License. #
#--------------------------------------------------------------------------- # #--------------------------------------------------------------------------- #
#
name="OpenNebula pre-networking contextualization" name="OpenNebula pre-networking contextualization"
depend() { depend() {
need localmount udev udev-trigger udev-settle need localmount udev udev-trigger udev-settle
before net before net
use logger after logger
keyword -stop -shutdown keyword -stop -shutdown
} }

@ -23,29 +23,53 @@ else
SED_I="sed -i''" SED_I="sed -i''"
fi fi
# Detects suitable running syslog service and restarts it
# to propagate the changed hostname into the logs
# (otherwise old or default value remains until reboot)
function restart_syslog() {
for _name in syslog syslogd rsyslog; do
if LANG=C systemctl is-active "${_name}" >/dev/null 2>&1; then
systemctl restart "${_name}" && return
elif service "${_name}" status >/dev/null 2>&1; then
service "${_name}" restart && return
fi
done
}
function set_hostname() { function set_hostname() {
local hostname=$1 local _hostname=$1
# remember currently set hostname to detect a change
local _old_hostname
_old_hostname=$(hostname)
if [ -d /run/systemd/system/ ] && hostnamectl status >/dev/null 2>/dev/null; then if [ -d /run/systemd/system/ ] && hostnamectl status >/dev/null 2>/dev/null; then
hostnamectl set-hostname --static "${hostname}" hostnamectl set-hostname --static "${_hostname}"
else else
if [ -f /etc/sysconfig/network ]; then if [ -f /etc/sysconfig/network ]; then
eval "${SED_I} '/^HOSTNAME=.*$/d' /etc/sysconfig/network" eval "${SED_I} '/^HOSTNAME=.*$/d' /etc/sysconfig/network"
echo "HOSTNAME=${hostname}" >>/etc/sysconfig/network echo "HOSTNAME=${_hostname}" >>/etc/sysconfig/network
elif [ "${_kernel}" = 'FreeBSD' ]; then elif [ "${_kernel}" = 'FreeBSD' ]; then
sysrc hostname="${hostname}" sysrc hostname="${_hostname}"
else else
echo "${hostname}" >/etc/hostname echo "${_hostname}" >/etc/hostname
fi fi
hostname "${hostname}" hostname "${_hostname}"
fi
# restart syslog if actual hostname changed
if [ "${_old_hostname}" != "$(hostname)" ]; then
restart_syslog
fi fi
} }
function set_domainname() { function set_domainname() {
domain=$1 local _domain=$1
touch /etc/resolv.conf
eval "${SED_I} -e '/^domain .*/d' /etc/resolv.conf" eval "${SED_I} -e '/^domain .*/d' /etc/resolv.conf"
echo "domain ${domain}" >>/etc/resolv.conf echo "domain ${_domain}" >>/etc/resolv.conf
} }
function get_first_ip() { function get_first_ip() {
@ -131,6 +155,10 @@ if [ -n "${name}" ]; then
domain='' domain=''
fi fi
if [ -n "${domain}" ]; then
set_domainname "${domain}"
fi
# FreeBSD # FreeBSD
if [ "${_kernel}" = 'FreeBSD' ]; then if [ "${_kernel}" = 'FreeBSD' ]; then
set_hostname "${name}" set_hostname "${name}"
@ -138,10 +166,6 @@ if [ -n "${name}" ]; then
set_hostname "${hostname}" set_hostname "${hostname}"
fi fi
if [ -n "${domain}" ]; then
set_domainname "${domain}"
fi
if [ -n "${DNS_HOSTNAME}" ]; then if [ -n "${DNS_HOSTNAME}" ]; then
host_ip=$first_ip host_ip=$first_ip
else else

Loading…
Cancel
Save