Arch Linux

Please read this before reporting a bug:
https://wiki.archlinux.org/title/Bug_reporting_guidelines

Do NOT report bugs when a package is just outdated, or it is in the AUR. Use the 'flag out of date' link on the package page, or the Mailing List.

REPEAT: Do NOT report bugs for outdated packages!
Tasklist

FS#23469 - /etc/rc.d/postfix start fails if called from a script

Attached to Project: Arch Linux
Opened by Nico Schottelius (telmich) - Sunday, 27 March 2011, 21:24 GMT
Last edited by Gaetan Bisson (vesath) - Monday, 28 March 2011, 22:41 GMT
Task Type Bug Report
Category Packages: Extra
Status Closed
Assigned To Gaetan Bisson (vesath)
Architecture All
Severity Low
Priority Normal
Reported Version
Due in Version Undecided
Due Date Undecided
Percent Complete 100%
Votes 0
Private No

Details

Description:


[root@kr .cdist]# cat /var/lib/cdist/out/object/__process/usr/lib/postfix/master/.cdist/code-remote
#
# The following code is imported from output of /home/users/nico/oeffentlich/rechner/projekte/cdist/conf/type/__process/gencode-remote
#

/etc/rc.d/postfix start
[23:16] kr:cdist% ssh root@localhost "/var/lib/cdist/out/object/__process/usr/lib/postfix/master/.cdist/code-remote"
:: Starting Postfix [BUSY] [FAIL]

Using the rc.d script directly works:
[23:17] kr:cdist% ssh root@localhost "/etc/rc.d/postfix start"
:: Starting Postfix [BUSY] [DONE]
[23:21] kr:cdist%

cdist is the usable configuration management (replaces puppet, cfengine, etc.), which generates scripts that are executed on the target host, which may contain arbitrary code as defined in the types (by the user).

Thus this use case will increase pretty much soon, as cdist gets more popular right now.


Additional info:
* package version(s)
* config and/or log files etc.


Steps to reproduce:

- create script that contains /etc/rc.d/postfix start
- shutdown postfix
- run ssh yourhost "yourscript"
This task depends upon

Closed by  Gaetan Bisson (vesath)
Monday, 28 March 2011, 22:41 GMT
Reason for closing:  Fixed
Additional comments about closing:  postfix-2.8.2-2 in [extra]
Comment by Nico Schottelius (telmich) - Sunday, 27 March 2011, 21:31 GMT
I've justed testet the same way with the cups rc.d script, which works:


[23:30] kr:type% cdist-deploy-to localhost
...

Checking code-remote for __process/cups ...
Executing code-remote for __process/cups ...
:: Starting CUPS Daemon [BUSY] [DONE]

Comment by Gaetan Bisson (vesath) - Sunday, 27 March 2011, 22:22 GMT
Works for me...

Add "#!/bin/sh" as the first line of your file "/var/lib/cdist/out/object/__process/usr/lib/postfix/master/.cdist/code-remote", and do "chmod 755" to it; then try again.
Comment by Gaetan Bisson (vesath) - Sunday, 27 March 2011, 22:27 GMT
Can you also show me the content of the cdist file for cups, and check if there is any error in /var/log/mail.log?
Comment by Gaetan Bisson (vesath) - Sunday, 27 March 2011, 22:29 GMT
One last question: are you sure that postfix is not already running?
Comment by Nico Schottelius (telmich) - Monday, 28 March 2011, 06:11 GMT
Good morning Gaetan,

regarding #!/bin/sh probably already clearified, as the cdist script is executed with sh -e in front.


[root@kr ~]# cat /var/lib/cdist/out/object/__process/cups/.cdist/code-remote
#
# The following code is imported from output of /home/users/nico/oeffentlich/rechner/projekte/cdist/conf/type/__process/gencode-remote
#

/etc/rc.d/cups start


[root@kr ~]# ls -lh /var/lib/cdist/out/object/__process/cups/.cdist/code-remote
-rwx------ 1 root root 161 27. Mär 23:30 /var/lib/cdist/out/object/__process/cups/.cdist/code-remote

Regarding postfix: Yes, I'm definitely sure, for two reasons: 1) cdist checks for a process running before it tries to start it 2) ps aux| grep postfix -> empty
Comment by Gaetan Bisson (vesath) - Monday, 28 March 2011, 11:23 GMT
This really looks like a bug in the way cdist runs its programs... Does it only happen over SSH?!?
Could you remove the "&> /dev/null" from the postfix rc.d script and try running it via cdist, so that we could see some helpful error message?
Comment by Nico Schottelius (telmich) - Monday, 28 March 2011, 11:43 GMT
No error message when I remove &>:

Checking code-remote for __process/usr/lib/postfix/master ...
Executing code-remote for __process/usr/lib/postfix/master ...
:: Starting Postfix [BUSY] [FAIL]
Checking code-local for __package_pacman/zsh ...
Executing code-local for __package_pacman/zsh ...
Checking code-remote for __package_pacman/zsh ...
Executing code-remote for __package_pacman/zsh ...
Saving cache to /home/users/nico/oeffentlich/rechner/projekte/cdist/cache/localhost ...
cdist 1.5.0pre: Successfully finished run on localhost
[13:34] kr:cdist% ssh root@localhost "head -n11 /etc/rc.d/postfix"
#!/bin/bash

. /etc/rc.conf
. /etc/rc.d/functions

PID=`pgrep -f /usr/lib/postfix/master`

start() {
stat_busy "Starting Postfix"
# [ -z "$PID" ] && /usr/sbin/postfix start &> /dev/null
[ -z "$PID" ] && /usr/sbin/postfix start
[13:35] kr:cdist%
Comment by Nico Schottelius (telmich) - Monday, 28 March 2011, 11:53 GMT
The more I debug the issue, the more confused I get!

I manually changed /var/lib/cdist/out/object/__process/usr/lib/postfix/master/.cdist/code-remote to contain only the following:

[root@kr ~]# cat /var/lib/cdist/out/object/__process/usr/lib/postfix/master/.cdist/code-remote
/etc/rc.d/postfix start
[root@kr ~]#

Calling it via ssh now gives me:

[13:43] kr:cdist% ssh root@localhost "/var/lib/cdist/out/object/__process/usr/lib/postfix/master/.cdist/code-remote"
:: Starting Postfix [BUSY] [FAIL]

Having another script containing the same content works, though:

[root@kr ~]# cat /root/postfix-test
/etc/rc.d/postfix start
[root@kr ~]# ls -lh /root/postfix-test
-rwx------ 1 root root 24 28. Mär 13:39 /root/postfix-test
[root@kr ~]#
[13:44] kr:cdist% ssh root@localhost "/root/postfix-test"
:: Starting Postfix [BUSY] [DONE]
[13:45] kr:cdist%

No diff:

[root@kr ~]# diff -u /var/lib/cdist/out/object/__process/usr/lib/postfix/master/.cdist/code-remote /root/postfix-test
[root@kr ~]#

Same permissons:

[root@kr ~]# ls -l /var/lib/cdist/out/object/__process/usr/lib/postfix/master/.cdist/code-remote /root/postfix-test
-rwx------ 1 root root 24 28. Mär 13:39 /root/postfix-test
-rwx------ 1 root root 24 28. Mär 13:43 /var/lib/cdist/out/object/__process/usr/lib/postfix/master/.cdist/code-remote
[root@kr ~]#
Comment by Nico Schottelius (telmich) - Monday, 28 March 2011, 12:01 GMT
[root@kr ~]# rm -f /root/postfix-test2

[root@kr ~]# cp /var/lib/cdist/out/object/__process/usr/lib/postfix/master/.cdist/code-remote /root/postfix-test2
[13:52] kr:cdist% ssh root@localhost "/root/postfix-test2"
:: Starting Postfix [BUSY] [DONE]

# copying it over works.

Comment by Nico Schottelius (telmich) - Monday, 28 March 2011, 12:02 GMT
Calling the generated file directly works as well:


[root@kr ~]# /var/lib/cdist/out/object/__process/usr/lib/postfix/master/.cdist/code-remote
:: Starting Postfix [BUSY] postfix/postfix-script: starting the Postfix mail system
[DONE]
[root@kr ~]#
Comment by Nico Schottelius (telmich) - Monday, 28 March 2011, 12:09 GMT
Yeah, getting more confused, probably cannot top it anymore:

[root@kr ~]# ln -s /var/lib/cdist/out/object/__process/usr/lib/postfix/master/.cdist/code-remote /root/

[13:54] kr:cdist% ssh root@localhost "/root/code-remote"
:: Starting Postfix [BUSY] [DONE]
[14:01] kr:cdist%

Comment by Nico Schottelius (telmich) - Monday, 28 March 2011, 12:14 GMT
Trying to copy it in the same folder makes it fail:


[root@kr ~]# cp /var/lib/cdist/out/object/__process/usr/lib/postfix/master/.cdist/code-remote /var/lib/cdist/out/object/__process/usr/lib/postfix/master/.cdist/FOO

[14:01] kr:cdist% ssh root@localhost "/var/lib/cdist/out/object/__process/usr/lib/postfix/master/.cdist/FOO"
:: Starting Postfix [BUSY] [FAIL]

Linking into the same directory as well:
[root@kr ~]# ln -s /var/lib/cdist/out/object/__process/usr/lib/postfix/master/.cdist/code-remote /var/lib/cdist/out/object/__process/usr/lib/postfix/master/.cdist/FOO2
[root@kr ~]#
[14:03] kr:cdist% ssh root@localhost "/var/lib/cdist/out/object/__process/usr/lib/postfix/master/.cdist/FOO2"
:: Starting Postfix [BUSY] [FAIL]

# One level higher does not work as well:

[root@kr ~]# ln -s /var/lib/cdist/out/object/__process/usr/lib/postfix/master/.cdist/code-remote /var/lib/cdist/out/object/__process/usr/lib/postfix/master/FOO3
[14:04] kr:cdist% ssh root@localhost "/var/lib/cdist/out/object/__process/usr/lib/postfix/master/FOO3"
:: Starting Postfix [BUSY] [FAIL]

# Linking to cdist top level dir works though:

[root@kr ~]# ln -s /var/lib/cdist/out/object/__process/usr/lib/postfix/master/.cdist/code-remote /var/lib/cdist/FOO4
[14:05] kr:cdist% ssh root@localhost "/var/lib/cdist/FOO4"
:: Starting Postfix [BUSY] [DONE]


This definitely indicates some problem with either the directory structure or naming or permissions.

Comment by Nico Schottelius (telmich) - Monday, 28 March 2011, 12:19 GMT
[root@kr ~]# ln -s /var/lib/cdist/out/object/__process/usr/lib/postfix/master/.cdist/code-remote /var/lib/cdist/out/FOO5

[14:06] kr:cdist% ssh root@localhost "/var/lib/cdist/out/FOO5"
:: Starting Postfix [BUSY] [DONE]

[root@kr ~]# ln -s /var/lib/cdist/out/object/__process/usr/lib/postfix/master/.cdist/code-remote /var/lib/cdist/out/object/FOO6

[14:08] kr:cdist% ssh root@localhost /var/lib/cdist/out/object/FOO6
:: Starting Postfix [BUSY] [DONE]
[14:09] kr:cdist%


[root@kr ~]# ln -s /var/lib/cdist/out/object/__process/usr/lib/postfix/master/.cdist/code-remote /var/lib/cdist/out/object/__process/FOO7

[14:09] kr:cdist% ssh root@localhost /var/lib/cdist/out/object/__process/FOO7
:: Starting Postfix [BUSY] [DONE]

Further linking attempts:
[14:10] kr:cdist% ssh root@localhost /var/lib/cdist/out/object/__process/usr/FOO8
:: Starting Postfix [BUSY] [DONE]

[14:11] kr:cdist% ssh root@localhost /var/lib/cdist/out/object/__process/usr/lib/postfix/FOO9
:: Starting Postfix [BUSY] [DONE]


[14:11] kr:cdist% ssh root@localhost /var/lib/cdist/out/object/__process/usr/lib/postfix/FOO9
:: Starting Postfix [BUSY] [DONE]
[14:11] kr:cdist% ssh root@localhost /var/lib/cdist/out/object/__process/usr/lib/postfix/master/FOO10
:: Starting Postfix [BUSY] [FAIL]
[14:12] kr:cdist%

Got it! It stops working between FOO9 and FOO10.

The "only" question left is, why.
Comment by Nico Schottelius (telmich) - Monday, 28 March 2011, 12:21 GMT
it seems the directory name is what is not allowed by the posfix script:


[root@kr ~]# mkdir -p /tmp/usr/lib/postfix/master/
[root@kr ~]# ln -s /var/lib/cdist/out/object/__process/usr/lib/postfix/master/.cdist/code-remote /tmp/usr/lib/postfix/master/FOO11
[root@kr ~]#

[14:12] kr:cdist% ssh root@localhost /tmp/usr/lib/postfix/master/FOO11
:: Starting Postfix [BUSY] [FAIL]
[14:13] kr:cdist%
Comment by Nico Schottelius (telmich) - Monday, 28 March 2011, 12:22 GMT
Err, found the bug, was too easy!


PID=`pgrep -f /usr/lib/postfix/master`

Use pgrep -f -x, please.
Comment by Gaetan Bisson (vesath) - Monday, 28 March 2011, 12:58 GMT
Great that you find that issue out!
I'll cleanup the rc.d script and make it use pidof rather than pgrep.

Loading...