You are not logged in.
I want to let my system automatically run a shell script when the system is booted . So I used systemctl to run it .
This is the systemd service file at /usr/lib/systemd/system/rc-local.service
[Unit]
Description="/etc/rc.d/* Compatibility"
[Service]
Type=forking
ExecStart=sh /etc/rc.d/ddns.sh
TimeoutSec=0
StandardInput=tty
RemainAfterExit=yes
[Install]
WantedBy=multi-user.targetAnd this is the file at /etc/rc.d/ddns.sh
#!/bin/bash
while true
do
python /home/would/aliyun-ddns-client/ddns.py >> /dev/null 2>&1 &
sleep 600
doneI actually don't quite understand the content at rc-local.service. I copied it from the internet . And I don't know if it is 100% suitable right here ...
But , It did work when I use the same way to auto run this script :
#!/bin/bash
sudo -u would transmission-daemon && sleep 5 && transmission-remote 9097 -n NAME:PASSWORD -tall -sSo I start to think , is it possible that in this way , systemd can not run the sleep command in shell script ?
Then I wrote this :
#!/bin/bash
while true
do
echo "a" > /zzz/coming
sleep 10
echo "I was here" > /zzz/see.txt
python /home/would/aliyun-ddns-client/ddns.py >> /dev/null 2>&1 &
echo "I was here,too" > /zzz/zee.txt
sleep 10
echo "I was here as well" > /zzz/wee.txt
doneAfter reboot I checked /zzz :
[would@one zzz]$ sleep 30
[would@one zzz]$ ll
total 8
drwxrwxrwx 2 root root 4096 Dec 24 00:01 ./
drwxr-xr-x 24 root root 4096 Dec 8 11:49 ../
-rw-r--r-- 1 would would 0 Dec 24 00:01 comingMaybe I have made a bad mistake from the start , but I really need to know how to run this script properly . Correct me below , thanks .
Last edited by 1ndeed (2018-12-24 07:38:58)
Offline
You set Type=forking. Read the man page for what that means - your script doesn't fork. Systemd likely kills the process after a short time (especially with TimeoutSec set to 0!)
As for the script it's crap to start with. Why run a shell to run a python script which does something unspecified (likely just in turn run shell commands)? Use one of the provided services:
https://wiki.archlinux.org/index.php/Dynamic_DNS
Alternatively, if this python script is actually good, use a systemd timer to launch it. That's what timers are for, don't use a script with a loop and sleep.
EDIT: I just looked up that ddns tool, and it includes a proper service and timer:
https://github.com/rfancn/aliyun-ddns-client
Last edited by Trilby (2018-12-23 16:36:29)
"UNIX is simple and coherent" - Dennis Ritchie; "GNU's Not Unix" - Richard Stallman
Offline
I was such a fool . I used exactly the same python script you posted , but I didn't check the .timer and .service file ... lol ...
Anyway , your thought is right . After reading wiki , I now wrote a ddns.timer file , And It's going well .
Thank you very much !!!
Offline