diff --git a/infra/image/build.sh b/infra/image/build.sh index 71679238ca089f8a1d9ab4667d890edc90018601..7de49e414fa8751fa48d9d4d222107a35afb29e5 100755 --- a/infra/image/build.sh +++ b/infra/image/build.sh @@ -119,13 +119,6 @@ then deployed=true fi echo - - if $deployed; then - log info "= Enabling services =" - container_exec "${name}" systemctl enable fixnet - container_exec "${name}" systemctl enable fixipaip - echo - fi container_stop "${name}" diff --git a/infra/image/dockerfile/c10s b/infra/image/dockerfile/c10s index 2852aab507a3068b0fe56129c7efca13dbef221b..fa22e0ec0ae6592f8b9c677f8d25fa80f003078e 100644 --- a/infra/image/dockerfile/c10s +++ b/infra/image/dockerfile/c10s @@ -31,6 +31,8 @@ COPY system-service/fixipaip.sh /root/ COPY system-service/fixnet.service /etc/systemd/system/ COPY system-service/fixipaip.service /etc/systemd/system/ RUN chmod +x /root/fixnet.sh /root/fixipaip.sh +RUN systemctl enable fixnet.service +RUN systemctl enable fixipaip.service STOPSIGNAL RTMIN+3 diff --git a/infra/image/dockerfile/c8s b/infra/image/dockerfile/c8s index 3cf629a044bed33c15a91a2ba6979454b9295fc7..3737ce7958ef56a0f811d45a9593042fc2157f1b 100644 --- a/infra/image/dockerfile/c8s +++ b/infra/image/dockerfile/c8s @@ -34,6 +34,8 @@ COPY system-service/fixipaip.sh /root/ COPY system-service/fixnet.service /etc/systemd/system/ COPY system-service/fixipaip.service /etc/systemd/system/ RUN chmod +x /root/fixnet.sh /root/fixipaip.sh +RUN systemctl enable fixnet.service +RUN systemctl enable fixipaip.service STOPSIGNAL RTMIN+3 diff --git a/infra/image/dockerfile/c9s b/infra/image/dockerfile/c9s index daf181c40f2296da585cdf75bdfd86f01526f49c..be729e6ff96921d337bc81c491de942a1ccd256b 100644 --- a/infra/image/dockerfile/c9s +++ b/infra/image/dockerfile/c9s @@ -30,6 +30,8 @@ COPY system-service/fixipaip.sh /root/ COPY system-service/fixnet.service /etc/systemd/system/ COPY system-service/fixipaip.service /etc/systemd/system/ RUN chmod +x /root/fixnet.sh /root/fixipaip.sh +RUN systemctl enable fixnet.service +RUN systemctl enable fixipaip.service STOPSIGNAL RTMIN+3 diff --git a/infra/image/dockerfile/fedora-latest b/infra/image/dockerfile/fedora-latest index acdcbcf0dbc0775903a07430e6315e3af3c7ad31..ae6dbcfe090ffec2d24fbe193f182dd830c1579b 100644 --- a/infra/image/dockerfile/fedora-latest +++ b/infra/image/dockerfile/fedora-latest @@ -33,6 +33,8 @@ COPY system-service/fixipaip.sh /root/ COPY system-service/fixnet.service /etc/systemd/system/ COPY system-service/fixipaip.service /etc/systemd/system/ RUN chmod +x /root/fixnet.sh /root/fixipaip.sh +RUN systemctl enable fixnet.service +RUN systemctl enable fixipaip.service STOPSIGNAL RTMIN+3 diff --git a/infra/image/dockerfile/fedora-rawhide b/infra/image/dockerfile/fedora-rawhide index 42bb89674740a51f951d32ef8c572daecf6770d7..c6f37397e531212b6fe13aa1346c3719aa21f2dd 100644 --- a/infra/image/dockerfile/fedora-rawhide +++ b/infra/image/dockerfile/fedora-rawhide @@ -33,6 +33,8 @@ COPY system-service/fixipaip.sh /root/ COPY system-service/fixnet.service /etc/systemd/system/ COPY system-service/fixipaip.service /etc/systemd/system/ RUN chmod +x /root/fixnet.sh /root/fixipaip.sh +RUN systemctl enable fixnet.service +RUN systemctl enable fixipaip.service STOPSIGNAL RTMIN+3 diff --git a/infra/image/system-service/fixipaip.service b/infra/image/system-service/fixipaip.service index ec56c0d44fae4b9405d3726e583f2c1639701596..13a6d6b882e2c996b689972508fcb0692d844e44 100644 --- a/infra/image/system-service/fixipaip.service +++ b/infra/image/system-service/fixipaip.service @@ -1,6 +1,7 @@ [Unit] Description=Fix IPA server IP in IPA Server After=ipa.service +PartOf=ipa.service [Service] Type=oneshot @@ -9,4 +10,4 @@ StandardOutput=journal StandardError=journal [Install] -WantedBy=default.target +WantedBy=ipa.service diff --git a/infra/image/system-service/fixipaip.sh b/infra/image/system-service/fixipaip.sh index bc895bb4201bfbcb0f6003a1e90a71e3d9455ebe..d1d373e0017bc988fd95f199cbcaf45cad3b2a0b 100755 --- a/infra/image/system-service/fixipaip.sh +++ b/infra/image/system-service/fixipaip.sh @@ -50,9 +50,9 @@ if [ -z "${FORWARDER}" ] || [ "${FORWARDER}" == "127.0.0.1" ]; then fi echo "Fix IPA:" -echo " HOSTNAME: '${HOSTNAME}'" -echo " IP: '${IP}'" -echo " PTR: '${PTR}'" +echo " HOSTNAME: '${HOSTNAME}'" +echo " IP: '${IP}'" +echo " PTR: '${PTR}'" echo " FORWARDER: '${FORWARDER}'" ZONES=$(ipa -e in_server=true dnszone-find --name-from-ip="${HOSTNAME}." \ diff --git a/infra/image/system-service/fixnet.service b/infra/image/system-service/fixnet.service index a546a2f2e7122a5a421ef6eb362c655fa669564a..c6b0749b44fd133dbf38be516b9dde2bcb69678f 100644 --- a/infra/image/system-service/fixnet.service +++ b/infra/image/system-service/fixnet.service @@ -1,8 +1,5 @@ [Unit] -Description=Fix server IP in IPA Server -Wants=network.target -After=network.target -Before=ipa.service +Description=Fix /etc/hosts and with local DNS also /etc/resolv.conf [Service] Type=oneshot @@ -11,4 +8,4 @@ StandardOutput=journal StandardError=journal [Install] -WantedBy=ipa.service +WantedBy=container-ipa.target diff --git a/infra/image/system-service/fixnet.sh b/infra/image/system-service/fixnet.sh index 0bf6d0369a243bf4b6be26e549d758a78cd832fb..13d0a8fe64f85829906ff7c0b7ea94a0412249ed 100755 --- a/infra/image/system-service/fixnet.sh +++ b/infra/image/system-service/fixnet.sh @@ -39,26 +39,35 @@ if [ -z "${IP}" ] || ! valid_ipv4 "${IP}" ; then exit 1 fi +DOMAIN=${HOSTNAME#*.} + echo "Fix NET:" echo " HOSTNAME: '${HOSTNAME}'" -echo " IP: '${IP}'" +echo " DOMAIN: '${DOMAIN}'" +echo " IP: '${IP}'" echo -if grep -qE "^[^(#\s*)][0-9\.]+\s$HOSTNAME(\s|$)" /etc/hosts -then - sed -i.bak -e "s/.*${HOSTNAME}/${IP}\t${HOSTNAME}/" /etc/hosts -else - echo -e "$IP\t${HOSTNAME} ${HOSTNAME%%.*}" >> /etc/hosts -fi +# /etc/hosts + +sed -i -E "/\s+${HOSTNAME}(\s|$)/d" /etc/hosts +echo -e "$IP\t${HOSTNAME} ${HOSTNAME%%.*}" >> /etc/hosts + +echo "/etc/hosts:" +cat "/etc/hosts" + +# /etc/resolv.conf + +# If bind is not installed, exit +[ -f "/etc/named.conf" ] || exit 0 +# If dyndb is not enabled for bind, exit +grep -q '^dyndb "ipa"' "/etc/named.conf" || exit 0 cp -a /etc/resolv.conf /etc/resolv.conf.fixnet cat > /etc/resolv.conf <<EOF -search ${HOSTNAME#*.} +search ${DOMAIN} nameserver 127.0.0.1 EOF -echo "/etc/hosts:" -cat "/etc/hosts" echo echo "/etc/resolv.conf:" cat "/etc/resolv.conf"