I am trying to use an initscript to run some rsyncing via inotifywait. In true newbie style I have borrowed an initscript of the web and have edited the inputs to suit (though I have read over it to understand how it works).
All is well to the extent that when I start the machine under run levels 2 or 3 the daemon that I have written is indeed triggered as expected – I can verify that if I edit a file in one test folder, it gets rsynced instantly to another folder which is what the daemon is set up to acheive at the minute.
The problem is that this script does not appear to be creating a pid file and hence I cannot stop the service by calling
Code:
sudo /etc/init.d/websites_send_backups stop
(whether I’m root or not. Running that command gives
Quote:
[ok] websites_send_backups process is not running
|
which is set to be echoed when the pid can’t found and stop is called – and I can verify that the relevant pid file is not in /var/run. I shouldn’t need to start/stop the service that much but I would like to be able to use the start stop syntax rather than searching for the process id using the name and killing from there. I get the same behaviour when I invoke the initscript from a shell in the foreground.
Disclaimer – I’m fresh to shell scripting so all sorts of scripting errors could be under my nose without my necessarily being aware of them.
This is on Debian Wheezy Release 7.4.
What I have tried:
• Reading the daemon log file (couldn’t even find a reference to website_send_backups), did a cat /var/log/daemon.log |grep website on it too to make sure.
• Perusing various other log files just in case again nothing caught my eye.
• Verified the daemon is truly responsible for triggering the inotifywait watch and therefore the initscript must be being invoked as expected by removing the website_send_backups using rc.update and rebooting – upon which as expected the rsyncing on close_write no longer occurs.
• Run ps –ef|grep websites_send_backups and ps –ef|grep websites_send_backupsd to find out what processes have been spawned under that name (see below).
• Checked the options provided by my initscript do indeed appear to be those specified in the manual.
• :Alternating the ‘provides’ line between the daemon name and the initscript name - though I think that’s just what gets printed to the terminal and is therefore more or less irrelevant (just wanted to say I’d edited something since the problem really) .
• Errmm...thats it. Thrown up my hands and started typing this post.
Here’s my init-script and output of ps commands – please let me know if I can usefully post anything else.
Code:
# Provides: websites_send_backupsd
# Required-Start: $remote_fs $syslog rsync
# Required-Stop:
# Default-Start: 2 3
# Default-Stop: 0 1 4 5 6
# Short-Description: This daemon sends website backup files to where they're needed
# Description: This daemon uses inotifywait to monitor directories in the background
# and rsync them to a target when they are opened for writing and then closed again.
### END INIT INFO
#
# Using the lsb functions to perform the operations.
. /lib/lsb/init-functions
# Process name ( For display )
NAME=websites_send_backups
# Daemon name, where is the actual executable
DAEMON=/home/deploy/websites_send_backupsd
# pid file for the daemon
PIDFILE=/var/run/websites_send_backupsd.pid
#
# If the daemon is not there, then exit.
test -x $DAEMON || exit 5
case $1 in
start)
# Checked the PID file exists and check the actual status of process
if [ -e $PIDFILE ]; then
status_of_proc -p $PIDFILE $DAEMON "$NAME process" && status="0" || status="$?"
# If the status is SUCCESS then don't need to start again.
if [ $status = "0" ]; then
exit # Exit
fi
fi
# Start the daemon.
log_daemon_msg "Starting the process" "$NAME"
# Start the daemon with the help of start-stop-daemon
# Log the message appropriately
if start-stop-daemon --start --quiet --oknodo --pidfile $PIDFILE --exec $DAEMON ; then
log_end_msg 0
else
log_end_msg 1
fi
;;
stop)
# Stop the daemon.
if [ -e $PIDFILE ]; then
status_of_proc -p $PIDFILE $DAEMON "Stoppping the $NAME process" && status="0" || status="$?"
if [ "$status" = 0 ]; then
start-stop-daemon --stop --quiet --oknodo --pidfile $PIDFILE
/bin/rm -rf $PIDFILE
fi
else
log_daemon_msg "$NAME process is not running"
log_end_msg 0
fi
;;
restart)
# Restart the daemon.
$0 stop && sleep 2 && $0 start
;;
status)
# Check the status of the process.
if [ -e $PIDFILE ]; then
status_of_proc -p $PIDFILE $DAEMON "$NAME process" && exit 0 || exit $?
else
log_daemon_msg "$NAME Process is not running"
log_end_msg 0
fi
;;
reload)
# Reload the process. Basically sending some signal to a daemon to reload
# it configurations.
if [ -e $PIDFILE ]; then
start-stop-daemon --stop --signal USR1 --quiet --pidfile $PIDFILE --name $NAME
log_success_msg "$NAME process reloaded successfully"
else
log_failure_msg "$PIDFILE does not exists"
fi
;;
*)
# For invalid arguments, print the usage message.
echo "Usage: $0 {start|stop|restart|reload|status}"
exit 2
;;
esac
Output of command ps –ef |grep websites_send_backups psd:
Quote:
root 3185 3179 0 13:00 ? 00:00:00 /bin/sh /home/deploy/websites_send_backupsd
root 3187 3185 0 13:00 ? 00:00:00 /bin/sh /home/deploy/websites_send_backupsd
deploy 3513 3464 0 13:02 pts/1 00:00:00 grep websites_send_backupsd
|
Output of command ps –ef |grep websites_send_backups :
Quote:
root 3179 2046 0 13:00 ? 00:00:00 /bin/sh /etc/init.d/websites_send_backups start
root 3185 3179 0 13:00 ? 00:00:00 /bin/sh /home/deploy/websites_send_backupsd
root 3187 3185 0 13:00 ? 00:00:00 /bin/sh /home/deploy/websites_send_backupsd
deploy 3515 3464 0 13:03 pts/1 00:00:00 grep websites_send_backups
|