-
cd /etc/init.d
进入目录
- 创建文件eshead,把下面内容粘贴进去,修改对应的环境变量java/node等
#!/bin/bash
#
#chkconfig: 345 63 37
#description: elasticsearch-head-master
#processname: elasticsearch-head-master
export NODE_HOME=/usr/local/node-v15.5.0-linux-x64
export JAVA_HOME=/usr/local/jdk1.8.0_271
export CLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar
export NODE_PATH=$NODE_HOME/lib/node_modules
export PATH=$PWD/bin:/usr/local/openresty/nginx/sbin:$JAVA_HOME/bin:$NODE_HOME/bin:$PATH
ESHEAD_HOME=/usr/local/elasticsearch-head-master/
case $1 in
start)
cd $ESHEAD_HOME
nohup grunt server 2>&1 &
echo "eshead is started"
;;
stop)
pid=`lsof -t -i:9100`
kill -9 $pid
echo "eshead is stop"
;;
restart)
pid=`lsof -t -i:9100`
kill -9 $pid
echo "eshead is stopped"
sleep 1
cd $ESHEAD_HOME
nohup grunt server 2>&1 &
echo "eshead is started"
;;
*)
echo "start|stop|restart"
;;
esac
exit 0
- 给脚本添加权限
chmod 755 eshead
- 添加服务到开机项
chkconfig --add eshead
- 设置为开机启动
chkconfig eshead on
- 测试
service eshead start