LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 07-08-2014, 04:33 AM   #1
lordalgar
LQ Newbie
 
Registered: Jul 2014
Posts: 3

Rep: Reputation: Disabled
How to run program/script as late in the shutdown process as possible?


How can I run a program/script as late in the shutdown process as possible? (Only when I poweroff, not on reboot etc.)

I need to run a script or program as late in the shutdown process as possible. I have tried /etc/rc0.d but it's run far to soon. I used:
sudo update-rc.d dmpsustop stop 00 0

Is there any other way (writing drivers, other tools, recompile kernel?)

I'm not very experianced in Linux s
 
Old 07-08-2014, 11:05 AM   #2
bigrigdriver
LQ Addict
 
Registered: Jul 2002
Location: East Centra Illinois, USA
Distribution: Debian stable
Posts: 5,908

Rep: Reputation: 356Reputation: 356Reputation: 356Reputation: 356
The scripts in /etc/rc0.d are run to prepare the system for bootup; rc1.d to get to runlevel 1, rc2.d to get to runlevel 2, and so on. The scripts to shutdown services to prepare for reboot should go in rc6.d.

Read the readme files in /etc rc6.d and /etc/init.d for more information.
 
Old 07-08-2014, 04:00 PM   #3
jefro
Moderator
 
Registered: Mar 2008
Posts: 21,974

Rep: Reputation: 3623Reputation: 3623Reputation: 3623Reputation: 3623Reputation: 3623Reputation: 3623Reputation: 3623Reputation: 3623Reputation: 3623Reputation: 3623Reputation: 3623
May have to put in some timers or waits to let stuff settle down.
 
Old 07-08-2014, 07:41 PM   #4
lordalgar
LQ Newbie
 
Registered: Jul 2014
Posts: 3

Original Poster
Rep: Reputation: Disabled
According to this page: http://www.linux.com/news/enterprise...nd-rcd-scripts

rc0.d should be used when poweroff. My problem is that my script is running to late in the shutdown (poweroff) process.

jefro: How can I wait for things to settle down, any special process or signal I can wait for?
 
Old 07-08-2014, 10:11 PM   #5
michaelk
Moderator
 
Registered: Aug 2002
Posts: 25,681

Rep: Reputation: 5894Reputation: 5894Reputation: 5894Reputation: 5894Reputation: 5894Reputation: 5894Reputation: 5894Reputation: 5894Reputation: 5894Reputation: 5894Reputation: 5894
What distribution/version are you running?

By running the update-rc.d as posted a link should of been created in the rc0.d directory like K00dmpsustop.

When a runlevel is entered all the process with KXXs are run first Then the SXX scripts are run. The difference between K and S is the Ks will be invoked with a stop parameter and S the start parameter.

So in reality K00 should be the first script that runs when the shutdown process starts. If your script is written like a standard init process then it might not be running at all. Without knowing anything about your script or what services it might be required to run we really do not know where in the shutdown process it should be executed.
 
Old 07-09-2014, 12:16 AM   #6
lordalgar
LQ Newbie
 
Registered: Jul 2014
Posts: 3

Original Poster
Rep: Reputation: Disabled
Hi, I'm running Raspian an Debian fork.

You are right a link is created called K01dmpsustop

This is run when shutdown (poweroff), but it's run to early. The script look like this:

Code:
#! /bin/sh
### BEGIN INIT INFO
# Provides:          dmpsustop
# Required-Start:
# Required-Stop:
# Default-Start:
# Default-Stop:      0
# Short-Description: 
# Description:
### END INIT INFO

PATH=/sbin:/usr/sbin:/bin:/usr/bin:/usr/local/bin

. /lib/lsb/init-functions

do_stop () {
        log_action_msg "------------///////////////\\\\\\\\\\\\\\\----------">&2
	log_action_msg "---- Shut down  ----">&2
}

case "$1" in
  start)
	# No-op
	;;
  restart|reload|force-reload)
	echo "Error: argument '$1' not supported" >&2
	exit 3
	;;
  stop)
	do_stop
	;;
  *)
	echo "Usage: $0 stop" >&2
	exit 3
	;;
esac
 
Old 07-09-2014, 12:27 AM   #7
pan64
LQ Addict
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 21,804

Rep: Reputation: 7306Reputation: 7306Reputation: 7306Reputation: 7306Reputation: 7306Reputation: 7306Reputation: 7306Reputation: 7306Reputation: 7306Reputation: 7306Reputation: 7306
so try rename it to K99dmpsustop
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 run before server shutdown vaishlinux Red Hat 6 04-04-2014 09:11 AM
Run the script at machine shutdown. trumtrak Linux - Newbie 2 03-18-2013 07:38 AM
How can a program run but not be in the process list? RandomTroll Linux - Software 10 11-01-2012 09:27 PM
Run script on shutdown or reboot VeeDubbs Linux - Server 1 10-23-2008 01:34 PM
How to run a script at startup after a shutdown? kklein9 Linux - Software 3 01-27-2006 03:32 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 02:45 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