[root@qwy ~]# cat /etc/init.d/elastisearch|grep -v '^#' export JAVA_HOME=/usr/local/java/jdk1.8.0_172 export JAVA_BIN=/usr/local/java/jdk1.8.0_172/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 /do1cloud/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 /do1cloud/wxqyh/component/elasticsearch-6.2.2/ ./bin/elasticsearch -d ! echo "elasticsearch startup" ;; *) echo "start|stop|restart" ;; esac exit $?
为启动脚本增加执行权限:chmod +x /etc/init.d/elastisearch
配置开机启动es:chkconfig --add elasticsearch
[root@qwy ~]# cat /etc/init.d/activemq |grep -v '^#' export JAVA_HOME='/usr/local/java/jdk1.8.0_172' export ACTIVEMQ_HOME=/do1cloud/wxqyh/component/soft/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 启动服务systemctl start activemq https://blog.csdn.net/u012326462/article/details/84899788
[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 https://www.cnblogs.com/taomylife/p/7992817.html