cdist/cdist/conf/type/__consul_agent/files/consul.sysv-redhat

99 lines
2.0 KiB
Plaintext
Raw Normal View History

#!/bin/bash
#
# /etc/rc.d/init.d/consul
#
# Daemonize the consul agent.
#
# chkconfig: 2345 95 95
# description: Service discovery and configuration made easy. \
# Distributed, highly available, and datacenter-aware.
# processname: consul
# pidfile: /var/run/consul/pidfile
# Source function library.
2018-10-10 10:56:48 +00:00
2018-10-07 18:27:57 +00:00
# shellcheck disable=SC1091
. /etc/init.d/functions
NAME=consul
CONSUL=/usr/local/bin/consul
2018-10-10 10:56:48 +00:00
CONFIG="/etc/$NAME/conf.d"
PID_FILE="/var/run/$NAME/pidfile"
LOG_FILE="/var/log/$NAME"
2018-10-07 18:27:57 +00:00
# shellcheck disable=SC1090
2018-10-10 10:56:48 +00:00
[ -e "/etc/sysconfig/$NAME" ] && . "/etc/sysconfig/$NAME"
export GOMAXPROCS="${GOMAXPROCS:-2}"
2018-10-10 10:56:48 +00:00
mkdir -p "/var/run/$NAME"
chown consul:consul "/var/run/$NAME"
chmod 2770 "/var/run/$NAME"
start() {
2018-10-10 10:56:48 +00:00
printf "Starting %s: " "$NAME"
daemon --user=consul \
--pidfile="$PID_FILE" \
"$CONSUL" agent -pid-file="$PID_FILE" -config-dir "$CONFIG" >> "$LOG_FILE" &
retcode=$?
2018-10-10 10:56:48 +00:00
touch "/var/lock/subsys/$NAME"
return "$retcode"
}
stop() {
2018-10-10 10:56:48 +00:00
printf "Shutting down %s: " "$NAME"
killproc -p "$PID_FILE" "$NAME"
retcode=$?
2018-10-10 10:56:48 +00:00
rm -f "/var/lock/subsys/$NAME"
return "$retcode"
}
case "$1" in
start)
2018-10-10 10:56:48 +00:00
if status -p "$PID_FILE" "$NAME" >/dev/null; then
echo "$NAME already running"
else
start
fi
;;
stop)
2018-10-10 10:56:48 +00:00
if status -p "$PID_FILE" "$NAME" >/dev/null; then
stop
else
echo "$NAME not running"
fi
;;
info)
"$CONSUL" info
;;
status)
2018-10-10 10:56:48 +00:00
status -p "$PID_FILE" "$NAME"
exit $?
;;
restart)
2018-10-10 10:56:48 +00:00
if status -p "$PID_FILE" "$NAME" >/dev/null; then
stop
fi
start
;;
reload)
2018-10-10 10:56:48 +00:00
if status -p "$PID_FILE" "$NAME" >/dev/null; then
2018-10-07 18:27:57 +00:00
kill -HUP "$(cat "$PID_FILE")"
else
echo "$NAME not running"
fi
;;
condrestart)
2018-10-10 10:56:48 +00:00
if [ -f "/var/lock/subsys/$NAME" ]; then
if status -p "$PID_FILE" "$NAME" >/dev/null; then
stop
fi
start
fi
;;
*)
echo "Usage: $NAME {start|stop|status|reload|restart|condrestart|info}"
exit 1
;;
esac
exit $?