Via remote ssh access I am trying to create a systemd service, if service was not created previously, create a new one if not check if the service is active and then stop it, update the service and restart it. if the service is not active then update the service and start it. I tried the following.
- 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"
I worked the first time but on subsequent trials, I keep getting
Failed to start inlaks-gt-cashout.service: Unit inlaks-gt-cashout.service not found.
I have tried removing the service and reloading the systemctl and even reset the failed units using systemctl daemon-reload
and systemctl reset-failed
but same result.
The blow is my .service
file
[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
systemctl is-active --quiet
withoutsudo
? In the other lines you put...