[root@qwy ~]# cat /etc/init.d/elastisearch|grep -v '^#'#!/bin/bash
# chkconfig: 2345 55 25
# description: SSH is a protocol for secure remote shell access.
export JAVA_HOME=/usr/local/java/jdk/
export JAVA_BIN=/usr/local/java/jdk/bin
export PATH=$PATH:$JAVA_HOME/bin
export CLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar
export JAVA_HOME JAVA_BIN PATH CLASSPATH
case "$1" in
start)
su esuser<<!
cd /wxqyh/component/elasticsearch-6.2.2/
./bin/elasticsearch -d
!
echo "elasticsearch startup"
;;
stop)
es_pid=`ps aux|grep elasticsearch | grep -v 'grep elasticsearch' | awk '{print $2}'`
kill -9 $es_pid
echo "elasticsearch stopped"
;;
restart)
es_pid=`ps aux|grep elasticsearch | grep -v 'grep elasticsearch' | awk '{print $2}'`
kill -9 $es_pid
echo "elasticsearch stopped"
su esuser<<!
cd /wxqyh/component/elasticsearch-6.2.2/
./bin/elasticsearch -d
!
echo "elasticsearch startup"
;;
*)
echo "start|stop|restart"
;;
esac
exit $?
为启动脚本增加执行权限:chmod +x /etc/init.d/elasticsearch
配置开机启动es:chkconfig --add elasticsearch
[root@qwy ~]# cat /etc/init.d/activemq |grep -v '^#'#!/bin/bash
# chkconfig: 2345 55 25
# description: SSH is a protocol for secure remote shell access.
export JAVA_HOME=/usr/local/java/jdk/
export JAVA_BIN=/usr/local/java/jdk/bin
export PATH=$PATH:$JAVA_HOME/bin
export CLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar
export JAVA_HOME JAVA_BIN PATH CLASSPATH
export ACTIVEMQ_HOME=/wxqyh/component/apache-activemq-5.15.9/
case $1 in
start)
sh $ACTIVEMQ_HOME/bin/activemq start
;;
stop)
sh $ACTIVEMQ_HOME/bin/activemq stop
;;
status)
sh $ACTIVEMQ_HOME/bin/activemq status
;;
restart)
sh $ACTIVEMQ_HOME/bin/activemq stop
sleep 1
sh $ACTIVEMQ_HOME/bin/activemq start
;;
esac
exit 0
设置开机自动自动chkconfig activemq on
启动服务service activemq start
[root@qwy ~]# cat /lib/systemd/system/tomcatportal.service
[Unit]
Description=tomcat
After=network.target
[Service]
Environment="JAVA_HOME=/usr/local/java/jdk1.8.0_172"
Type=oneshot
ExecStart=/do1cloud/wxqyh/test/apache-tomcat-8.5.31_portal/bin/startup.sh
ExecStop=/do1cloud/wxqyh/test/apache-tomcat-8.5.31_portal/bin/shutdown.sh
ExecReload=/bin/kill -s HUP $MAINPID
RemainAfterExit=yes
[Install]
WantedBy=multi-user.target
(2).设置权限
chmod 754 tomcat.service
(3).启动关闭服务,设置开机启动
#启动服务
systemctl start tomcat.service
#关闭服务
systemctl stop tomcat.service
#开机启动
systemctl enable tomcat.service
用一个例子来演示会更加清晰