LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
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 08-03-2009, 03:45 AM   #1
Lakki
Member
 
Registered: Jul 2008
Posts: 32

Rep: Reputation: 15
Last process during run level change


Hi,

I am working on RHEL 5.3

I want to display a message to user whenever he/she moves from run level 2 to 3.

Sometimes, the last process that is coming up when i go to run level 2 is irqbalance and sometime it is anacron.

Is there anyway to find out which will be the last process that is coming during the run level changes?

Thanks in advance!

Regards,
Lakshmi
 
Old 08-03-2009, 04:35 AM   #2
unSpawn
Moderator
 
Registered: May 2001
Posts: 29,415
Blog Entries: 55

Rep: Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600
/etc/rc.d/rc governs which services to start in what runlevel.
 
Old 08-03-2009, 05:44 AM   #3
catkin
LQ 5k Club
 
Registered: Dec 2008
Location: Tamil Nadu, India
Distribution: Debian
Posts: 8,578
Blog Entries: 31

Rep: Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208
Hello Lakki :-)

Do you really want to notify the user of changing from runlevel 2 to 3. What about leaving 2 (for something other than 3) or entering 3 (from something other than 2)? Answers to these questions will help determine if init scripts can be used to achieve what you want.

What/who is initiating the runlevel change?

Will there always be only one user? How will they be interacting with the system, to receive the messages -- terminal, GUI, remote login ... ? Answers to these questions will help determine the messaging mechanism to achieve what you want.

Best

Charles
 
Old 08-03-2009, 06:45 AM   #4
Lakki
Member
 
Registered: Jul 2008
Posts: 32

Original Poster
Rep: Reputation: 15
Hi Charles,

Thanks for your queries! Here are the answers!

We have only 3 run levels in the system and i want to notify the user when moving from run-level 3 to 2. I have one of these processes(irqbalance, anacron) as the last process during the run level change

And it can be root user or another 2 users created for the application.

The interaction or the run level change is always via the console(terminal)

Regards,
Lakki
 
Old 08-03-2009, 10:14 AM   #5
catkin
LQ 5k Club
 
Registered: Dec 2008
Location: Tamil Nadu, India
Distribution: Debian
Posts: 8,578
Blog Entries: 31

Rep: Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208
Hello Lakki

Thanks for clear answers to questions asked! I'm talking ubuntu so some translation may be required if you're running something else but the concepts should (TM) be valid.
Quote:
Originally Posted by Lakki View Post
We have only 3 run levels in the system and i want to notify the user when moving from run-level 3 to 2.
The /etc/init.d/rc script is your friend! Here are the relevant lines from it
Code:
# Now find out what the current and what the previous runlevel are.
runlevel=$RUNLEVEL

# Get first argument. Set new runlevel to this argument.
[ "$1" != "" ] && runlevel=$1
if [ "$runlevel" = "" ]
then
	echo "Usage: $scriptname <runlevel>" >&2
	exit 1
fi
previous=$PREVLEVEL
[ "$previous" = "" ] && previous=N

export runlevel previous
The "export" makes $previous and $runlevel available to all /etc/rc[S0-5].d/ files. The first of those files run by rc when transitioning to, say, runlevel 2 is the first (by alphanumeric sorting) of the /etc/rc2.d/K* files. So you should (TM) be able to do what you want by creating an /etc/init.d/runlevel_reporter script and setting up symlinks to it as /etc/rc[23].d/K00runlevel_reporter.

The runlevel_reporter script would need to examine the values of $previous and $runlevel and write to /dev/console as required.

For nice integration with the boot process and utilities that manage /etc/rc[S0-5].d/* symlinks it would be easiest to base runlevel_reporter on /etc/init.d/skeleton. /etc/init.d/skeleton includes
Code:
# Define LSB log_* functions.
# Depend on lsb-base (>= 3.0-6) to ensure that this file is present.
. /lib/lsb/init-functions
You may like to examine the functions provided in /lib/lsb/init-functions; it has functions to write to the console ensuring consistent boot message appearance.

Best

Charles
 
Old 08-03-2009, 10:17 AM   #6
catkin
LQ 5k Club
 
Registered: Dec 2008
Location: Tamil Nadu, India
Distribution: Debian
Posts: 8,578
Blog Entries: 31

Rep: Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208
Hello Lakki
Quote:
Originally Posted by Lakki View Post
The interaction or the run level change is always via the console(terminal)
I assumed that you would be OK with having the runlevel change notification written to the console too but that may not be what you meant. Do you (also) want to write to multiple users' GUIs? Terminals in GUIs?
 
Old 08-04-2009, 07:26 AM   #7
Lakki
Member
 
Registered: Jul 2008
Posts: 32

Original Poster
Rep: Reputation: 15
Smile

Hi Charles

Thanks for your detailed answers. It helped me a lot. I haved added code in /etc/rc.d/rc to accomaodate the changes!

And regarding the ouptut display, i just wanted to display only in console and that too for a single user at a time.

Thanks,
Lakshmi
 
Old 08-04-2009, 08:15 AM   #8
unSpawn
Moderator
 
Registered: May 2001
Posts: 29,415
Blog Entries: 55

Rep: Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600
Please note that making changes to core components of SysV init like /etc/rc.d/rc is not advisable because it is not a best practice, as opposed to /etc/inittab or /etc/rc.d/init.d initscripts (as catkin pointed out in post #5), and any changes might be removed next time the "initscripts" package is updated.
 
Old 08-04-2009, 08:31 AM   #9
catkin
LQ 5k Club
 
Registered: Dec 2008
Location: Tamil Nadu, India
Distribution: Debian
Posts: 8,578
Blog Entries: 31

Rep: Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208
Hello Lakshmi
Quote:
Originally Posted by Lakki View Post
I haved added code in /etc/rc.d/rc to accomaodate the changes!
As unSpawn pointed out your modifications would be more persistent if you added an /etc/init.d script rather than changing rc itself.
 
Old 08-04-2009, 09:07 AM   #10
Lakki
Member
 
Registered: Jul 2008
Posts: 32

Original Poster
Rep: Reputation: 15
Hi,

But adding a new script in /etc/init.d/ and monitoring for the run level change, makes the system to display the message immediately after moving from run-levl 3 to 2. It is not waiting until all the process in the run level 2 comes up. Also since i am not sure whether to add in /etc/init.d/anacron or /etc/init.d/irqbalance, i opted to add a separate script to monitor the run level change. but it didnt help out!

Any suggestions please!!

Regards,
Lakki
 
Old 08-04-2009, 09:45 AM   #11
catkin
LQ 5k Club
 
Registered: Dec 2008
Location: Tamil Nadu, India
Distribution: Debian
Posts: 8,578
Blog Entries: 31

Rep: Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208
Quote:
Originally Posted by Lakki View Post
Hi,

But adding a new script in /etc/init.d/ and monitoring for the run level change, makes the system to display the message immediately after moving from run-levl 3 to 2. It is not waiting until all the process in the run level 2 comes up. Also since i am not sure whether to add in /etc/init.d/anacron or /etc/init.d/irqbalance, i opted to add a separate script to monitor the run level change. but it didnt help out!

Any suggestions please!!

Regards,
Lakki
I'm sorry -- I misunderstood you to want to tell the user that a change from runlevel 3 to 2 (or 2 to 3) had started, not that it had finished.

If you want to tell the user that a change from runlevel 3 to 2 (or 2 to 3) has finished, then link your /etc/init.d/ script as /etc/rc[23].d/S99<whatever>, ensuring that S99<whatever> comes after all the other scripts in alphanumeric sort order.
 
  


Reply



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
Can't switch to TTY or run level 3 from run level 5 reemfz Fedora 3 06-01-2009 08:06 AM
change run level siva19185 Linux - Newbie 1 07-10-2008 09:33 AM
set your default run level so you will boot to a default run level - vga console Adam555 Linux - Newbie 1 01-21-2008 04:55 PM
how to change test sizze or character size in run level 3 in text mode? betrussell23 Linux - Newbie 1 10-13-2006 04:23 AM
emacs in run level 3 then switch to X (level 7) then back to level 3 dsoliver Slackware 3 09-01-2006 03:31 AM

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

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