Linux - SoftwareThis 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
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
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.
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)
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
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.
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?
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.
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!
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.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.