通过远程 ssh 访问,我尝试创建一个 systemd 服务,如果之前没有创建服务,则创建一个新的服务,如果没有,则检查服务是否处于活动状态,然后停止它,更新服务并重新启动它。如果服务未处于活动状态,则更新服务并启动它。我尝试了以下操作。
- sshpass -p "password" ssh -o stricthostkeychecking=no -t -t user@ip "mkdir -p FROM_REMOTE/ABS/inlaks-gt-cashout/ && cd FROM_REMOTE/ABS/inlaks-gt-cashout/ && [[ ! -f service.sh ]] && echo 'java -jar inlaks-gtb-cashout-service-1.1.jar' > service.sh || echo 'File already exists'"
- sshpass -p "password" scp -o stricthostkeychecking=no target/inlaks-gtb-cashout-service-1.1.jar user@ip:FROM_REMOTE/ABS/inlaks-gt-cashout/
- sshpass -p "password" scp -o stricthostkeychecking=no service/inlaks-gt-cashout.service user@ip:FROM_REMOTE/SERVICES/
- sshpass -p "password" ssh -o stricthostkeychecking=no -t -t user@ip "cd /etc/systemd/system && [[ ! -f inlaks-gt-cashout.service ]] && sudo cp /home/asodad/FROM_REMOTE/SERVICES/inlaks-gt-cashout.service /etc/systemd/system/"
- sshpass -p "password" ssh -o stricthostkeychecking=no -t -t user@ip "systemctl is-active --quiet inlaks-gt-cashout.service systemctl stop inlaks-gt-cashout.service"
- sshpass -p "password" ssh -o stricthostkeychecking=no -t -t user@ip "cd /etc/systemd/system/ && sshpass -p 'password' sudo systemctl start inlaks-gt-cashout.service && sshpass -p 'password' sudo systemctl enable inlaks-gt-cashout.service && sshpass -p 'password' sudo systemctl daemon-reload"
我第一次成功了,但在随后的尝试中,我不断
无法启动 inlaks-gt-cashout.service:未找到单元 inlaks-gt-cashout.service。
我尝试过删除该服务并重新加载 systemctl,甚至尝试使用systemctl daemon-reload
并重置失败的单元,systemctl reset-failed
但结果相同。
打击是我的.service
文件
[Unit]
Description=Start Inlaks gt cash out service
After=network.target
[Service]
Type=simple
Restart=always
WorkingDirectory=/home/asodad/FROM_REMOTE/ABS/inlaks-gt-cashout
RestartSec=5
StartLimitInterval=0
User=asodad
ExecStart=/bin/bash /home/asodad/FROM_REMOTE/ABS/inlaks-gt-cashout/service.sh
[Install]
WantedBy=multi-user.target