Created
December 12, 2019 11:55
-
-
Save bejean/143681822f8cc89efaea0ed1c0dbbb21 to your computer and use it in GitHub Desktop.
elasticsearch init.d script
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
#!/bin/bash | |
# | |
# elasticsearch Start/Stop elasticsearch server. | |
# | |
# chkconfig: 35 99 01 | |
# description: elasticsearch server | |
# | |
# processname: elasticsearch | |
# | |
# change this value as necessary | |
RUNAS=elasticsearch | |
ES_HOME=/opt/elasticsearch/elasticsearch | |
export ES_PATH_CONF=/opt/elasticsearch/config | |
if [ -n "$RUNAS" ]; then | |
# verify the specified run as user exists | |
runas_uid="`id -u "$RUNAS"`" | |
if [ $? -ne 0 ]; then | |
echo "Utilisteur $RUNAS non trouvé !" | |
exit 1 | |
fi | |
fi | |
start() { | |
echo -n "Démarrage elasticsearch serveur" | |
echo | |
if [ -f $ES_HOME/elasticsearch.pid ]; then | |
echo "Fichier $ES_HOME/elasticsearch.pid existe déjà !" | |
exit 1 | |
else | |
cd $ES_HOME | |
if [ -n "$RUNAS" ] && [ "$(whoami)" != "$RUNAS" ]; then | |
su -c "export ES_PATH_CONF=$ES_PATH_CONF; $ES_HOME/bin/elasticsearch -d -p $ES_HOME/elasticsearch.pid" - "$RUNAS" | |
else | |
$ES_HOME/bin/elasticsearch -d -p $ES_HOME/elasticsearch.pid | |
fi | |
fi | |
} | |
stop() { | |
echo -n $"Arrêt elasticsearch serveur" | |
echo | |
if [ -f $ES_HOME/elasticsearch.pid ]; then | |
kill -9 `cat $ES_HOME/elasticsearch.pid` | |
rm -f $ES_HOME/elasticsearch.pid | |
else | |
echo "Fichier $ES_HOME/elasticsearch.pid non trouvé !" | |
exit 1 | |
fi | |
} | |
restart() { | |
stop | |
sleep 5 | |
start | |
} | |
case "$1" in | |
start) | |
start | |
;; | |
stop) | |
stop | |
;; | |
restart) | |
restart | |
;; | |
*) | |
echo $"Usage: $0 {start|stop|restart}" | |
exit 1 | |
;; | |
esac | |
exit $? |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment