问题遇到的现象和发生背景
想给启动canal脚本startup.sh注册为服务,然后随着开机启动而启动
问题相关代码,请勿粘贴截图
运行结果及报错内容
1.启动systemctl start canal.service报错
● canal.service - canal
Loaded: loaded (/usr/lib/systemd/system/canal.service; enabled; vendor preset: disabled)
Active: failed (Result: exit-code) since Thu 2022-02-17 11:53:42 CST; 5s ago
Process: 2961 ExecStart=/home/canal/bin/startup.sh (code=exited, status=1/FAILURE)
Feb 17 11:53:41 localhost.localdomain systemd[1]: Starting canal...
Feb 17 11:53:41 localhost.localdomain startup.sh[2961]: which: no java in (/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin)
Feb 17 11:53:41 localhost.localdomain startup.sh[2961]: Cannot find a Java JDK. Please set either set JAVA or put java (>=1.5) in your PATH.
Feb 17 11:53:42 localhost.localdomain systemd[1]: canal.service: control process exited, code=exited status=1
Feb 17 11:53:42 localhost.localdomain systemd[1]: Failed to start canal.
Feb 17 11:53:42 localhost.localdomain systemd[1]: Unit canal.service entered failed state.
Feb 17 11:53:42 localhost.localdomain systemd[1]: canal.service failed.
目前我Java命令和Javac 命令在全局正常执行,正常安装Java环境
[root@localhost ~]# java -version
java version "11.0.10" 2021-01-19 LTS
2.查看已启动服务
[root@localhost canal]# systemctl list-units --type=service
UNIT LOAD ACTIVE SUB DESCRIPTION
● canal.service loaded failed failed canal
我的解答思路和尝试过的方法
1./usr/lib/systemd/system新增canal.service内容如下
[Unit]
Description=canal
After=network.target
[Service]
Type=forking
User=testaccount
# 此处的执行路径需要改为实际启动脚本路径
ExecStart=/home/canal/bin/startup.sh
PrivateTmp=true
# 指定此进程可以打开的最大文件数
LimitNOFILE=65535
# 指定此进程可以打开的最大进程数
LimitNPROC=65535
# 最大虚拟内存
LimitAS=infinity
# 最大文件大小
LimitFSIZE=infinity
# 超时设置 0-永不超时
TimeoutStopSec=0
# SIGTERM是停止java进程的信号
KillSignal=SIGTERM
# 信号只发送给给JVM
KillMode=process
# java进程不会被杀掉
SendSIGKILL=no
# 正常退出状态
SuccessExitStatus=143
[Install]
WantedBy=multi-user.target
然后刷新服务启动canal.service
systemctl daemon-reload
systemctl start canal.service
我想要达到的结果
canal注册为服务并随着系统启动而启动