nginxinc/nginx-wiki

Example RedHat init script assumes you configured with --user

jeffkaufman opened this issue · 1 comments

The RedHat init script example has:

user=`$nginx -V 2>&1 | grep "configure arguments:" | sed 's/[^*]*--user=\([^ ]*\).*/\1/g' -`
if [ -z "`grep $user /etc/passwd`" ]; then
    useradd -M -s /bin/nologin $user
fi

The --user argument is optional, though, and the init script handles that case badly. As a minimum, it should probably be something like:

-user=`$nginx -V 2>&1 | grep "configure arguments:" | sed 's/[^*]*--user=\([^ ]*\).*/\1/g' -`
+user=`$nginx -V 2>&1 | grep "configure arguments:.*--user" | sed 's/[^*]*--user=\([^ ]*\).*/\1/g' -`
-if [ -z "`grep $user /etc/passwd`" ]; then
+if [ -n "$user" ] && [ -z "`grep $user /etc/passwd`" ]; then

Looking through the other init scripts to see if this bug is more widespread, none of them seem to be trying to add a user for --user, however, so maybe we don't need to be trying to create this directory at all?

Here's a pull request: #319