centos7增加tomcat自启动

增加启动文件

vim /lib/systemd/system/tomcat.service

写入如下内容

[Unit]
Description=tomcat
After=network.target

[Service]
Type=oneshot
systemctl daemon-reloadxecStart=/home/tomcat9/bin/startup.sh
ExecStop=/home/tomcat9/bin/shutdown.sh
ExecReload=/bin/kill -s HUP $MAINPID
RemainAfterExit=yes

[Install]
WantedBy=multi-user.target/home/tomcat9/bin/startup.sh
ExecStop=/home/tomcat9/bin/shutdown.sh
ExecReload=/bin/kill -s HUP $MAINPID
RemainAfterExit=yes

[Install]
WantedBy=multi-user.target

 

上面的内容中标红的地方改成自己tomcat的解压目录,然后保存退出

赋权限

chmod 754 tomcat.service

重载系统服务列表

systemctl daemon-reload

修改自己catalina.sh

vim /home/tomcat9/bin/catalina.sh

在第99行加入如下代码

export JAVA_HOME=/home/jdk1.8.0_144
export JRE_HOME=/home/jdk1.8.0_144/jre

 

加入完成后大概如下,标红的事新加入的内容

#   LOGGING_MANAGER (Optional) Override Tomcat's logging manager
#                   Example (all one line)
#                   LOGGING_MANAGER="-Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager"
#
#   UMASK           (Optional) Override Tomcat's default UMASK of 0027
#
#   USE_NOHUP       (Optional) If set to the string true the start command will
#                   use nohup so that the Tomcat process will ignore any hangup
#                   signals. Default is "false" unless running on HP-UX in which
#                   case the default is "true"
# -----------------------------------------------------------------------------
export JAVA_HOME=/home/jdk1.8.0_144
export JRE_HOME=/home/jdk1.8.0_144/jre
# OS specific support.  $var _must_ be set to either true or false.
cygwin=false
darwin=false
os400=false
hpux=false
case "`uname`" in
CYGWIN*) cygwin=true;;
Darwin*) darwin=true;;
OS400*) os400=true;;
HP-UX*) hpux=true;;
esac


# resolve links - $0 may be a softlink
export JAVA_HOME=/home/jdk1.8.0_144
export JRE_HOME=/home/jdk1.8.0_144/jre
# OS specific support.  $var _must_ be set to either true or false.
cygwin=false
darwin=false
os400=false
hpux=false
case "`uname`" in
CYGWIN*) cygwin=true;;
Darwin*) darwin=true;;
OS400*) os400=true;;
HP-UX*) hpux=true;;
esac


# resolve links - $0 may be a softlink

 

保存退出后,通过下面命令将tomcat.service加入到开机自启动

systemctl enable tomcat.service 

手动启动和停止tomcat服务

#启动服务 
systemctl start tomcat.service   
#关闭服务   
systemctl stop tomcat.service

 

你可能感兴趣的:(Linux操作杂项)