Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Debian: /var/run/consul/consul.pid user affinity inconsistent #120

Closed
weitzj opened this issue May 18, 2015 · 10 comments
Closed

Debian: /var/run/consul/consul.pid user affinity inconsistent #120

weitzj opened this issue May 18, 2015 · 10 comments

Comments

@weitzj
Copy link
Contributor

weitzj commented May 18, 2015

The init template for Debian uses start-stop-daemon to create a pidfile owned by the daemon user root. https://github.com/solarkennedy/puppet-consul/blob/master/templates/consul.debian.erb#L57

But:

It passes the -pid-file parameter along to the consul agent. See: https://github.com/solarkennedy/puppet-consul/blob/master/templates/consul.debian.erb#L21

This causes the launch of the consul agent to fail, since it cannot write to /var/run/consul/consul.pid using the user:group => consul:consul

There are 2 solutions:

  • Make /var/run/consul/consul.pid writeable by the consul user, which runs consul agent
  • Let start-stop-daemon write the pid to /var/run/consul/consul.pid (this means removing the pid-file param from consul agent
@weitzj
Copy link
Contributor Author

weitzj commented May 19, 2015

The PR implements the second solution, since NGINX does it this way, too. It also fixes a status check bug.

@EvanKrall
Copy link
Contributor

Couldn't you instead remove --make-pidfile from the start-stop-daemon args? Is it actually preferable to have start-stop-daemon manage the pidfile?

@weitzj
Copy link
Contributor Author

weitzj commented May 21, 2015

Yeah, we could do that. I was just inspired by the nginx file on my debian machine, which looks almost the same as the current puppet-consul debian file. https://github.com/solarkennedy/puppet-consul/blob/master/templates/consul.debian.erb#L21

Do you want me to implement the other solution instead?

@EvanKrall
Copy link
Contributor

I don't really have strong opinions either way.

@weitzj
Copy link
Contributor Author

weitzj commented May 21, 2015

Nginx script Debine Weezy

e.g.: https://blog.luukhendriks.eu/2013/05/17/nginx-initscript-debian-7.html

#!/bin/sh

### BEGIN INIT INFO
# Provides:          nginx
# Required-Start:    $local_fs $remote_fs $network $syslog
# Required-Stop:     $local_fs $remote_fs $network $syslog
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
# Short-Description: starts the nginx web server
# Description:       starts nginx using start-stop-daemon
### END INIT INFO

PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
DAEMON=/usr/sbin/nginx
NAME=nginx
DESC=nginx

# Include nginx defaults if available
if [ -f /etc/default/nginx ]; then
    . /etc/default/nginx
fi

test -x $DAEMON || exit 0

set -e

. /lib/lsb/init-functions

test_nginx_config() {
    if $DAEMON -t $DAEMON_OPTS >/dev/null 2>&1; then
        return 0
    else
        $DAEMON -t $DAEMON_OPTS
        return $?
    fi
}

case "$1" in
    start)
        echo -n "Starting $DESC: "
        test_nginx_config
        # Check if the ULIMIT is set in /etc/default/nginx
        if [ -n "$ULIMIT" ]; then
            # Set the ulimits
            ulimit $ULIMIT
        fi
        start-stop-daemon --start --quiet --pidfile /var/run/$NAME.pid \
            --exec $DAEMON -- $DAEMON_OPTS || true
        echo "$NAME."
        ;;

    stop)
        echo -n "Stopping $DESC: "
        start-stop-daemon --stop --quiet --pidfile /var/run/$NAME.pid \
            --exec $DAEMON || true
        echo "$NAME."
        ;;

    restart|force-reload)
        echo -n "Restarting $DESC: "
        start-stop-daemon --stop --quiet --pidfile \
            /var/run/$NAME.pid --exec $DAEMON || true
        sleep 1
        test_nginx_config
        # Check if the ULIMIT is set in /etc/default/nginx
        if [ -n "$ULIMIT" ]; then
            # Set the ulimits
            ulimit $ULIMIT
        fi
        start-stop-daemon --start --quiet --pidfile \
            /var/run/$NAME.pid --exec $DAEMON -- $DAEMON_OPTS || true
        echo "$NAME."
        ;;

    reload)
        echo -n "Reloading $DESC configuration: "
        test_nginx_config
        start-stop-daemon --stop --signal HUP --quiet --pidfile /var/run/$NAME.pid \
            --exec $DAEMON || true
        echo "$NAME."
        ;;

    configtest|testconfig)
        echo -n "Testing $DESC configuration: "
        if test_nginx_config; then
            echo "$NAME."
        else
            exit $?
        fi
        ;;

    status)
        status_of_proc -p /var/run/$NAME.pid "$DAEMON" nginx && exit 0 || exit $?
        ;;
    *)
        echo "Usage: $NAME {start|stop|restart|reload|force-reload|status|configtest}" >&2
        exit 1
        ;;
esac

exit 0

@weitzj
Copy link
Contributor Author

weitzj commented May 21, 2015

We could actually implement a real reload command, sending HUP, which is missing in the current solution

@EvanKrall
Copy link
Contributor

Real reload would be nice too, but doesn't necessarily have to happen in the same PR.

@weitzj
Copy link
Contributor Author

weitzj commented May 21, 2015

Yes. One should not highjack this on here. :)

@weitzj
Copy link
Contributor Author

weitzj commented May 21, 2015

Please review again. Added CHANGELOG

@EvanKrall
Copy link
Contributor

Merged! Thanks for the PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants