If you run a service on the internet it’s a good idea to put it in a virtual machine rather than on the physical linux box or BSD install. It adds a nice security barrier between your machine and the internet and its nasties so if something indeed nasty happens, you can easily revert the VM and your main machine will be safe(r). I won’t be explaining how to set up a virtual machine in the tute as there are many good guides on the net on how to do this. However what I’m going to present here is a quick and dirty way of making sure that if you ever need to restart your physical box then the virtual machine will shutdown and startup on reboot (bounce).
I’m using Oracle VirtualBox virtual machines and openSUSE though it should work on any Redhat and other distros.
My virtual machine’s name is “banana”, yours probably won’t be, so you’ll need to change the code appropriatley.
First create a file in /etc/init.d/ , mine is called vbox_banana and I have the following in it
#!/bin/bash # /etc/init.d/vbox_banana # ### BEGIN INIT INFO # Provides: vbox_banana # Required-Start: $local_fs $remote_fs $network vboxdrv # Should-Start: # Should-Stop: # Required-Stop: # Default-Start: 3 5 # Default-Stop: 0 1 2 6 # X-Interactive: true # Short-Description: banana virtual box # Description: Start the banana virtual box ### END INIT INFO # # main part # PATH=/sbin:/usr/sbin:/usr/bin:/bin LOG=/var/log/banana.log case "$1" in start) echo `date` echo "Starting banana" >> $LOG sudo -u tutuser /usr/bin/VBoxManage startvm "banana" --type headless >> $LOG 2>&1 ;; stop) echo `date` "Stoping banana" >> $LOG sudo -u tutuser /usr/bin/VBoxManage controlvm "banana" acpipowerbutton >> $LOG 2>&1 ;; esac
I suggest replacing the occurance of “banana” with your VM’s name. In “vi” do this by using
Also change the user to the user you want to use to own the VM process – it’s never a good idea to start as root as this gives too many privliages.
Finally add it to the start up init scripts using
sudo chkconfig vbox_banana on
If there are any problems have a look in the log file – cat /var/log/banana.log in this case:
Sun May 27 16:18:15 EST 2012 echo Starting banana Waiting for VM "banana" to power on... VM "banana" has been successfully started.
Please try this out and let us know how you go and if you needed to change anything for your distro then I can update this tut to help others.
Also don’t forget to try out the monkey tool, it’s a great time saver.
Go Back to the tutorial menu page.