LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 02-17-2014, 08:16 AM   #1
linuxecho
LQ Newbie
 
Registered: Feb 2014
Posts: 8

Rep: Reputation: Disabled
init script successfully triggers daemon process but doesn't create pid file -Deb7


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
 
Old 02-17-2014, 10:45 AM   #2
linuxecho
LQ Newbie
 
Registered: Feb 2014
Posts: 8

Original Poster
Rep: Reputation: Disabled
Errrm...ahem. I've now read the manual for the start stop daemon tool and it would seem that it doesn't actually create the pidfile unless you specify the -make-pidfile option. Ironic cheers all round. And even if you do use that option, it doesn't actually delete the pidfile when you use the stop command. Sorry, I kind of assumed that this kind of thing was being handled by the start-stop-daemon as default, though on reflection that is a silly assumption, particularly as my init script explicitly handles its removal rather than relying on the start stop daemon for that - I now realise that most processes handle their own pidfile creation and deletion.
However although my init script currently handles the deletion of the pidfile on successful stop, I'm guessing that getting the daemon itself to handle the creation and removal of its pid is the preferred option rather than relying on the start stop daemon and the initscript respectively as its more portable and more reliable.
I don't know how exactly to grab the environment variable from the start-stop-daemon within the daemon itself, but I'll have a look into that.... I suppose I could grep for it or something but I imagine that is a horrible hack and there is a more elegant way...
So I've solved my own non issue again. I'm having a great dialogue with myself here Its a real pity I can't mark my own comments as helpful and gain reputation I'd be a guru or something in no time (I'm joking of course, for those of you that may be serious minded - you never know).

Last edited by linuxecho; 02-17-2014 at 11:12 AM.
 
1 members found this post helpful.
  


Reply

Tags
daemon, init script, pid, start, stop



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Script to check PID from file and check whether process is running or not rajkiran183 Linux - Newbie 5 10-19-2012 11:28 AM
init script (stop) doesn't remove process IDs tdnnash25 Linux - Server 3 12-23-2009 09:01 PM
CentOS 4 (Fedora Core) init script - create PID file cejennings_cr Linux - Newbie 1 07-10-2006 08:22 AM
starting script, init by copy/create file in (samba) folder? muab Linux - General 7 06-22-2005 06:02 PM
How can I create a pid file from a backgournd process that I start? Hackiller Linux - General 3 05-12-2004 02:37 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 02:39 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration