[root@bd043 init.d]# cat elasticsearch #!/bin/sh # elasticsearch Startup script for the elasticsearch # # chkconfig: 2345 80 05 # description: The elasticsearch will store data # processname: elasticsearch ### BEGIN INIT INFO # Provides: elasticsearch # Required-Start: $all # Required-Stop: $remote_fs $syslog # Default-Start: 2 3 4 5 # Default-Stop: 0 1 6 # Short-Description: Start elasticsearch at boot time ### END INIT INFO DESC="ES" SEVICE_NAME=elasticsearch PIDFILE=/var/run/$NAME.pid RUN_AS=es COMMAND="/home/es/es_for_cmdb/elasticsearch/bin/elasticsearch" es_start() { if [ -e $PIDFILE ] then echo "$SEVICE_NAME is running..." else start-stop-daemon --start --quiet --background --make-pidfile --pidfile $PIDFILE --chuid $RUN_AS --exec $COMMAND echo "Starting $DESC: $SEVICE_NAME" fi } es_stop() { start-stop-daemon --stop --quiet --pidfile $PIDFILE if [ -e $PIDFILE ] then rm $PIDFILE fi } es_status() { if [ -e $PIDFILE ] then echo "$SEVICE_NAME is running..." else echo "$SEVICE_NAME not run!" fi } case $1 in start) es_start echo "ok!" ;; stop) echo "Stopping $DESC: $SEVICE_NAME" es_stop echo "ok!" ;; restart) echo "Restarting $DESC: $SEVICE_NAME" es_stop sleep 1 es_start echo "ok!" ;; status) es_status ;; *) echo "usage: /etc/init.d/$SEVICE_NAME {start|stop|status|restart}" exit 1 ;; esac exit 0