[oe] [meta-networking][PATCH V2 1/2] postfix.inc: fix start postfix failed while hostname is numeric
Hongxu Jia
hongxu.jia at windriver.com
Wed Dec 2 10:15:40 UTC 2015
While hostname is numeric, start postfix failed
...
root at qemux86-64:~# hostname 1.2.3.4
root at qemux86-64:~# systemctl restart postfix
|Job for postfix.service failed because the control process exited
with error code. See "systemctl status postfix.service" and
"journalctl -xe" for details.
root at qemux86-64:~# systemctl status postfix -l
Dec 02 08:05:40 1.2.3.4 aliasesdb[535]: /usr/sbin/postconf: fatal: unable to use my own hostname
Dec 02 08:05:41 1.2.3.4 aliasesdb[535]: newaliases: warning: valid_hostname: numeric hostname: 1.2.3.4
Dec 02 08:05:41 1.2.3.4 postfix/sendmail[537]: warning: valid_hostname: numeric hostname: 1.2.3.4
Dec 02 08:05:41 1.2.3.4 aliasesdb[535]: newaliases: fatal: unable to use my own hostname
Dec 02 08:05:42 1.2.3.4 postfix[540]: warning: valid_hostname: numeric hostname: 1.2.3.4
Dec 02 08:05:42 1.2.3.4 postfix[540]: fatal: unable to use my own hostname
...
Refer meta/recipes-core/initscripts/initscripts-1.0/hostname.sh in oe-core,
add check_hostname.sh and invoke it before postfix start, if the hostname
is invalid, set "localhost" to main.cf.
Signed-off-by: Hongxu Jia <hongxu.jia at windriver.com>
---
.../recipes-daemons/postfix/files/check_hostname.sh | 13 +++++++++++++
meta-networking/recipes-daemons/postfix/files/postfix | 1 +
.../recipes-daemons/postfix/files/postfix.service | 1 +
meta-networking/recipes-daemons/postfix/postfix.inc | 3 +++
4 files changed, 18 insertions(+)
create mode 100755 meta-networking/recipes-daemons/postfix/files/check_hostname.sh
diff --git a/meta-networking/recipes-daemons/postfix/files/check_hostname.sh b/meta-networking/recipes-daemons/postfix/files/check_hostname.sh
new file mode 100755
index 0000000..37a0dd0
--- /dev/null
+++ b/meta-networking/recipes-daemons/postfix/files/check_hostname.sh
@@ -0,0 +1,13 @@
+#! /bin/sh
+
+HOSTNAME=$(/bin/hostname)
+
+if [ -z "$HOSTNAME" -o "$HOSTNAME" = "(none)" -o ! -z "`echo $HOSTNAME | sed -n '/^[0-9]*\.[0-9].*/p'`" ]; then
+ # If hostname is invalid, and myhostname not existed in main.cf
+ /usr/sbin/postconf -h "myhostname" 2>/dev/null
+ if [ $? -ne 0 ]; then
+ # Set "localhost" to main.cf
+ /usr/sbin/postconf -e "myhostname=localhost"
+ fi
+fi
+
diff --git a/meta-networking/recipes-daemons/postfix/files/postfix b/meta-networking/recipes-daemons/postfix/files/postfix
index 0ea67ef..8c7a601 100755
--- a/meta-networking/recipes-daemons/postfix/files/postfix
+++ b/meta-networking/recipes-daemons/postfix/files/postfix
@@ -40,6 +40,7 @@ case "$1" in
newaliases
fi
if ! postfix status >/dev/null 2>&1; then
+ /usr/sbin/check_hostname.sh
postfix start
check_return $?
else
diff --git a/meta-networking/recipes-daemons/postfix/files/postfix.service b/meta-networking/recipes-daemons/postfix/files/postfix.service
index 02ea640..3a9a0a1 100644
--- a/meta-networking/recipes-daemons/postfix/files/postfix.service
+++ b/meta-networking/recipes-daemons/postfix/files/postfix.service
@@ -6,6 +6,7 @@ Conflicts=sendmail.service exim.service
[Service]
Type=forking
PIDFile=@LOCALSTATEDIR@/spool/postfix/pid/master.pid
+ExecStartPre=- at SBINDIR@/check_hostname.sh
ExecStartPre=- at LIBEXECDIR@/aliasesdb
ExecStart=@SBINDIR@/postfix start
ExecReload=@SBINDIR@/postfix reload
diff --git a/meta-networking/recipes-daemons/postfix/postfix.inc b/meta-networking/recipes-daemons/postfix/postfix.inc
index 3e7f918..271eb09 100644
--- a/meta-networking/recipes-daemons/postfix/postfix.inc
+++ b/meta-networking/recipes-daemons/postfix/postfix.inc
@@ -23,6 +23,7 @@ SRC_URI = "ftp://ftp.porcupine.org/mirrors/postfix-release/official/postfix-${PV
file://internal_recipient \
file://postfix.service \
file://aliasesdb \
+ file://check_hostname.sh \
"
S = "${WORKDIR}/postfix-${PV}"
@@ -145,6 +146,8 @@ do_install () {
install -m 644 ${WORKDIR}/main.cf_2.0 ${D}${sysconfdir}/postfix/main.cf
sed -i 's#@LIBEXECDIR@#${libexecdir}#' ${D}${sysconfdir}/postfix/main.cf
+ install -m 755 ${WORKDIR}/check_hostname.sh ${D}${sbindir}/
+
install -m 755 ${WORKDIR}/postfix ${D}${sysconfdir}/init.d/postfix
install -m 644 ${WORKDIR}/internal_recipient ${D}${sysconfdir}/postfix/internal_recipient
--
1.9.1
More information about the Openembedded-devel
mailing list