Improve quoting.

This commit is contained in:
Darko Poljak 2018-10-10 12:56:48 +02:00
parent 610deba454
commit 7a9dea9754

View file

@ -11,51 +11,52 @@
# pidfile: /var/run/consul/pidfile # pidfile: /var/run/consul/pidfile
# Source function library. # Source function library.
# shellcheck disable=SC1091 # shellcheck disable=SC1091
. /etc/init.d/functions . /etc/init.d/functions
NAME=consul NAME=consul
CONSUL=/usr/local/bin/consul CONSUL=/usr/local/bin/consul
CONFIG=/etc/$NAME/conf.d CONFIG="/etc/$NAME/conf.d"
PID_FILE=/var/run/$NAME/pidfile PID_FILE="/var/run/$NAME/pidfile"
LOG_FILE=/var/log/$NAME LOG_FILE="/var/log/$NAME"
# shellcheck disable=SC1090 # shellcheck disable=SC1090
[ -e /etc/sysconfig/$NAME ] && . /etc/sysconfig/$NAME [ -e "/etc/sysconfig/$NAME" ] && . "/etc/sysconfig/$NAME"
export GOMAXPROCS=${GOMAXPROCS:-2} export GOMAXPROCS="${GOMAXPROCS:-2}"
mkdir -p /var/run/$NAME mkdir -p "/var/run/$NAME"
chown consul:consul /var/run/$NAME chown consul:consul "/var/run/$NAME"
chmod 2770 /var/run/$NAME chmod 2770 "/var/run/$NAME"
start() { start() {
printf "Starting %s" "$NAME: " printf "Starting %s: " "$NAME"
daemon --user=consul \ daemon --user=consul \
--pidfile="$PID_FILE" \ --pidfile="$PID_FILE" \
"$CONSUL" agent -pid-file="$PID_FILE" -config-dir "$CONFIG" >> "$LOG_FILE" & "$CONSUL" agent -pid-file="$PID_FILE" -config-dir "$CONFIG" >> "$LOG_FILE" &
retcode=$? retcode=$?
touch /var/lock/subsys/$NAME touch "/var/lock/subsys/$NAME"
return $retcode return "$retcode"
} }
stop() { stop() {
printf "Shutting down %s" "$NAME: " printf "Shutting down %s: " "$NAME"
killproc -p "$PID_FILE" $NAME killproc -p "$PID_FILE" "$NAME"
retcode=$? retcode=$?
rm -f /var/lock/subsys/$NAME rm -f "/var/lock/subsys/$NAME"
return $retcode return "$retcode"
} }
case "$1" in case "$1" in
start) start)
if status -p "$PID_FILE" $NAME >/dev/null; then if status -p "$PID_FILE" "$NAME" >/dev/null; then
echo "$NAME already running" echo "$NAME already running"
else else
start start
fi fi
;; ;;
stop) stop)
if status -p "$PID_FILE" $NAME >/dev/null; then if status -p "$PID_FILE" "$NAME" >/dev/null; then
stop stop
else else
echo "$NAME not running" echo "$NAME not running"
@ -65,25 +66,25 @@ case "$1" in
"$CONSUL" info "$CONSUL" info
;; ;;
status) status)
status -p "$PID_FILE" $NAME status -p "$PID_FILE" "$NAME"
exit $? exit $?
;; ;;
restart) restart)
if status -p "$PID_FILE" $NAME >/dev/null; then if status -p "$PID_FILE" "$NAME" >/dev/null; then
stop stop
fi fi
start start
;; ;;
reload) reload)
if status -p "$PID_FILE" $NAME >/dev/null; then if status -p "$PID_FILE" "$NAME" >/dev/null; then
kill -HUP "$(cat "$PID_FILE")" kill -HUP "$(cat "$PID_FILE")"
else else
echo "$NAME not running" echo "$NAME not running"
fi fi
;; ;;
condrestart) condrestart)
if [ -f /var/lock/subsys/$NAME ]; then if [ -f "/var/lock/subsys/$NAME" ]; then
if status -p "$PID_FILE" $NAME >/dev/null; then if status -p "$PID_FILE" "$NAME" >/dev/null; then
stop stop
fi fi
start start