The officially official Devuan Forum!

You are not logged in.

#1 2021-11-28 21:46:08

Altoid
Member
Registered: 2017-05-07
Posts: 1,429  

[SOLVED] Problem with shutdown script

Hello:

I shut down my Devuan Beowulf system with a script called from a launcher which I set up within the panel of my Xfce desktop:

This is the script:

#!/bin/sh
# added to shutdown directly - no shutdown helper 
PATH=/sbin:/bin:/usr/sbin:/usr/bin:
#
sync && sudo ethtool -s eth0 wol d && sudo rmmod -s -v e1000e && sudo shutdown -h now

This is the launcher command line:

xfce4-terminal -x sudo /usr/bin/shutdown.sh

This has been working perfectly well for the longest time.
Some time ago I set up Pihole in an autostarted Vbox virtual machine but although it seems to start up properly it does not shutdown gracefully.

ie: sudo shutdown -h now takes effect before the virtual machine has completely shut down.

The idea is to send the virtual machine the shutdown command, wait 5s and then execute the shutdown script.
Simple if not elegant.

As VBox gives members of the vboxusers group permission to start and shutdown a virtual machine, I cannot add the shutdown command to the shutdown script called from the launcher because this script needs sudo. ie: root privileges and the vms belong to vmusers and not to root.

So I add the virtual machine shutdown script + a 5s sleep to the launcher command line.
But it does not work with the launcher.

vboxmanage controlvm "madmax ascii" poweroff && sleep 5s && sudo /usr/bin/shutdown.sh works properly if I execute it from a terminal.

But not when I run it from the launcher:

xfce4-terminal -x vboxmanage controlvm "madmax ascii" poweroff && sleep 5s && /usr/bin/shutdown.sh

It only shuts down the virtual machine, the rest of the command does not have effect.

Cannot figure out what I'm doing wrong.

Any ideas?

Thanks in advance.

A.

Last edited by Altoid (2021-11-28 21:47:29)

Offline

#2 2021-11-29 12:43:39

hevidevi
Member
Registered: 2021-09-17
Posts: 230  

Re: [SOLVED] Problem with shutdown script

Maybe instead of using sleep use the wait command.

https://linuxize.com/post/bash-wait/

Offline

#3 2021-11-29 14:48:22

Altoid
Member
Registered: 2017-05-07
Posts: 1,429  

Re: [SOLVED] Problem with shutdown script

Hello:

hevidevi wrote:

... instead of using sleep use the wait command.

Hmm ...

"... wait is a command that waits for the given jobs to complete ..."

Think that may be it?

I'll try it out and report back here.

But if it the command works from an open terminal ...

vboxmanage controlvm "madmax ascii" poweroff && sleep 5s && sudo /usr/bin/shutdown.sh

... shouldn't it also work in the launcher command line?

xfce4-terminal -x vboxmanage controlvm "madmax ascii" poweroff && sleep 5s && sudo /usr/bin/shutdown.sh

My guess is that there's something in the syntax I'm using, just cannot find out what it is.

Thanks for your input.

Best,

A.

Offline

#4 2021-11-29 14:55:30

rolfie
Member
Registered: 2017-11-25
Posts: 1,055  

Re: [SOLVED] Problem with shutdown script

If its working directly and not in a script, my first guess would be path issues.

rolfie

Offline

#5 2021-11-29 15:00:52

Altoid
Member
Registered: 2017-05-07
Posts: 1,429  

Re: [SOLVED] Problem with shutdown script

Hello:

Altoid wrote:

... try it out and report ...

No, no change in how running the command from the launcher behaves.

But thanks a lot for the heads up on wait. 8^D

Using it instead of sleep, which has to be used with an arbitrary time lapse (which may or may not be always right) makes for a faster resolution of the command.

Thanks for your input.

Best,

A.

Offline

#6 2021-11-29 15:46:36

Altoid
Member
Registered: 2017-05-07
Posts: 1,429  

Re: [SOLVED] Problem with shutdown script

Hello:

rolfie wrote:

... working directly and not in a script, my first guess would be path ...

I thought of that at first so I checked the script and the launcher command line.
On one hand both xfce4-terminal and vboxmanage are located in /usr/bin/.
Also, as the vm does get shut down, I concluded that it was not related.

Nevertheelss, I just checked to see:

xfce4-terminal -x /usr/bin/vboxmanage controlvm "madmax ascii" poweroff && wait && sudo /usr/bin/shutdown.sh

... does not work either.

Thanks for your input.

Best,

A.

Offline

#7 2021-11-29 16:02:52

Head_on_a_Stick
Member
From: London
Registered: 2019-03-24
Posts: 3,125  
Website

Re: [SOLVED] Problem with shutdown script

I won't comment on VirtualBox (that sound you can hear is me biting my tongue) but using an entire terminal emulator to run a script seems... excessive.

Perhaps just run a shell instead, for example:

sh -c 'command1 && command2'

But I would recommend using /etc/rc6.d/ to execute scripts on shutdown. Ask the interweb for details 'cos I really don't know what I'm doing with sysvinit.


Brianna Ghey — Rest In Power

Offline

#8 2021-11-29 20:15:45

Altoid
Member
Registered: 2017-05-07
Posts: 1,429  

Re: [SOLVED] Problem with shutdown script

Hello:

Head_on_a_Stick wrote:

... won't comment on VirtualBox ...

=^ )

Head_on_a_Stick wrote:

... an entire terminal emulator to run a script ...

The only way I found to run this set of commands and see the printout roll out 'live' without much hassle.
Maybe could have sent the output to a file.

Head_on_a_Stick wrote:

Perhaps just run a shell instead ....

Yes!!!
It lives!  8^D

sh -c 'vboxmanage controlvm "madmax ascii" poweroff && wait && sudo /usr/bin/shutdown.sh' as the command in the launcher works great.

Quite fast, maybe because the terminal is not involved now (?).

I have to look at the logs and see if anything is amiss VBox wise, but at first sight it seems to work as intended.

Head_on_a_Stick wrote:

... recommend using /etc/rc6.d/ to execute scripts on shutdown.

I'll have a look at that further on.

Thank you very much for your input.
Much appreciated.

Best,

A.

Last edited by Altoid (2021-11-29 20:16:36)

Offline

#9 2021-11-29 20:58:01

Altoid
Member
Registered: 2017-05-07
Posts: 1,429  

Re: [SOLVED] Problem with shutdown script

Hello:

Altoid wrote:

Yes!!!
It lives!  8^D
.. look at the logs and see if anything is amiss ...

No problems detected in the guest machine logs, Pihole or Unbound.

For completeness' sake:

I run an autostarted VBbox Devuan Beowulf guest running Pihole/Unbound.
Although it starts up properly, for some reason it does not shutdown gracefully.

The result is that I get error messages when I shut down the host:

groucho@devuan:/var/log$ cat messages | grep -i error
--- snip ---
Nov 19 22:38:23 localhost kernel: [21254.843754] traps: VBoxSVC[2451] trap int3 ip:7fa545efcddc sp:7ffe92195e50 error:0 in VBoxXPCOMIPCC.so[7fa545ef8000+f000]
--- snip ---
groucho@devuan:/var/log$

See https://dev1galaxy.org/viewtopic.php?id=4684

Fixing this script (VBox) issue made everything right.
Now the host shuts down after the guest shuts down properly, it's health is preserved and there are no more localhost kernel errors.

Thanks to all that pitched in.  8^)

Best,

A.

Last edited by Altoid (2021-11-30 11:14:40)

Offline

Board footer