LinuxQuestions.org
Latest LQ Deal: Linux Power User Bundle
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > Slackware
User Name
Password
Slackware This Forum is for the discussion of Slackware Linux.

Notices


Reply
  Search this Thread
Old 09-06-2016, 08:15 PM   #1
mfoley
Senior Member
 
Registered: Oct 2008
Location: Columbus, Ohio USA
Distribution: Slackware
Posts: 1,392

Rep: Reputation: 120Reputation: 120
Need way to delay shutdown/session logout


I have an /etc/rc.d/rc.local_shutdown script that is trying to gracefully shutdown a Virtual Machine before the KDE session is terminated by `shutdown -r now`. The script works when run manually, but when I do the `shutdown` the KDE session and/or the x11vnc session(s) are terminated immediately, apparently before the rc.local_shutdown is run.

Is there a way to put a "hook" in ahead of terminating login sessions so I can delay the shutdown until after I accomplish my mission?

followup: in looking at /etc/inittab, it appears that runlevel 6 executes /etc/rc.d/rc.6. I don't see any mechanism to kill of login processes outside of that script. rc.local_shutdown runs close to the top of the rc.6 script (just after saving the hardware clock). So, is it possible that initd runs the rc.local_shutdown in the background? If so, I could try:
Code:
# /etc/rc.d/rc.6
/etc/rc.d/rc.local_shutdown
cPid=$!
while kill -0 $cPid; do sleep 1; done

Last edited by mfoley; 09-06-2016 at 08:33 PM.
 
Old 09-06-2016, 08:30 PM   #2
frankbell
LQ Guru
 
Registered: Jan 2006
Location: Virginia, USA
Distribution: Slackware, Debian, Mageia, and whatever VMs I happen to be playing with
Posts: 13,699
Blog Entries: 22

Rep: Reputation: 3601Reputation: 3601Reputation: 3601Reputation: 3601Reputation: 3601Reputation: 3601Reputation: 3601Reputation: 3601Reputation: 3601Reputation: 3601Reputation: 3601
How about writing a little script that closes the VM, waits a decent interval, then invokes the shutdown command?

Just a thought.
 
Old 09-06-2016, 09:22 PM   #3
Emerson
LQ Guru
 
Registered: Nov 2004
Location: Saint Amant, Acadiana
Distribution: Gentoo ~arch
Posts: 6,311

Rep: Reputation: Disabled
If you could run the VM in headless mode then shutting down KDE wouldn't kill it.
 
Old 09-06-2016, 10:36 PM   #4
mfoley
Senior Member
 
Registered: Oct 2008
Location: Columbus, Ohio USA
Distribution: Slackware
Posts: 1,392

Original Poster
Rep: Reputation: 120Reputation: 120
Quote:
Originally Posted by frankbell View Post
How about writing a little script that closes the VM, waits a decent interval, then invokes the shutdown command?

Just a thought.
I could do this if I'mn controlling the shutdown, for example after a `slackpkg update`. But this is supposed to be an office user's workstations, so what about if the user clicks on SHUTDOWN/REBOOT?

Quote:
Originally Posted by Emerson View Post
If you could run the VM in headless mode then shutting down KDE wouldn't kill it.
In fact, I don't know what "headless mode" means for a VM. Can the user still see the VM window and do what he/she needs to to on that VM?

For testing, if I `echo` from rc.6, where does the output go? I've looked in /var/log/messgaes and `dmesg | grep "some string"`

Last edited by mfoley; 09-06-2016 at 10:42 PM.
 
Old 09-07-2016, 07:01 AM   #5
bassmadrigal
LQ Guru
 
Registered: Nov 2003
Location: West Jordan, UT, USA
Distribution: Slackware
Posts: 5,121

Rep: Reputation: 2902Reputation: 2902Reputation: 2902Reputation: 2902Reputation: 2902Reputation: 2902Reputation: 2902Reputation: 2902Reputation: 2902Reputation: 2902Reputation: 2902
I think you're looking for KDE Settings -> Startup and Shutdown. With scripts, there's a "Run on" column that allows you to specify Startup, Shutdown, or Pre-KDE Startup.

See https://userbase.kde.org/System_Sett...nd_Shutdown/en for more details.

So, you would need to create a script that ends in .sh (unless that requirement has been lifted), then add it to KDE's autostart section, but change the Run On option to Shutdown.

NOTE: This feature does not differentiate between Logout and Shutdown. Both will run the script. Depending on how you intend for those VMs to start, you may want to add an entry to the Autostart to start things up when the user logs in too.
 
1 members found this post helpful.
Old 09-07-2016, 07:17 AM   #6
Emerson
LQ Guru
 
Registered: Nov 2004
Location: Saint Amant, Acadiana
Distribution: Gentoo ~arch
Posts: 6,311

Rep: Reputation: Disabled
Quote:
Originally Posted by mfoley View Post
In fact, I don't know what "headless mode" means for a VM. Can the user still see the VM window and do what he/she needs to to on that VM?
If there was a window in GUI environment you couldn't call it headless. For instance I had Agocontrol running in a headless VM, since it has a web interface all I had to do to access it was to point my browser to VM's IP address. You didn't tell us how/why are you using VM, so I just offered a solution - it may not fit your purpose.
 
Old 09-07-2016, 03:17 PM   #7
mfoley
Senior Member
 
Registered: Oct 2008
Location: Columbus, Ohio USA
Distribution: Slackware
Posts: 1,392

Original Poster
Rep: Reputation: 120Reputation: 120
Quote:
Originally Posted by Emerson View Post
If there was a window in GUI environment you couldn't call it headless. For instance I had Agocontrol running in a headless VM, since it has a web interface all I had to do to access it was to point my browser to VM's IP address. You didn't tell us how/why are you using VM, so I just offered a solution - it may not fit your purpose.
I'm working on replacing Windows AD domain workstations in our office with Linux. However, some applications (e.g. quickbooks) only run in Windows and some partner sites only permit Internet Explorer. To solve these problem I am trying to let users run a WIN7 VM under Linux. That part works. So yes, they need a GUI.

Quote:
Originally Posted by bassmadrigal View Post
I think you're looking for KDE Settings -> Startup and Shutdown. With scripts, there's a "Run on" column that allows you to specify Startup, Shutdown, or Pre-KDE Startup.

See https://userbase.kde.org/System_Sett...nd_Shutdown/en for more details.

So, you would need to create a script that ends in .sh (unless that requirement has been lifted), then add it to KDE's autostart section, but change the Run On option to Shutdown.

NOTE: This feature does not differentiate between Logout and Shutdown. Both will run the script. Depending on how you intend for those VMs to start, you may want to add an entry to the Autostart to start things up when the user logs in too.
I saw that in KDE. I'll definitely try that next.

In /etc/rc.d/rc.6, I tried moving the running of rc.local_shutdown to be the absolute first thing in the script, before the sysvinit shutdown (which is where VirtualBox puts its shutdown scripts). Unfortunately, that didn't work either. The first thing init does is:

INIT: Sending Processes the TERM signal

Then I see the "echo "Running shutdown script /etc/rc.d/rc.6:" message. So, apparently init kills off login process before doing anything.
 
Old 09-07-2016, 04:50 PM   #8
bassmadrigal
LQ Guru
 
Registered: Nov 2003
Location: West Jordan, UT, USA
Distribution: Slackware
Posts: 5,121

Rep: Reputation: 2902Reputation: 2902Reputation: 2902Reputation: 2902Reputation: 2902Reputation: 2902Reputation: 2902Reputation: 2902Reputation: 2902Reputation: 2902Reputation: 2902
Quote:
Originally Posted by mfoley View Post
In /etc/rc.d/rc.6, I tried moving the running of rc.local_shutdown to be the absolute first thing in the script, before the sysvinit shutdown (which is where VirtualBox puts its shutdown scripts). Unfortunately, that didn't work either. The first thing init does is:

INIT: Sending Processes the TERM signal

Then I see the "echo "Running shutdown script /etc/rc.d/rc.6:" message. So, apparently init kills off login process before doing anything.
I'm pretty sure anything in rc.6 or rc.shutdown_local are run after KDE is shutdown. I don't think there exists anything in the base system that will run commands for any WM/DE before the shutdown/logout process of that WM/DE. I think you need to find something within your preferred WM/DE that will run things when it detects a logout/shutdown has occurred.
 
1 members found this post helpful.
Old 09-07-2016, 05:04 PM   #9
mfoley
Senior Member
 
Registered: Oct 2008
Location: Columbus, Ohio USA
Distribution: Slackware
Posts: 1,392

Original Poster
Rep: Reputation: 120Reputation: 120
Quote:
Originally Posted by bassmadrigal View Post
I'm pretty sure anything in rc.6 or rc.shutdown_local are run after KDE is shutdown. I don't think there exists anything in the base system that will run commands for any WM/DE before the shutdown/logout process of that WM/DE. I think you need to find something within your preferred WM/DE that will run things when it detects a logout/shutdown has occurred.
Yes, KDE and login sessions generally are apparently terminated before rc.6. Oh well. I did create the KDE shutdown script as your previous post describes. Interestingly, KDE and/or VirtualBox are smart enough that I box pops up when I log out asking how I want to shut down the VM. When I select APCI (graceful shutdown), the logout is canceled and the VM is shutdown. I can then log out.

That solves my problem without me having to solve it!

So, if I need to shutdown or reboot for some other reason (UPS power failure, slackpkg upgrade, ...) I can have those scripts run a check for and gracefully shutdown any running VMs:
Code:
ps -eo pid,user,comm,args | grep "/opt/VirtualBox/VirtualBox --comment" | grep -v grep | \
while read
do
    pid=`echo $REPLY | awk '{print $1}'`
    u=`echo $REPLY | awk '{print $2}'`
    VM=`echo $REPLY | awk '{print $6}'`

    echo Shutting down VirtualMachine $VM for user $u, pid $pid
    su $u --command "/usr/bin/VBoxManage controlvm $VM acpipowerbutton"
    while kill -0 $pid; do sleep 1; echo waiting; done
done
I think I'm good to go!
 
2 members found this post helpful.
  


Reply

Tags
delay, shutdown


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
[SOLVED] system failed to save session at shutdown, but retrieved changes after next shutdown - ?! newbiesforever Linux - General 5 06-09-2016 09:58 PM
logout before shutdown with shutdown button in XFCE ta0kira Ubuntu 2 06-25-2011 04:57 AM
Gnome 2.8 logout delay in Debian Sarge HalfDiminished Debian 2 04-07-2005 03:19 PM
Delay during GNOME login/logout -> devfsd Romendo Mandriva 0 09-02-2004 04:49 PM
Logout delay The Burninator Linux - Newbie 3 02-03-2003 11:58 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > Slackware

All times are GMT -5. The time now is 06:16 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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration