JiuyeXD's Blog
九叶
九叶博主

越努力 越幸运

登录
夜间

Centos8 创建/启动服务 报错 Control process exited, code=exited status=203

1. 问题

1.1 描述

部署spring cloud项目开机自启脚本的时候遇到了报错

5月 31 10:27:20 localhost.noob systemd[1]: Starting springcloud - resource recovery service...
5月 31 10:27:20 localhost.noob systemd[1]: recovery.service: Control process exited, code=exited status=203
5月 31 10:27:20 localhost.noob systemd[1]: recovery.service: Failed with result 'exit-code'.
5月 31 10:27:20 localhost.noob systemd[1]: Failed to start springcloud - resource recovery service.

2. 解决方案

2.1 新建 启动/停止/重启服务的shell文件

2.1.1 启动 recovery-start
#!/bin/bash
javaOptions="-Dfile.encoding=utf-8 -Xms512m -Xmx1024m -XX:MetaspaceSize=128m -XX:MaxMetaspaceSize=512m"

nohup java $javaOptions -jar /recovery/ruoyi-gateway.jar >/dev/null 2>&1 & 
nohup java $javaOptions -jar /recovery/ruoyi-auth.jar >/dev/null 2>&1 & 
nohup java $javaOptions -jar /recovery/ruoyi-modules-system.jar >/dev/null 2>&1 & 
nohup java $javaOptions -jar /recovery/ruoyi-modules-gen.jar >/dev/null 2>&1 & 
nohup java $javaOptions -jar /recovery/ruoyi-modules-file.jar >/dev/null 2>&1 & 
nohup java $javaOptions -jar /recovery/ruoyi-modules-recovery.jar >/dev/null 2>&1 & 
2.1.2 停止 recovery-stop
#!/bin/bash

ps -ef | grep ruoyi | grep -v grep | cut -c 10-16 | xargs kill -9
2.1.3 重启 recovery-restart
#!/bin/bash
javaOptions="-Dfile.encoding=utf-8 -Xms512m -Xmx1024m -XX:MetaspaceSize=128m -XX:MaxMetaspaceSize=512m"

ps -ef | grep ruoyi | grep -v grep | cut -c 10-16 | xargs kill -9

nohup java $javaOptions -jar /recovery/ruoyi-gateway.jar >/dev/null 2>&1 & 
nohup java $javaOptions -jar /recovery/ruoyi-auth.jar >/dev/null 2>&1 & 
nohup java $javaOptions -jar /recovery/ruoyi-modules-system.jar >/dev/null 2>&1 & 
nohup java $javaOptions -jar /recovery/ruoyi-modules-gen.jar >/dev/null 2>&1 & 
nohup java $javaOptions -jar /recovery/ruoyi-modules-file.jar >/dev/null 2>&1 & 
nohup java $javaOptions -jar /recovery/ruoyi-modules-recovery.jar >/dev/null 2>&1 & 

2.2 创建 recovery.service 服务启动项

2.2.1 新建 recovery.service 服务文件

systemd有系统和用户区分

系统(/usr/lib/systemd/system/)

用户(/etc/lib/systemd/user/)

一般系统管理员手工创建的单元文件建议存放在/etc/systemd/system/目录下面。

vim /lib/systemd/system/recovery.service
[Unit]
Description=springcloud - resource recovery service
Documentation=https://qwq.ro
After=network.target
[Service]
Type=forking
ExecStart=/bin/bash /recovery/bin/recovery-start
ExecReload=/bin/bash /recovery/bin/recovery-restart
ExecStop=/bin/bash /recovery/bin/recovery-stop
PrivateTmp=true
[Install]
WantedBy=multi-user.target

3. 测试


```
systemctl daemon-reload			# 先进行文件生效配置
systemctl enable recovery.service	# 设置为开机启动
systemctl start recovery.service	# 启动nacos服务
systemctl stop recovery.service		# 停止nacos服务
```

![image.png](https://old.qwq.ro/usr/uploads/2021/05/2310004218.png)
THE END