LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices


Reply
  Search this Thread
Old 07-15-2015, 02:58 PM   #1
dodul
LQ Newbie
 
Registered: Oct 2013
Posts: 4

Rep: Reputation: Disabled
Whats the proper what to terminate a script using start-stop-daemon?


I am using a start-stop-daemon to make a INIT script for my script. I am using `--make-pidfile` cause my script doesnt make its own pid. I can start my script using start and pid file generates with appropriate PID. But the stop function doesnt work. I am getting return code 0 with `--oknodo` and 1 without it. If I do

ps -ef | grep perl

and

cat /home/me/mydaemon/run

I always see the same PID. I can terminate the script using

kill -15 PID.

But not with the stop function of my init script.

Whats the proper way to stop my process?

As per start-stop-daemon manual,

Quote:
--stop Checks for the existence of a specified process. If such a process exists, start-stop-daemon sends it the signal specified by --signal, and exits with error status 0. If such a process does not exist, start-stop-daemon exits with error status 1 (0 if --oknodo is specified). If --retry is specified, then start-stop-daemon will check that the process(es) have terminated.
I didnt find find any documentation for `--signal` itself. Like how to specify `--signal` if I want to send a SIGTERM.
Code:
#!/bin/sh
	### BEGIN INIT INFO
	# Provides:          myd
	# Required-Start:    $local_fs $network $named $time $syslog
	# Required-Stop:     $local_fs $network $named $time $syslog
	# Default-Start:     2 3 4 5
	# Default-Stop:      0 1 6
	# Description:       Diitalk daemon for sending push notifications
	### END INIT INFO

	. /lib/lsb/init-functions

	PATH=/sbin:/bin:/usr/sbin:/usr/bin
	DAEMON="/home/me/mydaemon/myd"
	NAME="myd"
	DESC="My Daemon"
	HOMEDIR=/home/me/mydaemon/run
	PIDFILE="$HOMEDIR/$NAME.pid"
	USER=me
	GROUP=me
	SHM_MEMORY=64
	PKG_MEMORY=8
	DUMP_CORE=no

	case "$1" in
	  start|debug)
			log_daemon_msg "Starting $DESC: $NAME"
			start-stop-daemon --start --quiet --background --make-pidfile --pidfile $PIDFILE \
					--exec $DAEMON || log_failure_msg " already running"
			log_end_msg 0
			;;
	  stop)
			log_daemon_msg "Stopping $DESC: $NAME"
			start-stop-daemon --oknodo --stop --quiet --pidfile $PIDFILE \
					--exec $DAEMON
            echo $?
			log_end_msg 0
			;;
 
Old 07-17-2015, 10:09 AM   #2
rtmistler
Moderator
 
Registered: Mar 2011
Location: USA
Distribution: MINT Debian, Angstrom, SUSE, Ubuntu, Debian
Posts: 9,882
Blog Entries: 13

Rep: Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930
You might need to use the --user option for your directives, however from what I see you're doing it correctly. Do you see the log for "Stopping"?
 
  


Reply

Tags
bash, init script



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 On
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Scripting with start-stop-daemon agentgates Linux - Server 6 02-01-2012 03:59 PM
[SOLVED] start-stop-daemon in Slackware? qlands Slackware 6 06-24-2011 04:03 PM
Bash script to verify the daemon is working if not, start the daemon kishoreru Linux - Newbie 7 09-23-2009 04:29 AM
Proper way to start / stop xinetd tcdmail Linux - Server 1 06-28-2007 06:03 PM
how can I get/make a proper squid daemon startup script for boot time binkybuckle Debian 0 07-05-2003 07:58 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 02:29 AM.

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