Created
January 30, 2017 09:49
-
-
Save adionditsak/01cb91b1a0e74ce98007ee7e1c253d51 to your computer and use it in GitHub Desktop.
vault startup/service script (ubuntu 14)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# | |
# Daemon for vault | |
# | |
# chkconfig: 345 99 20 | |
# description: Daemon for vault | |
# processname: vault | |
### BEGIN INIT INFO | |
# Provides: vault | |
# Required-Start: $network | |
# Required-Stop: | |
# Should-Start: | |
# Should-Stop: | |
# Default-Start: 3 4 5 | |
# Default-Stop: 0 1 6 | |
# Short-Description: start and stop vault | |
# Description: Daemon for vault | |
### END INIT INFO | |
VAULT_PATH="/usr/local/bin/vault" | |
VAULT_CONFIG="/etc/vault/vault.hcl" | |
VAULT_STARTUP_LOG="/var/log/vault_startup.log" | |
start() { | |
$VAULT_PATH server -config=$VAULT_CONFIG 2>&1 >> $VAULT_STARTUP_LOG & | |
return $? | |
} | |
stop() { | |
# Seal the vault before stopping | |
$VAULT_PATH seal -address=http://$(cat $VAULT_CONFIG |awk '/address/ {x=$3} END {print x}'|sed 's/"//g') | |
# Get the process number and kill the process | |
kill $(ps -C vault|awk 'END {print $1}') | |
return $? | |
} | |
status() { | |
if [ -z $(ps -C vault|awk 'END {print $1}'|grep -v PID) ]; then | |
echo "Vault is not running." | |
return 3 | |
else | |
$VAULT_PATH status -address=http://$(cat $VAULT_CONFIG |awk '/address/ {x=$3} END {print x}'|sed 's/"//g') | |
fi | |
return 0 | |
} | |
seal () { | |
if [ -z $(ps -C vault|awk 'END {print $1}'|grep -v PID) ]; then | |
echo "Vault is not running." | |
return 3 | |
else | |
$VAULT_PATH seal -address=http://$(cat $VAULT_CONFIG |awk '/address/ {x=$3} END {print x}'|sed 's/"//g') | |
return $? | |
fi | |
} | |
case "$1" in | |
start) | |
start | |
RETVAL=$? | |
;; | |
stop) | |
stop | |
RETVAL=$? | |
;; | |
status) | |
status | |
RETVAL=$? | |
;; | |
seal) | |
seal | |
RETVAL=$? | |
;; | |
*) | |
echo $"Usage: vault {start|stop|status|seal}" | |
RETVAL=2 | |
;; | |
esac | |
exit $RETVAL |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment