[英]Init Script Not Running On System Reboot/Shutdown
I have made a bash init script in file at /etc/init.d/redis-snapshot
:我在
/etc/init.d/redis-snapshot
文件中创建了一个 bash init 脚本:
#!/bin/bash
### BEGIN INIT INFO
# Provides: redis-snapshot
# Required-Start: $local_fs $syslog Stime redis-server
# Required-Stop: $local_fs $syslog $time redis-server
# Default-Start: 0 6
# Default-Stop: 2 3 4 5
# Short-Description: Backup redis data on system exit
# Description: redis-snapshot is a simple bash script to dump redis data
# to disk whenever the system shuts down or reboots.
### END INIT INFO
# path to script log file
ACTIVITYLOG='/home/noman/Desktop/redis-snapshot.log'
# create/touch log file
touch $ACTIVITYLOG
# invoke the save command on redis-cli
# this will dump all in-memory data to disk
OUTPUT="$(redis-cli SAVE)"
echo -e "$(date +'%Y-%m-%d %H:%M:%S %Z')\tSnapshoting Redis Data To Disk" >> $ACTIVITYLOG
echo -e "$(date +'%Y-%m-%d %H:%M:%S %Z')\tRedis says $OUTPUT" >> $ACTIVITYLOG
# end - nothing to do
I am using the following command to make it run on system reboot and shutdown:我正在使用以下命令使其在系统重新启动和关闭时运行:
sudo update-rc.d redis-snapshot start 99 0 6 .
It does not work for some reason and I am clueless what to try next.由于某种原因它不起作用,我不知道接下来要尝试什么。
Any bright ideas?有什么好主意吗?
What is your underlying distro and release?你的底层发行版和发行版是什么? Try
尝试
chkconfig --add redis-snapshot
If you wish to specifically find out whether your script is run, you may try skipping output redirection to file, so you'd see it during boot-up or checking /var/log/boot.log
after boot.如果您想特别确定您的脚本是否正在运行,您可以尝试跳过输出重定向到文件,这样您就可以在启动期间或在启动后检查
/var/log/boot.log
看到它。
If the output is missing, then your script was not added to /etc/rc#.d
.如果输出丢失,则您的脚本未添加到
/etc/rc#.d
。
An alternative method of running a script on startup (which I prefer) is via /etc/rc.local
.在启动时运行脚本的另一种方法(我更喜欢)是通过
/etc/rc.local
。 Eg:例如:
bash /root/script.sh
exit 0
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.