*pokes thread*
I was thinking.. maybe try using the full path to logger and see what happens. If it works when run as your normal user, but not on shutdown, perhaps the path is not found.
*pokes thread*
I was thinking.. maybe try using the full path to logger and see what happens. If it works when run as your normal user, but not on shutdown, perhaps the path is not found.
Come to #ubuntuforums! We have cookies! | Basic Ubuntu Security Guide
Tomorrow's an illusion and yesterday's a dream, today is a solution...
sure, i'll give it a try. I found the logger executable, but there has to be a way to get direct access to the log. since a touch works, a file write should as well.
Things are rarely just crazy enough to work, but they're frequently just crazy enough to fail hilariously.
touch is an internal command, isn't it?
Come to #ubuntuforums! We have cookies! | Basic Ubuntu Security Guide
Tomorrow's an illusion and yesterday's a dream, today is a solution...
indeed it is, as is >> or so it would appear. I was able to manually write to the syslog file on shutdown, so looks like that will work. I need to clean it up a little to better integrate the logging, as well as get it to echo to stdout, but here is my working copy.
a quick question on savestate. I did some poking around and it seems like there is no cli way to gracefully shutdown the guest. do virtual filesystems suffer from the write-in-progress danger that physical disks carry with them? is it safe to simply reset them?
I'm also having a problem with network services in the guest when resuming from saved state. I think I can handle that though.
Code:#!/bin/bash ### BEGIN INIT INFO # Provides: vmboot # Required-Start: vboxdrv $local_fs $syslog # Required-Stop: vboxdrv $local_fs $syslog # Default-Start: 2 3 4 5 # Default-Stop: 0 1 6 # Short-Description: Stop/Start VMs before/after System shutdown ### END INIT INFO # Add this script to /etc/init.d/ # Run update-rc.d vmboot defaults as root # Written to work with VirtualBox 4.x # User who is running the VMs VBOXUSER=CONFIGURE_ME SU="sudo -H -u $VBOXUSER" #en/disable syslogging 1|0 EnableLogging="1" echocmd="echo -e" loggercmd="logger -s -f /var/log/syslog" logdate=$(echo -e $(date +"%b %d %H:%M:%S")) loggermsg="$(echo -e $logdate `hostname` vmboot: %s)\n" # Path to VBoxManage VBOXMANAGE="/usr/bin/VBoxManage --nologo" # Get UUID of All Running VMs # UUID looks like this: a02b5b54-a84d-48fa-8dac-2a3fad55717e RUNNINGVMS=$($SU $VBOXMANAGE list runningvms | sed -e 's/^".*".*{\(.*\)}/\1/') # Get UUID of All VMs ALLVMS=$($SU $VBOXMANAGE list vms | sed -e 's/^".*".*{\(.*\)}/\1/') #set logging if [[ "$EnableLogging" -eq "1" ]]; then echocmd=$loggercmd fi # Check to insure $ALLVMS is not null and exit if it is. if [[ $ALLVMS = "" ]]; then $echocmd "No VMs are detected on this host! Did you configure the VBOXUSER variable?"; exit fi function logMsg(){ if [[ "$EnableLogging" -eq "1" ]]; then printf "$loggermsg" "$1" >> /var/log/syslog >> /dev/stdout; fi } function stopService(){ if [[ -n $RUNNINGVMS ]]; then for v in $RUNNINGVMS; do $echocmd "Saving state of $($SU $VBOXMANAGE list vms | grep $v | awk -F\" '{print $(NF-1)}')..." && $SU $VBOXMANAGE controlvm $v savestate done; else $echocmd "No running VMs to save!" fi # If the previous loop has an error, the loops exits and returns an error. if [[ $? -ne 0 ]]; then $echocmd "There was an error stopping your VMs!"; else echo -e "$(touch /var/log/vmboot-shutdown-`date +%Y%m%d%H%M%S`)"; logMsg "VMBoot has saved all VMs"; fi } function startService(){ for v in $ALLVMS; do if [[ -n $($SU $VBOXMANAGE showvminfo $v) ]]; then $echocmd "Waiting for VM \"$($SU $VBOXMANAGE list vms | grep $v | awk -F\" '{print $(NF -1)}')\" to power on..." && $SU $VBOXMANAGE startvm $v --type headless 1> /dev/null && logger -s "VM \"$($SU $VBOXMANAGE list vms | grep $v | awk -F\" '{print $(NF-1)}')\" has been successfully started."; else $echocmd "No Saved VMs to start!" fi # If the previous loop has an error, the loops exits and returns an error. if [[ $? -ne 0 ]]; then $echocmd "There was an error starting your VMs! Try starting them manually to see what the problem is."; break fi done } function restartService(){ stopService startService } function serviceStatus(){ if [[ -n $RUNNINGVMS ]]; then $echocmd "List of Running VMs:" && $SU $VBOXMANAGE list runningvms; else $echocmd "No VMs Currently Running!" fi } case $1 in stop) stopService ;; start) startService ;; restart) restartService ;; status) serviceStatus ;; force-reload) #not really sure what to do here other than restart restartService ;; *) echo "Usage: /etc/init.d/vmboot start | stop | status | restart | force-reload"; exit 1 ;; esac exit 0 # eof
Last edited by doas777; September 23rd, 2011 at 06:25 AM.
Things are rarely just crazy enough to work, but they're frequently just crazy enough to fail hilariously.
From what I read, just powering off the guest may cause problems and/or data corruption on the virtual hdd.
I did see that you can send these two signals to the guest via cli:
I think that might be what you are looking for, tho I have not used it. Just replace savestate with that.Code:acpipowerbutton
Last edited by CharlesA; September 23rd, 2011 at 12:22 PM.
Come to #ubuntuforums! We have cookies! | Basic Ubuntu Security Guide
Tomorrow's an illusion and yesterday's a dream, today is a solution...
ok, It took a little fiddling, but I got the ACPI button to work. the guest had not installed acpid by default so I had to:
but after that, the guest responded correctly to the shutdown request. very nice.Code:sudo apt-get acpid
I will be testing the guest network services on startup and shutdown tonight and tomorrow (server reboots are a little bit of a pain during the day). if all goes well, I'll clean up the script and pass it back if you are interested. I'm a .net/java programmer by trade, so I am used to somewhat cleaner code that shell usually provides. I am always struck by how insanely flexible, yet bizarrely arcane shell is.
after that, all I need to look at running transmission as a service (on the host) and I am golden.
Last edited by doas777; September 24th, 2011 at 09:22 PM.
Things are rarely just crazy enough to work, but they're frequently just crazy enough to fail hilariously.
Glad you got it figured out. Good luck with getting the network issues resolves and transmission to run as a service.
I'd love a copy of the script once you get it up and running.
Come to #ubuntuforums! We have cookies! | Basic Ubuntu Security Guide
Tomorrow's an illusion and yesterday's a dream, today is a solution...
I think I have everything running to my taste now, so here you go. I hope its of use.
New\Notable:
documentation expanded
added a spin-wait to let the vms actually shutdown before exit
new behavoir for force-reload. attempts to gracefully stop, and resets guest if it cannot.
Thanks again, and have fun,
Franklin
Things are rarely just crazy enough to work, but they're frequently just crazy enough to fail hilariously.
Looks good. Nice job!
Come to #ubuntuforums! We have cookies! | Basic Ubuntu Security Guide
Tomorrow's an illusion and yesterday's a dream, today is a solution...
Thank you guys! Those scripts helped me out bigtime! You have done a great job here
Bookmarks