简体   繁体   中英

Init Script Not Running On System Reboot/Shutdown

I have made a bash init script in file at /etc/init.d/redis-snapshot :

#!/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.

If the output is missing, then your script was not added to /etc/rc#.d .

An alternative method of running a script on startup (which I prefer) is via /etc/rc.local . Eg:

bash /root/script.sh
exit 0

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM