ubuntu22.04开机自启动Eureka服务
1、创建启动脚本eurekaService.sh
shell
#我们把启动脚本放在/usr/software目录下
cd /usr/software
vim eurekaService.sh
eurekaService.sh内容为
shell
#!/bin/sh
# this is a eurekaService shell to startup at the mechian power on.
echo "eurekaServer-0.0.1-SNAPSHOT.jar service start loading..."
nohup java -jar /usr/software/eurekaServer-0.0.1-SNAPSHOT.jar > /usr/software/log.txt 2>&1 &
echo "eurekaService loads successful"
2、赋予可执行权限
shell
chmod 777 eurekaService.sh
3、新建要启动的Eureka服务文件
shell
#新建要启动的服务文件
vim /etc/systemd/system/eureka.service
eureka.service内容为
shell
[Unit]
Description=this is eurekaService
After=network.target
[Service]
Type=forking
ExecStart=/usr/software/eurekaService.sh #指定上面创建的脚步文件路径
[Install]
WantedBy=multi-user.target #多用户
4、启动Eureka服务
shell
#让系统获取到你刚自定义的service文件并设置开机启动
systemctl daemon-reload
systemctl start eureka.service
systemctl enable eureka.service
#查看日志
systemctl status eureka.service