Running the following commands in a shell runs without issues:
ssh user@machine systemctl status my-service.service
ssh user@machine sudo systemctl stop my-service.service
scp -r ./my-service/* user@machine:/home/user/my-service
ssh user@machine chmod +x /home/user/my-service/my-service
ssh user@machine sudo systemctl start my-service.service
ssh user@machine sudo systemctl status my-service.service
However, putting this in a deploy.sh
file results in none of the above being able to execute.
Errors:
- Invalid unit name "my-service" was escaped as "my-service\x0d" (maybe you should use systemd-escape?)
- Unit my-service\x0d.service could not be found.
- Invalid unit name "my-service.service" was escaped as "my-service.service\x0d" (maybe you should use systemd-escape?)
- Failed to stop my-service\x0d.service: Unit my-service.service\x0d.service not loaded. : No such file or directorynlock/
- chmod: cannot access '/home/user/my-service/my-service'$'\r': No such file or directory
- Invalid unit name "my-service.service" was escaped as "my-service.service\x0d" (maybe you should use systemd-escape?)
- Failed to start my-service.service\x0d.service: Unit my-service.service\x0d.service not found. Invalid unit name "my-service.service" was escaped as "my-service.service\x0d" (maybe you should use systemd-escape?)
- Unit my-service.service\x0d.service could not be found.
Some were broken up. It seems something related to escaping. For some reason adding a space at the end of the lines makes it sort of work but still not without errors.
Googling on the errors shows some hits about using --
and adding it together with the trailing space makes some commands work but still giving an escaping error.
I would lay dollars to doughnuts that you edited this file on or from a Windows machine.
Linux uses \x0a (ASCII code 10) to separate lines within a file (or script).
Windows uses the combination of \x0d ("Carriage_Return", ASCII code 13) and \x0a ("Line Feed", ASCII 10) to do the same job.
Give a Windows-edited file to a Linux machine and it sees every single line as having an extraneous \x0d on the end.
Get yourself a decent Windows editor (NotePad++ is free and very highly recommended) or learn how to use vi. Sure, it has its own learning curve, but some of its capabilities might surprise you!