MyThinkPond

On Java, Python, Groovy, Grails, Spring, Node.js, Linux, Arduino, ARM, Embedded Devices & Web

Two useful links comparing CentOS 6.X’s – SysV-Init vs CentOS 7.X – SystemD – init systems

Posted by Venkatt Guhesan on July 19, 2016

In CentOS 6.8, the init system that brings up all the services (link autoexec files in Windows) was called SysV- Init. This has been the foundation for ages as long I’ve been using CentOS. But in the latest release of CentOS (CentOS 7+) the init engine has been moved to a more favorable engine labeled SystemD. SystemD is the init engine behind Ubuntu, Fedora, Red Hat and CentOS. So the standardization is good for the Linux community but moving from CentOS 6.8 to CentOS 7 is not a trivial task (especially when it comes to RPMs that working on the SysV-Init paradigm).

Here are two links that outlines the differences:

Cheers!

 

 

Posted in CentOS 6.X, CentOS7, Linux | Tagged: , , , , , , | Leave a Comment »

Tiny storage device writes information atom-by-atom

Posted by Venkatt Guhesan on July 18, 2016

Memory that writes atom-by-atom. 

Approx. 500TB per square inch. 

Entire library of Congress archives can be stored in .1mm square inches. 

Write speed measured in minutes. Not yet ready for prime time but promising future. 

http://www.bbc.co.uk/news/science-environment-36824902

Posted in Uncategorized | Leave a Comment »

WaitUntilPortOpens() – How to wait until process A runs and binds to a port before spawning process B?

Posted by Venkatt Guhesan on July 8, 2016

Sometimes we have situations where you need to wait until one application is loaded that may bind to a certain port before kicking off a second application that may depend on that port. This process is typically described as “Wait-Until-Port-Opens” (or it could be the reverse – where you want to wait until a port closes).

Here are some use-cases for this method or script:

  • You have a Java web application (Jetty, Tomcat, WildFly, etc) that listens on port 8080 and you want your Nginx or Apache HTTPd server to start as a proxy-server once that back-end web server is bound to port 8080.
  • You want to spin off your Kong (microserver management) after, your back-end REST server is up and listening on port 123.
  • Or the reverse, where you want to kick off an email alert-notification, if you are unable to bind to a certain port where your web server runs and it has now crashed.

On a Linux system, this can be accomplished in many ways. Tools like netcat (nc), netstat, telnet makes this very simple. You can write a bash script that accomplishes this easy. But not all footprints may have those libraries installed. For example, if you’re switching from CentOS 6.8 to CentOS 7. A lot of the network tools are no longer available or their binaries are not yet ready for prime-time on the new SystemD footprint in CentOS 7. Netcat is one of those tools not yet ready in the CentOS 7. So you will need a common independent way to scan for the port.

First, let’s look at how this can be done using the above tools:

# Depends on netcat (nc)
# Run netcat and try binding to port 8080 on localhost. 
# If not sleep for five-seconds and repeat until it's available
while ! echo exit | nc localhost 8080; do sleep 5; done

# Variation of the above that depends on netstat utility
while netstat -lnt | awk '$4 ~ /:8080$/ {exit 1}'; do sleep 5; done

# If you know the process-id of your service, then you
PID=1234
while ! lsof -n -Fn -p $PID | grep -q '^n.*:8080$'; do sleep 5; done

# Variation that depends on netchat (nc)
# If the port is open, then do nothing but if the port goes down then react
while ! nc -q 1 localhost 8080 </dev/null; do sleep 5; done

As you can see all the above examples depend on other network tools to be installed on the Linux footprint. This design is good, if you have complete control of the OS and dependent RPMs and libraries that are installed.

If on the other case, if you do not have any of the above libraries such as netcat (nc), netstat, lsof then here is a Linux method to doing the same:

# Most (99.999%) Linux systems have "timeout" and "sleep" commands available so the below 
while ! timeout 1 bash -c "echo > /dev/tcp/localhost/8080"; do sleep 5; done;
# Do something here such as spawning a new service

So how does the above code work? Through the use of “Bash TCP Sockets”. You can learn more about then in the references below:

Tech Tip: TCP/IP Access Using bash

More on Using Bash’s Built-in /dev/tcp File (TCP/IP)

Cheers!

Today’s Inspirational Quote:

Doing what you love is the cornerstone of having abundance in your life.
Wayne Dyer (American philosopher, self-help author, and a motivational speaker)

-AUM

Posted in Bash, CentOS7, Linux | Tagged: , , | Leave a Comment »

bash script to generate config or property file from a template file containing variables

Posted by Venkatt Guhesan on June 23, 2016

Sometimes we have configuration or properties file (as templates) such as httpd.conf or server.conf where we want to dynamically replace $variables with values before writing the output to a new file.

Example:

# httpd.conf.tmpl
<Location $STATUS_URI>
    SetHandler server-status
    Order deny,allow
    Deny from all
    Allow from $MONITOR_IP
</Location>

We want to develop an install script in Bash such that it reads the httpd.conf.tmpl and replaces the $STATUS_URI and $MONITOR_IP with appropriate values (either passed in as script arguments or coded in the bash script) and then write out the resulting output to a new file such as /tmp/httpd.conf

Here is such as script:

#!/usr/bin/env bash

# Define the variables with values you want replaced
STATUS_URI="foobar"
MONITOR_IP="192.168.1.1"
# This could also be read in via bash arguments. 
# Google "bash getopts" for more information

# render a template configuration file
# expand variables + preserve formatting
# user="Venkatt"
# referenced inside the template.txt as $user
# render_template /path/to/template.txt > path/to/configuration_file
function render_template() {
  eval "echo \"$(cat $1)\""
}

function generate_httpd_conf {
  echo "#### Creating /tmp/httpd.conf from template ./httpd.conf.tmpl"
  render_template httpd.conf.tmpl > /tmp/httpd.conf
}

Generated output:

<Location foobar>
    SetHandler server-status
    Order deny,allow
    Deny from all
    Allow from 192.168.1.1
</Location>

This can be a useful method to generate .conf .prop (configuration or properties) files.

Cheers.

And now for today’s inspirational quote:

Let us sacrifice our today so that our children can have a better tomorrow.
Abdul Kalam
– 11th President of India from 2002 to 2007
– Chief ‘Rocket’ Scientist born from a poor family with humble beginnings.
– Lived as a “Man of simplicity”

Posted in Bash, Linux | Tagged: , , , , , | Leave a Comment »

Bizarre fourth state of water discovered

Posted by Venkatt Guhesan on June 18, 2016

Bizarre fourth state of water discovered

Scientists at the Oak Ridge National Lab (ORNL) have discovered that when (water) put under extreme pressure in small spaces, the life-giving liquid can exhibit a strange fourth state known as “tunneling”.

Quantum tunneling means that a particle, or in this case a molecule, can overcome a barrier and be on both sides of it at once – or anywhere in between. Think of rolling a ball down one side of a hill and up another. The second hill is the barrier and the ball would only have enough energy to climb it to the height from which it was originally dropped. If the second hill was taller, the ball wouldn’t be able to roll over it. That’s classical physics. Quantum physics and the concept of tunneling means the ball could jump to the other side of the hill with ease or even be found inside the hill – or on both sides of the hill at once.

  • Gizmag.com

 

Learn more at:

http://www.gizmag.com/fourth-state-of-water/42999/?li_source=LI&li_medium=default-widget

Example of a Beryllium crystal’s hexagonal (six-sided) crystal-structure arrangement:

311px-hexagonal_close_packed-svg

What does this all mean to us?

  1. Microscopically, the universe continues to marvel us with it’s mysteries. If something as simple as water, can display new remarkable properties and states of matter, imaging the permutations and mysteries still locked up when you look at the periodic table of elements as a whole and all the combinations of molecules that exist in nature and some created artificially.
  2. Macroscopically, when you look up on a dark starry night, and you see galaxies upon galaxies and now scientists are debating over multi-verse theories, string theories and branes.  We definitely have a universe full of mysteries to solve.

So we should be fortunate and happy to know that we are living in the best of times where society has evolved beyond our petty differences in beliefs and faith. And we are able to look at each moment in wonder as the universe unveils it’s mysteries like a grand operatic in front of us. And one day, our great-great grandchildren and descendants will  look back at the stepping stones we laid for them in this unraveling.

And since this is around Father’s day, I’m reminded of a proverb in the classical Tamil literature (Book of Proverbs) – Thirukkural  written around 2nd or 3rd BCE, on the topic of “Father” that reflects my sentiment here:

தந்தை மகற்காற்று நன்றி அவையத்து
முந்தி இருப்பச் செயல்.

The benefit which a father should confer on his child is to give him/her precedence in the assembly of the learned.

Thirukkural

Wishing everyone a Happy Fathers Day – 2016!

Cheers!

 

Posted in General, Outdoors & Nature, Science and Technology | Tagged: , , , , | Leave a Comment »

Article: The spherical genius of the Hüttlin Kugelmotor

Posted by Venkatt Guhesan on June 18, 2016

The spherical genius of the Hüttlin Kugelmotor

Electrical motors are an energy-efficient method for driving vehicles but battery technology is simply not going to advance quickly enough for all-electric vehicles to be a practical reality for most uses anytime soon. The near and mid-term future is undoubtedly a combination of compact combustion engine generators charging dense battery packs that drive electric motors – the “range extender” option.

After nearly twenty years of development another “range extender” candidate is going through final testing and it is a work of elegant genius – Dr. Herbert Hüttlin’s Kugelmotor.

– From GizMag.com

kugelmotor-0Learn more here:

http://www.gizmag.com/huttlin-kugelmotor/19923/?li_source=LI&li_medium=default-widget

Posted in General, Science and Technology | Tagged: , , | Leave a Comment »

Appeals Court Hands Obama Administration Major Win In Net Neutrality Case

Posted by Venkatt Guhesan on June 14, 2016

Appeals Court Hands Obama Administration Major Win In Net Neutrality Case

The Obama administration’s rules prevent internet service providers from charging content producers for faster or more reliable service, a practice known as “paid prioritization.” The rules also ban blocking and purposefully slowing the traffic of lawful services, and apply to both mobile and fixed broadband service.

Today’s ruling is a victory for consumers and innovators who deserve unfettered access to the entire web, and it ensures the internet remains a platform for unparalleled innovation, free expression and economic growth

Read more at the link below:

http://www.huffingtonpost.com/entry/court-obama-net-neutrality-rules_us_571a29dce4b0d4d3f722fc46

Posted in In the News, Science and Technology | Tagged: , | Leave a Comment »

New ‘Superman’ crystals can store data for billions of years

Posted by Venkatt Guhesan on June 13, 2016

New ‘Superman’ crystals can store data for billions of years

http://money.cnn.com/2016/02/17/technology/5d-data-storage-memory-crystals/index.html?iid=surge-story-summary

Posted in Science and Technology, Technology | Tagged: , | Leave a Comment »

Intel’s miracle chip could make your gadgets 1,000 times faster

Posted by Venkatt Guhesan on June 13, 2016

Intel and Micron say they have a new computer chip that will make your gadgets significantly faster, more durable and able to store way more data.

http://money.cnn.com/2015/07/29/technology/intel-3d-xpoint-chip/index.html?iid=EL

 

Posted in Science and Technology, Technology | Tagged: , , | Leave a Comment »

Two static website generators explored – Hugo & Jekyll

Posted by Venkatt Guhesan on June 5, 2016

Today I had to quickly assemble a wiki/blog website for our family temple back in India. At first, I considered doing my traditional option to leverage WordPress (this blog MyThinkPond.com uses WordPress). Then I thought of all the complexities of setting up a MySQL database, creating and registering the site with WP Jetpack, etc. I wanted something quick, easy to maintain and something that I can hand over to someone else for maintaining. Most software developers are used to GIT for source-control and if there was a way to keep the source files in a GIT then this opens up the possibility of merely giving thee end-user the access to the GIT repo and they can then either maintain it in the long run or branch it into their own copy. Spending a bit of time researching my options, I came across a suit of tools that allows you to generate static-blogs and wiki. Out of the dozen or so options, I decided to explore the one with the most traffic (namely Jekyll) and one that is ranking fourth but built on GoLang (namely Hugo).

Both Jekyll and Hugo had similar features when it came to Content, Front-Matter, Templates, Taxonomies, Themes, Categories, Sections, support for static content besides blogs, ability to support Markdown syntax for editing. So I would highly recommend both Jekyll and Hugo. What made me opt for Hugo is the simplicity of setup/installation. With Hugo, I had to download one executable [since it was developed in GoLang (one of my *new* favorite languages), it allows for native compilation for many different architectures and operating systems including Windows, Linux, FreeBSD, NetBSD and OS X (Darwin) for x64, i386 and ARM architectures (essentially wherever the Go compiler tool chain can run). Once I unzipped the executable to a directory, all I had to do is to add it onto my $PATH either in Linux or in Windows. And that is all you need to do to get started. Whereas with Jekyll, I had to first install Ruby, then  Ruby Gems, then (gem install jekyll) then NodeJS and optionally Python 2.7 for Jekyll 2 or earlier. The installation steps for getting Jekyll was way too complex. Granted I had most of those tools already installed but for non-developers, this would be a pain-point.

Once Hugo was available on my $path, then to create a blank site all I had to do is as follows:

mkdir myproject
cd myproject
hugo new site sivavishnu .
# Creates a blank starter site with default theme

Now in my case, I am a big fan of Bootstrap. So I googled for a themes built on Bootstrap for Hugo. I came across a few options, which led me to BootsWatch. I found that Nicholas Whittier had created a Hugo-Bootswatch (Thank you Nicholas) theme built on top of Bootswatch&gt;Bootstrap. So to integrate Hugo-Bootswatch to my site, I followed directions on Hugo as follows:

cd myproject
mkdir themes
git clone https://github.com/nilproductions/hugo-bootswatch.git
# This clones a copy of the "hugo-bootswatch" project under my "themes" folder

Now to create some sample blog articles using Hugo:

cd myproject
hugo new post/first.md
# This creates a markdown file under myproject/sivavishnu/content/post/first.md
# You can now edit this file and using Markdown syntax for the headers and HTML for the body

Here is a link to learning Markdown

Now here are two options in Hugo to preview and to generate the site:

# To run a webserver with latest blog (including drafts):
hugo --theme=hugo-bootswatch server --buildDrafts
# To generate the latest blog (under public folder)
hugo --theme=hugo-bootswatch

If you want to then go crazy and create static pages, exclusions from list, customize the CSS by adding some colors, etc you can do
all of this!:-)

But here are two options that you will need to consider:

  1. Since this is a static site (with no back-end server engine like PHP, NodeJS, Tomcat, etc), you will need a way to allow users to search your site. I chose to add Google Site Search as an option. It’s free but the catch is that until Google indexes your site the search option is not functional.
  2. Analytics for your site to trach your hits. See the link in Hugo document for steps.
  3. Adding the ability under blog pages for external users to comment. Again Hugo gives you the option to integrate with Disqus. See link on Hugo document how-to integrate Hugo with Disqus.

This way, all your site is doing is serve a static site. Did I mention that Hugo also generates your static site wicked fast?

So as a last step, I generated the static website and uploaded it to my BlueHost hosting provider.

And don’t forget to check in your code into a GIT repo of your choice. In my case, I’ve checked in my code at BitBucket.org.

Here are the links:

Hope you enjoyed reading this article. Consider subscribing and sharing!

— update

Few folks emailed me asking what those fonts were on the site. It’s one of the oldest spoken languages that exists in Southern India called Tamil.

And now for today’s inspirational quote:

When I stand before God at the end of my life, I would hope that I would not have a single bit of talent left and could say, I used everything you gave me.
– Erma Bombeck

.AUM.

Posted in Hugo, Wiki | Tagged: , , , , , , , , | Leave a Comment »

 
Follow

Get every new post delivered to your Inbox.

Join 160 other followers