I have set up a systemd.service that starts a bash script when the system boots. The script starts, but it seems that it cannot find the referenced source files but when i start the same script from the terminal i works fine. Al scripts are in one and the same directory.
Anyone have any suggestions to fix this?
systemd.service file:
[Unit]
Description=RIB
After=network-online.target
[Service]
Type=simple
ExecStart=/home/user/release/.scripts/start-script.sh start
Restart=on-failure
[Install]
WantedBy=multi-user.target
part of the start-script.sh
#!/bin/bash
source config.sh
source function.sh
check_connection #function
# GET LOCATION IN .JSON FILE
get_location #function
if [[ $? -ne 0 ]]
then
printf "%s\n""Can't get location\n\n"
else
printf "%s\n""Location successfully retrieved\n\n"
fi
source config.sh:
version="2021.01.25"
date=`date '+%Y-%m-%d %H:%M:%S'`
time=`date '+%H:%M:%S'`
temp_path="/home/$USER/temp"
release_path="/home/$USER/release"
info_path="$release_path/to/info"
content_path="$release_path/to/content"
ftp_url="ftp.test.com"
source function.sh:
function check_connection ()
{
printf "%s\n""${Green}Check connection with $ftp_url.${Color_Off}\n\n"
while ! timeout 0.2 ping -c 1 -n $ftp_url &> /dev/null
do
printf "%s\n""${Green}RIB cannot reach $ftp_url, check WIFI connection.${Color_Off}\n\n"
sleep 5
done
printf "%s\n""${Green}RIB can reach $ftp_url.${Color_Off}\n\n"
}
printf "%s\n"".- why is there no space? Didn't you meanprintf "%s\n" "..."?it seems that it cannot find the referenced source files"it seems"? From where? Do you have an error message?Anyone have any suggestions to fix this?What do you think current working directory of the script is when run from systemd?WorkingDirectory=/home/user/release/.scripts/to yoursystemd.servicefile. This sets the working directory for executed processes.get_locationfunction isn't defined anywhere.function, see wiki.bash-hackers.org/scripting/obsolete