Page 3 of 6 FirstFirst 12345 ... LastLast
Results 21 to 30 of 60

Thread: VBox as a service in Lucid

  1. #21
    Join Date
    Oct 2009
    Beans
    Hidden!
    Distro
    Ubuntu 12.04 Precise Pangolin

    Re: VBox as a service in Lucid

    *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...

  2. #22
    Join Date
    Dec 2007
    Location
    The last place I look
    Beans
    Hidden!
    Distro
    Ubuntu 10.04 Lucid Lynx

    Re: VBox as a service in Lucid

    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.

  3. #23
    Join Date
    Oct 2009
    Beans
    Hidden!
    Distro
    Ubuntu 12.04 Precise Pangolin

    Re: VBox as a service in Lucid

    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...

  4. #24
    Join Date
    Dec 2007
    Location
    The last place I look
    Beans
    Hidden!
    Distro
    Ubuntu 10.04 Lucid Lynx

    Re: VBox as a service in Lucid

    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.

  5. #25
    Join Date
    Oct 2009
    Beans
    Hidden!
    Distro
    Ubuntu 12.04 Precise Pangolin

    Re: VBox as a service in Lucid

    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:

    Code:
     acpipowerbutton
    I think that might be what you are looking for, tho I have not used it. Just replace savestate with that.
    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...

  6. #26
    Join Date
    Dec 2007
    Location
    The last place I look
    Beans
    Hidden!
    Distro
    Ubuntu 10.04 Lucid Lynx

    Re: VBox as a service in Lucid

    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:
    Code:
    sudo apt-get acpid
    but after that, the guest responded correctly to the shutdown request. very nice.

    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.

  7. #27
    Join Date
    Oct 2009
    Beans
    Hidden!
    Distro
    Ubuntu 12.04 Precise Pangolin

    Re: VBox as a service in Lucid

    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...

  8. #28
    Join Date
    Dec 2007
    Location
    The last place I look
    Beans
    Hidden!
    Distro
    Ubuntu 10.04 Lucid Lynx

    Re: VBox as a service in Lucid

    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
    Attached Files Attached Files
    Things are rarely just crazy enough to work, but they're frequently just crazy enough to fail hilariously.

  9. #29
    Join Date
    Oct 2009
    Beans
    Hidden!
    Distro
    Ubuntu 12.04 Precise Pangolin

    Re: VBox as a service in Lucid

    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...

  10. #30
    Join Date
    May 2012
    Beans
    1

    Re: VBox as a service in Lucid

    Thank you guys! Those scripts helped me out bigtime! You have done a great job here

Page 3 of 6 FirstFirst 12345 ... LastLast

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •