zhmg23

我们是如此的不同
资深运维工程师互荐群: 102123162

RHEL7/CentOS7下通过Systemd控制tomcat启动/停止/进程守护

例如:我要通过Systemd,控制tomcat的端口为7000的管理系统停止、启动,以及进程守护

创建服务文件,服务文件的位置
/etc/systemd/system

vi /etc/systemd/system/tomcat7000.service


# Systemd unit file for tomcat
[Unit]
Description=Apache Tomcat Web Application Container
After=syslog.target network.target

[Service]
Type=forking

Environment=JAVA_HOME=/usr/server/jdk8/jre
Environment=CATALINA_PID=/usr/server/tomcat-manage-7000/temp/tomcat.pid
Environment=CATALINA_HOME=/usr/server/tomcat-manage-7000
Environment=CATALINE_BASE=/usr/server/tomcat-manage-7000
Environment='CATALINE_OPTS=-Xms2G -Xmx2G -Xss256k -XX:PermSize=256m -XX:MaxPermSize=256m -XX:NewSize=256m -XX:MaxNewSize=256m -XX:SurvivorRatio=8 -XX:+UseParNewGC -XX:ParallelGCThreads=8 -XX:+CMSParallelRemarkEnabled -XX:CMSInitiatingOccupancyFraction=70 -XX:+UseCMSCompactAtFullCollection'
Environment='JAVA_OPTS=-Djava.awt.haedless=true -Djava.security.egd=file:/dev/./urandom'

ExecStart=/usr/server/tomcat-manage-7000/bin/startup.sh
ExecStop=/bin/kill -15 $MAINPID

User=tomcat
Group=tomcat

[Install]
WantedBy=multi-user.target


保存退出!

启动服务

# systemctl  start  tomcat7000.service

停止服务

# systemctl  stop  tomcat7000.service

查看服务状态

# systemctl  status tomcat7000.service


评论