I am currently porting all my crontab configs into systemd-services, i.e. creating units for tasks that needs to autostart on my computers.
One of these units is giving me a headache. I called it "uplink.service", it's purpose is to call a script that builds a reverse ssh tunnel to my server and establishes that. This is the unit I created:
[Unit] Description = SSH-Uplink After = network.target [Service] ExecStart = /bin/bash /root/script/uplink.sh [Install] WantedBy = multi-user.target
This is the script the unit points to:
ssh -fNC -R XXXX:localhost:22 user@ip -pXXXX -i ~/script/id_rsa touch /tmp/uplinkonline
As you can see, for debugging this script tries to make a new file called uplinkonline in /tmp. This works; the file is created after starting the service, so the script itself is successfully called.
And this is the output of systemctl after trying to start it:
uplink.service - SSH-Uplink Loaded: loaded (/etc/systemd/system/uplink.service; disabled; vendor preset: disabled) Active: inactive (dead) Nov 07 10:44:01 loki systemd: Started SSH-Uplink.
The script itself works while starting it manually or calling it by startup via crontab. But somehow systemd seems to expect a different behaviour and exits, without starting the SSH connection. Where did I go wrong?