Thursday, 16 June 2016

Developer Days VM Startup and Shutdown, SQLcl

If you're developing on a remote platform, chances are that you are using a Virtual Machine. (VM)  In Oracle, we release a virtual machine called the  "Oracle Developer Days".    This is available on the Oracle Technology Network and ala google.  Todays hack is setting up headless vm's, ports and aliases to speed up your day. (This post took a lot longer to write that the aliases we set up!)

For this virtual machine on Virtual Box, we have a bunch of cool stuff to get your teeth into, prebuilt and configured, ready to go.  Most of the time, we all start our VM from the virtual box front end like this from the application and use the guy front end into the VM.



You can click on the network tab and click port forwarding to see how you are allowing access to this virtual machine.



Clicking on your VM in the user interface, you can start it up and get the full GUI to work from.

Normal VM startup within the GUI
This takes a while and has to be done every time you are starting up which is too many times.  Like any engineer, we are all trying to reduce the number of times we have to do the same thing so I like to make these into command line calls and make the GUI disappear so we can ssh into the virtual machine.

From above, we can see that ssh is mapped to port 2222 on the host for this guest virtual machine so there should be no issues in working this way.   To startup your VM from the command line like above, run this below (obviously changing the name of your VM before you do!)  This will open a window and startup your VM.

vboxmanage startvm "Oracle DB Developer VM" --type=gui

You can also start up your virtual machine in a headless session, you can run this command, very similar to the one above to do that.

(bamcgill@daedalus)–(0|ttys001|-bash)
(~) $vboxmanage startvm "Oracle DB Developer VM" --type headless
Waiting for VM "Oracle DB Developer VM" to power on...
VM "Oracle DB Developer VM" has been successfully started.
(bamcgill@ daedalus)–(0|ttys001|-bash)
(~) $

and thats it. the machine will boot, start the database and start the listeners.  you can then ssh into your machine like this.

(bamcgill@ daedalus)–(0|ttys001|-bash)
(~) $ssh -p 2222 oracle@localhost
oracle@localhost's password: 
Last login: Thu Jun 16 07:35:21 2016
[oracle@vbgeneric ~]$ sqlplus barry/oracle

SQL*Plus: Release 12.1.0.2.0 Production on Thu Jun 16 07:38:20 2016

Copyright (c) 1982, 2014, Oracle.  All rights reserved.

Last Successful login time: Thu Jun 16 2016 06:30:17 -04:00

Connected to:
Oracle Database 12c Enterprise Edition Release 12.1.0.2.0 - 64bit Production
With the Partitioning, OLAP, Advanced Analytics and Real Application Testing options

SQL> Disconnected from Oracle Database 12c Enterprise Edition Release 12.1.0.2.0 - 64bit Production
With the Partitioning, OLAP, Advanced Analytics and Real Application Testing options
[oracle@vbgeneric ~]$ logout
Connection to localhost closed.
(bamcgill@daedalus)–(0|ttys001|-bash)
(~) $

All very cool and means I can have aliases setup to do this too so I don't have to remember all the long bits of a vboxmanage statement!

(bamcgill@daedalus)–(0|ttys001|-bash)
(~) $alias | grep vbox
alias headless='vboxmanage startvm "Oracle DB Developer VM" --type headless'
alias poweroff='vboxmanage controlvm "Oracle DB Developer VM" poweroff'
alias startvm='vboxmanage startvm "Oracle DB Developer VM" --type=gui'
alias vboxsave='vboxmanage controlvm "Oracle DB Developer VM" savestate'
(bamcgill@daedalus)–(0|ttys001|-bash)
(~) $

poweroff  rips the rug from under the VM and it is reset
savestate saves the VM like a most recent snapshot and when started again, the VM is refreshed with this state.

When all this is setup, you can connect with SQLcl.  By default, sqlcl will look at a few connect strings when you connect, so you can try sql user/password in your host machine.

(bamcgill@ daedalus)–(0|ttys001|-bash)
(~) $sql barry/oracle

SQLcl: Release 4.2.0.16.167.1601 RC on Thu Jun 16 13:01:44 2016

Copyright (c) 1982, 2016, Oracle.  All rights reserved.

Last Successful login time: Thu Jun 16 2016 13:01:44 +01:00

Connected to:
Oracle Database 12c Enterprise Edition Release 12.1.0.2.0 - 64bit Production
With the Partitioning, OLAP, Advanced Analytics and Real Application Testing options


BARRY@orcl🍻🍺 >

Fantastic.  Look out for more great features on Oracle SQLcl and SQLDeveloper  with Kris, Jeff , Dermot and  Turloch 
SaveSave