前言
为了更好的管理自己编写的小程序,可以将自己写的一些小工具直接注册为linux服务。下面,我就以tomcat注册为systemctl举例子
下载tomcat
在apack官网下载 tomcat-8.5.61 :https://tomcat.apache.org/download-80.cgi
然后通过xftp放到自己的目标目录
解压tomcat并且编辑
# 因为我下的tomcat是zip压缩的,所以先下一个unzip解压软件
yum install unzip
# 在目标目录解压
unzip apache-tomcat-8.5.61.zip
# 赋予权限755
# 一般简单赋予权限是755或者777
# 777是所有用户都有执行,读,写权限,755是root用可执行权限.文件所属用户和其它组用户没有执行权限!
# 这里考虑到最后会变成服务进行执行,就赋予了755权限
chmod 755 -R apache-tomcat-8.5.61/
# tomcat开启PID文件
cd apache-tomcat-8.5.61/bin
vi ./catalina.sh
修改 catalina.sh 文件,在 PRGDIR 下面一行添加 CATALINAPID 参数行,如下:
PRGDIR=dirname "$PRG"
CATALINA_PID=$PRGDIR/tomcat.pid
然后使用cat命令 修改如下:
cat catalina.sh
[root@localhost bin]# cat catalina.sh
#!/bin/sh
# Licensed to the Apache Software Foundation (ASF) under one or more
# contributor license agreements. See the NOTICE file distributed with
# this work for additional information regarding copyright ownership.
# The ASF licenses this file to You under the Apache License, Version 2.0
# (the "License"); you may not use this file except in compliance with
# the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governi