问题描述
我已经设置了一个 systemd.service,它会在系统启动时启动一个 bash 脚本。脚本启动,但似乎找不到引用的源文件,但是当我从终端启动相同的脚本时,我工作正常。所有脚本都在同一个目录中。
有人有任何建议来解决这个问题吗?
systemd.service 文件:
[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
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
源配置文件:
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"
源函数.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"
}
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)