进入系统目录 /usr/lib/systemd/system
新建文件 tomcat7.service
文件内容如下
[Unit]
Description=Apache Tomcat 7
After=syslog.target network.target
[Service]
Type=forking
PIDFile=/opt/tomcat7/tomcat.pid
ExecStart=/opt/tomcat7/bin/startup.sh
ExecReload=/bin/kill -s HUP $MAINPID
ExecStop=/bin/kill -s QUIT $MAINPID
PrivateTmp=true
User=tomcat7
Group=tomcat7
[Install]
WantedBy=multi-user.target
注册服务
sudo systemctl enable tomcat7.service
服务启动
sudo systemctl start/stop/restart tomcat7