<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Taleeb Midi</title>
    <description>The latest articles on DEV Community by Taleeb Midi (@tmidi).</description>
    <link>https://dev.to/tmidi</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F63142%2F3973cb5f-608f-4042-9f6c-141b5b160812.png</url>
      <title>DEV Community: Taleeb Midi</title>
      <link>https://dev.to/tmidi</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/tmidi"/>
    <language>en</language>
    <item>
      <title>Change Directory Up Faster With Back up Command</title>
      <dc:creator>Taleeb Midi</dc:creator>
      <pubDate>Mon, 14 May 2018 00:31:14 +0000</pubDate>
      <link>https://dev.to/tmidi/change-directory-up-faster-with-back-up-command-20k2</link>
      <guid>https://dev.to/tmidi/change-directory-up-faster-with-back-up-command-20k2</guid>
      <description>&lt;p&gt;Posted first on &lt;a href="https://midiroot.com" rel="noopener noreferrer"&gt;midiroot.com&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;&lt;a href="http://donovanbrown.com" rel="noopener noreferrer"&gt;Donovan Brown&lt;/a&gt; wrote a good &lt;a href="http://donovanbrown.com/post/Why-cd-when-you-can-just-backup" rel="noopener noreferrer"&gt;article&lt;/a&gt; showcasing how you can use a custom PowerShell function to navigate up directories without the need to type multiple &lt;code&gt;cd ..&lt;/code&gt; . I find his idea interesting and could be of important time saver if you spend a lot of time working with PowerShell.&lt;/p&gt;

&lt;p&gt;Unfortunately (or fortunately depends how you see it) nowadays I don't use PowerShell a lot, and when I do my usage is limited to few PowerCLI commands, but I do spend a considerable time interacting with Linux Shell, so the natural thing to do is to port Donovan's idea into a Bash script. The Bash script is going to be different from the PowerShell one, but the concept remains the same.&lt;/p&gt;

&lt;p&gt;What we need?&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;A function that take an integer as an argument.&lt;/li&gt;
&lt;li&gt;A help function to display a basic help menu when wrong argument entered.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  The help function:
&lt;/h2&gt;

&lt;p&gt;I like to keep this as simple as possible, since our function will take only one line for the argument and the second line to indicate that this a help menu:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;    &lt;span class="k"&gt;function &lt;/span&gt;bu_usage &lt;span class="o"&gt;()&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
       &lt;span class="nb"&gt;cat&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&amp;lt;-&lt;/span&gt;&lt;span class="no"&gt;EOF&lt;/span&gt;&lt;span class="sh"&gt;
        Usage: bu [N]
                N        Where N is the number of level to move back to. this argument must be an integer.
                h help   displays this basic help menu.
&lt;/span&gt;&lt;span class="no"&gt;        EOF
&lt;/span&gt;    &lt;span class="o"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;I used &lt;code&gt;-EOF&lt;/code&gt; to allow indentation, this work better with tabs than with spaces.&lt;/p&gt;

&lt;h2&gt;
  
  
  The back up function
&lt;/h2&gt;

&lt;p&gt;Now that our help function is out of the way we can start building the backup function. we know the function will take one argument, and this argument must be an integer:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="k"&gt;function &lt;/span&gt;bu &lt;span class="o"&gt;()&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
    &lt;span class="nv"&gt;FUNCTIONARG&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="nv"&gt;$1&lt;/span&gt;
    &lt;span class="c"&gt;# Make sure the provided argument is a positive integer:&lt;/span&gt;
    &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="o"&gt;[[&lt;/span&gt; &lt;span class="o"&gt;!&lt;/span&gt; &lt;span class="nt"&gt;-z&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="k"&gt;${&lt;/span&gt;&lt;span class="nv"&gt;FUNCTIONARG&lt;/span&gt;&lt;span class="p"&gt;##*[!0-9]*&lt;/span&gt;&lt;span class="k"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt; &lt;span class="o"&gt;]]&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="k"&gt;then
        for &lt;/span&gt;i &lt;span class="k"&gt;in&lt;/span&gt; &lt;span class="si"&gt;$(&lt;/span&gt;&lt;span class="nb"&gt;seq &lt;/span&gt;1 &lt;span class="nv"&gt;$FUNCTIONARG&lt;/span&gt;&lt;span class="si"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="k"&gt;do
            &lt;/span&gt;STRARGMNT+&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"../"&lt;/span&gt;
        &lt;span class="k"&gt;done
        &lt;/span&gt;&lt;span class="nv"&gt;CMD&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"cd &lt;/span&gt;&lt;span class="k"&gt;${&lt;/span&gt;&lt;span class="nv"&gt;STRARGMNT&lt;/span&gt;&lt;span class="k"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;
        &lt;span class="nb"&gt;eval&lt;/span&gt; &lt;span class="nv"&gt;$CMD&lt;/span&gt;
    &lt;span class="k"&gt;else
        &lt;/span&gt;bu_usage
    &lt;span class="k"&gt;fi&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;How this works?&lt;/strong&gt; the functions starts first by making sure the argument is a valid integer, if not it will call the help function we created earlier. Then using a sequence of numbers from 1 to the argument, we will append &lt;code&gt;../&lt;/code&gt; string to &lt;code&gt;STRARGMNT&lt;/code&gt; with each iteration. When the for loop is complete we run &lt;code&gt;cd&lt;/code&gt; command with all the final appended up directories. This will give us:&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;argument&lt;/th&gt;
&lt;th&gt;command&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;1&lt;/td&gt;
&lt;td&gt;cd ..&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;2&lt;/td&gt;
&lt;td&gt;cd ../..&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;3&lt;/td&gt;
&lt;td&gt;cd ../../..&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;h2&gt;
  
  
  How to use this?
&lt;/h2&gt;

&lt;p&gt;I usually add functions like these to a &lt;code&gt;.functions&lt;/code&gt; file under my home directory, the function file get sources by &lt;code&gt;.bash_profile&lt;/code&gt;.&lt;br&gt;
To source &lt;code&gt;.functions&lt;/code&gt; or other dotfiles add this for loop to your &lt;code&gt;.bash_profile&lt;/code&gt;, files must be comma separated:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="k"&gt;for &lt;/span&gt;file &lt;span class="k"&gt;in&lt;/span&gt; ~/.&lt;span class="o"&gt;{&lt;/span&gt;functions&lt;span class="o"&gt;}&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="k"&gt;do&lt;/span&gt;
    &lt;span class="o"&gt;[&lt;/span&gt; &lt;span class="nt"&gt;-r&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="nv"&gt;$file&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt; &lt;span class="se"&gt;\]&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class="se"&gt;\[&lt;/span&gt; &lt;span class="nt"&gt;-f&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="nv"&gt;$file&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt; &lt;span class="se"&gt;\]&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class="nb"&gt;source&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="nv"&gt;$file&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;done&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="nb"&gt;unset &lt;/span&gt;file&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Create &lt;code&gt;.functions&lt;/code&gt; and add this content to it:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt; &lt;span class="k"&gt;function &lt;/span&gt;bu &lt;span class="o"&gt;()&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;function &lt;/span&gt;bu_usage &lt;span class="o"&gt;()&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
       &lt;span class="nb"&gt;cat&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&amp;lt;-&lt;/span&gt;&lt;span class="no"&gt;EOF&lt;/span&gt;&lt;span class="sh"&gt;
        Usage: bu [N]
                N        Where N is the number of level to move back to. this argument must be an integer.
                h help   displays this basic help menu.
&lt;/span&gt;&lt;span class="no"&gt;        EOF
&lt;/span&gt;    &lt;span class="o"&gt;}&lt;/span&gt;


    &lt;span class="c"&gt;# unset variables&lt;/span&gt;
    &lt;span class="nv"&gt;STRARGMNT&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;""&lt;/span&gt;
    &lt;span class="nv"&gt;FUNCTIONARG&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="nv"&gt;$1&lt;/span&gt;

    &lt;span class="c"&gt;# Make sure the provided argument is a positive integer:&lt;/span&gt;
    &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="o"&gt;[[&lt;/span&gt; &lt;span class="o"&gt;!&lt;/span&gt; &lt;span class="nt"&gt;-z&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="k"&gt;${&lt;/span&gt;&lt;span class="nv"&gt;FUNCTIONARG&lt;/span&gt;&lt;span class="p"&gt;##*[!0-9]*&lt;/span&gt;&lt;span class="k"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt; &lt;span class="o"&gt;]]&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="k"&gt;then
        for &lt;/span&gt;i &lt;span class="k"&gt;in&lt;/span&gt; &lt;span class="si"&gt;$(&lt;/span&gt;&lt;span class="nb"&gt;seq &lt;/span&gt;1 &lt;span class="nv"&gt;$FUNCTIONARG&lt;/span&gt;&lt;span class="si"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="k"&gt;do
            &lt;/span&gt;STRARGMNT+&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"../"&lt;/span&gt;
        &lt;span class="k"&gt;done
        &lt;/span&gt;&lt;span class="nv"&gt;CMD&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"cd &lt;/span&gt;&lt;span class="k"&gt;${&lt;/span&gt;&lt;span class="nv"&gt;STRARGMNT&lt;/span&gt;&lt;span class="k"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;
        &lt;span class="nb"&gt;eval&lt;/span&gt; &lt;span class="nv"&gt;$CMD&lt;/span&gt;
    &lt;span class="k"&gt;else
        &lt;/span&gt;bu_usage
    &lt;span class="k"&gt;fi&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This is slightly different from the previous functions we created. The help menu is a nested function inside the main &lt;code&gt;bu&lt;/code&gt; function. we also created empty &lt;code&gt;STRARGMNT&lt;/code&gt; to unset the variable each time the function runs.&lt;/p&gt;

&lt;p&gt;When you are done &lt;code&gt;source .bash_profile&lt;/code&gt; or close and reopen your terminal for the change to take effect&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;how to run?&lt;/strong&gt;&lt;br&gt;
&lt;code&gt;bu help&lt;/code&gt; or &lt;code&gt;bu -h&lt;/code&gt; for help menu.&lt;br&gt;
&lt;code&gt;bu 2&lt;/code&gt; to go two folders up, this is the equivalent of running &lt;code&gt;cd ..\..\&lt;/code&gt;&lt;br&gt;
you can see &lt;code&gt;bu&lt;/code&gt; in action here(external link):&lt;/p&gt;

&lt;p&gt;&lt;a href="https://asciinema.org/a/Serx0ac08heiRW4QI61FW2QKv" rel="noopener noreferrer"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fasciinema.org%2Fa%2FSerx0ac08heiRW4QI61FW2QKv.png" alt="asciicast"&gt;&lt;/a&gt;&lt;/p&gt;

</description>
      <category>bash</category>
      <category>shell</category>
    </item>
    <item>
      <title>Getting started with HAProxy: Install from code source</title>
      <dc:creator>Taleeb Midi</dc:creator>
      <pubDate>Mon, 14 May 2018 00:24:27 +0000</pubDate>
      <link>https://dev.to/tmidi/getting-started-with-haproxy-install-from-code-source-5c4g</link>
      <guid>https://dev.to/tmidi/getting-started-with-haproxy-install-from-code-source-5c4g</guid>
      <description>&lt;h2&gt;
  
  
  intro
&lt;/h2&gt;

&lt;p&gt;In this post, which is taken from my &lt;a href="https://midiroot.com/post/haproxy-getting-started/"&gt;personal blog&lt;/a&gt;, I will demonstrate how we can install HAProxy from source code. According to &lt;a href="https://en.wikipedia.org/wiki/HAProxy"&gt;Wikipedia&lt;/a&gt;, HAProxy was written and still maintained by &lt;a href="http://1wt.eu/#wami"&gt;Willy Tarreau&lt;/a&gt; since 2000. HAProxy is free open source software (FOSS), that provides a high availability load balancer and proxy server for TCP (Transmission Control Protocol) and HTTP (Hypertext Transfer Protocol) based applications that spreads requests across multiple servers. It is written in &lt;strong&gt;C&lt;/strong&gt; language and thus the reputation for being fast and efficient.&lt;/p&gt;

&lt;p&gt;If you are curious, this &lt;a href="http://www.haproxy.org/#feat"&gt;HAProxy Page&lt;/a&gt; offers more details about its features.&lt;/p&gt;

&lt;h2&gt;
  
  
  Installation
&lt;/h2&gt;

&lt;p&gt;In this guide , we will be installing the latest stable version of 1.8 (as of May 09, 2018). the current HAProxy available under RHEL is &lt;code&gt;1.5.18&lt;/code&gt; and &lt;code&gt;1.8.8&lt;/code&gt; on Debian/Ubuntu. before taking the next step, make sure you have &lt;code&gt;gcc&lt;/code&gt;, &lt;code&gt;pcre-static&lt;/code&gt; and &lt;code&gt;pcre-devel&lt;/code&gt; installed:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;# CentOS RHEL:
sudo yum -y install make gcc perl pcre-devel zlib-devel

# Debian/Ubuntu:
sudo apt install make gcc perl pcre-devel zlib-devel
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;Enable IP forwarding and binding to non-local IP addresses:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;# echo "net.ipv4.ip_forward = 1" &amp;gt;&amp;gt; /etc/sysctl.conf
# echo "net.ipv4.ip_nonlocal_bind = 1" &amp;gt;&amp;gt; /etc/sysctl.conf
# sysctl -p
net.ipv4.ip_forward = 1
net.ipv4.ip_nonlocal_bind = 1
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;Download the source code:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;wget https://www.haproxy.org/download/1.8/src/haproxy-1.8.8.tar.gz
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;Extract the file and change directory:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;tar xvzf haproxy-1.8.8.tar.gz &amp;amp;&amp;amp; cd haproxy-1.8.8
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;Compile the program:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;make TARGET=linux2628 USE_PCRE=1 USE_OPENSSL=1 USE_ZLIB=1
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;This is the list of TARGETs:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;linux22     for Linux 2.2&lt;/li&gt;
&lt;li&gt;linux24     for Linux 2.4 and above (default)&lt;/li&gt;
&lt;li&gt;linux24e    for Linux 2.4 with support for a working epoll (&amp;gt; 0.21)&lt;/li&gt;
&lt;li&gt;linux26     for Linux 2.6 and above&lt;/li&gt;
&lt;li&gt;linux2628   for Linux 2.6.28, 3.x, and above (enables splice and tproxy)&lt;/li&gt;
&lt;li&gt;solaris     for Solaris 8 or 10 (others untested)&lt;/li&gt;
&lt;li&gt;freebsd     for FreeBSD 5 to 10 (others untested)&lt;/li&gt;
&lt;li&gt;netbsd      for NetBSD&lt;/li&gt;
&lt;li&gt;osx         for Mac OS/X&lt;/li&gt;
&lt;li&gt;openbsd     for OpenBSD 5.7 and above&lt;/li&gt;
&lt;li&gt;aix51       for AIX 5.1&lt;/li&gt;
&lt;li&gt;aix52       for AIX 5.2&lt;/li&gt;
&lt;li&gt;cygwin      for Cygwin&lt;/li&gt;
&lt;li&gt;haiku       for Haiku&lt;/li&gt;
&lt;li&gt;generic     for any other OS or version.&lt;/li&gt;
&lt;li&gt;custom      to manually adjust every setting&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;You can also compile the program with following options:&lt;br&gt;
USE_PCRE=1 to use libpcre, in whatever form is available on your system (shared or static).&lt;br&gt;
USE_ZLIP=1 to use zlib compression Library.&lt;br&gt;
USE_OPENSSL=1 to add native support for SSL using the GNU makefile.&lt;/p&gt;

&lt;p&gt;Install HAProxy:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;sudo make install
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;With that, we should now have the chosen HAProxy version installed. now we need to setup HAProxy.&lt;/p&gt;

&lt;h2&gt;
  
  
  Setup:
&lt;/h2&gt;

&lt;p&gt;Adding HAProxy user:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;id -u haproxy &amp;amp;&amp;gt; /dev/null || useradd -s /usr/sbin/nologin -r haproxy
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;Copy HAProxy binary located in the extracted HAProxy directory to &lt;code&gt;/usr/sbin/&lt;/code&gt;:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;cp haproxy /usr/sbin/
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;Create Manual page:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;wget -qO - https://raw.githubusercontent.com/horms/haproxy/master/doc/configuration.txt | gzip -c &amp;gt; /usr/share/doc/haproxy/configuration.txt.gz
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;Create Systemd service script to manage HAProxy, use the following at your discretion:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;sudo wget https://gist.githubusercontent.com/tmidi/1699a358533ae876513e2887fec6fbe2/raw/6c07ce39adc56c731d2bbeb88b90d8bbc636f3ea/haproxy.service -O /lib/systemd/system/haproxy.service
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;or create &lt;code&gt;/lib/systemd/system/haproxy.service&lt;/code&gt; with the following content: &lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;[Unit]
Description=HAProxy Load Balancer
Documentation=man:haproxy(1)
Documentation=file:/usr/share/doc/haproxy/configuration.txt.gz
# allows us to do millisecond level restarts without triggering alert in Systemd
StartLimitInterval=0
StartLimitBurst=0
After=network.target syslog.service
Wants=syslog.service

[Service]
Environment="CONFIG=/etc/haproxy/haproxy.cfg" "PIDFILE=/run/haproxy.pid"
# EXTRAOPTS and RELOADOPS come from this default file
EnvironmentFile=-/etc/default/haproxy
ExecStartPre=/usr/sbin/haproxy -f $CONFIG -c -q
ExecStart=/usr/sbin/haproxy -W -f $CONFIG -p $PIDFILE $EXTRAOPTS
ExecReload=/usr/sbin/haproxy -f $CONFIG -c -q $EXTRAOPTS $RELOADOPTS
ExecReload=/bin/kill -USR2 $MAINPID
KillMode=mixed
Restart=always
Type=forking

[Install]
WantedBy=multi-user.target
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;Enable and start &lt;code&gt;haproxy.service&lt;/code&gt;:&lt;/p&gt;


&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;systemctl enablle haproxy.service&lt;br&gt;
systemctl start haproxy.service&lt;br&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;h2&gt;
&lt;br&gt;
  &lt;br&gt;
  &lt;br&gt;
  Conclusion&lt;br&gt;
&lt;/h2&gt;

&lt;p&gt;This conclude conclude HAProxy installation steps.This guide however covers only the installation steps, in future post I will demonstrate how to configure HAProxy to load balance three backend web servers while using sticky session and SSL Pass-through.&lt;/p&gt;

&lt;p&gt;If you find this guide helpful, please share it with your friends and colleagues. I am on &lt;a href="https://twitter.com/taleeb_midi"&gt;Twitter&lt;/a&gt; and &lt;a href="https://www.linkedin.com/in/taleebmidi/"&gt;LinkedIn&lt;/a&gt;, let's connect or let me know if you have any question or any suggestions.&lt;/p&gt;

</description>
      <category>haproxy</category>
      <category>setup</category>
      <category>install</category>
    </item>
    <item>
      <title>Ansible: Directory Layout</title>
      <dc:creator>Taleeb Midi</dc:creator>
      <pubDate>Fri, 16 Feb 2018 04:48:26 +0000</pubDate>
      <link>https://dev.to/tmidi/ansible-directory-layout-5edj</link>
      <guid>https://dev.to/tmidi/ansible-directory-layout-5edj</guid>
      <description>&lt;p&gt;According to Ansible's &lt;a href="http://docs.ansible.com/ansible/latest/playbooks_best_practices.html"&gt;Best Practices&lt;/a&gt;, There are many possible ways to organize playbook content, and that the usage of such layout should fit your needs. The only thing I highly recommend is using &lt;em&gt;roles&lt;/em&gt; instead of tasks, this will give your flexibility and better organization of your code.&lt;/p&gt;

&lt;p&gt;Ansible provide two examples of directory layouts. the first one is pretty simple and the one I go to when I am working on a small environement with a sample production and staging inventory files:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;production                # inventory file for production servers
staging                   # inventory file for staging environment

group_vars/
   group1                 # here we assign variables to particular groups
   group2                 # ""
host_vars/
   hostname1              # if systems need specific variables, put them here
   hostname2              # ""

library/                  # if any custom modules, put them here (optional)
module_utils/             # if any custom module_utils to support modules, put them here (optional)
filter_plugins/           # if any custom filter plugins, put them here (optional)

site.yml                  # master playbook
webservers.yml            # playbook for webserver tier
dbservers.yml             # playbook for dbserver tier

roles/
    common/               # this hierarchy represents a "role"
        tasks/            #
            main.yml      #  &amp;lt;-- tasks file can include smaller files if warranted
        handlers/         #
            main.yml      #  &amp;lt;-- handlers file
        templates/        #  &amp;lt;-- files for use with the template resource
            ntp.conf.j2   #  &amp;lt;------- templates end in .j2
        files/            #
            bar.txt       #  &amp;lt;-- files for use with the copy resource
            foo.sh        #  &amp;lt;-- script files for use with the script resource
        vars/             #
            main.yml      #  &amp;lt;-- variables associated with this role
        defaults/         #
            main.yml      #  &amp;lt;-- default lower priority variables for this role
        meta/             #
            main.yml      #  &amp;lt;-- role dependencies
        library/          # roles can also include custom modules
        module_utils/     # roles can also include custom module_utils
        lookup_plugins/   # or other types of plugins, like lookup in this case

    webtier/              # same kind of structure as "common" was above, done for the webtier role
    monitoring/           # ""
    fooapp/               # ""
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;I always use the following command to create the above directory structure and get started as soon as possible:&lt;/p&gt;

&lt;pre&gt;
  &lt;code&gt;
mkdir -p group_vars host_vars library module_utils filter_plugins
mkdir -p roles/common/{tasks,handlers,templates,files,vars,defaults,meta,library,module_utils,lookup_plugins}
touch production staging site.yml roles/common/{tasks,handlers,templates,files,vars,defaults,meta}/main.yml
  &lt;/code&gt;
&lt;/pre&gt;

&lt;p&gt;When I have a more complex inventory, with multiple groups and children, I opt for this alternative directory layout:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;inventories/
   production/
      hosts               # inventory file for production servers
      group_vars/
         group1           # here we assign variables to particular groups
         group2           # ""
      host_vars/
         hostname1        # if systems need specific variables, put them here
         hostname2        # ""

   staging/
      hosts               # inventory file for staging environment
      group_vars/
         group1           # here we assign variables to particular groups
         group2           # ""
      host_vars/
         stagehost1       # if systems need specific variables, put them here
         stagehost2       # ""

library/
module_utils/
filter_plugins/

site.yml
webservers.yml
dbservers.yml

roles/
    common/               # this hierarchy represents a "role"
        tasks/            #
            main.yml      #  &amp;lt;-- tasks file can include smaller files if warranted
        handlers/         #
            main.yml      #  &amp;lt;-- handlers file
        templates/        #  &amp;lt;-- files for use with the template resource
            ntp.conf.j2   #  &amp;lt;------- templates end in .j2
        files/            #
            bar.txt       #  &amp;lt;-- files for use with the copy resource
            foo.sh        #  &amp;lt;-- script files for use with the script resource
        vars/             #
            main.yml      #  &amp;lt;-- variables associated with this role
        defaults/         #
            main.yml      #  &amp;lt;-- default lower priority variables for this role
        meta/             #
            main.yml      #  &amp;lt;-- role dependencies
        library/          # roles can also include custom modules
        module_utils/     # roles can also include custom module_utils
        lookup_plugins/   # or other types of plugins, like lookup in this case
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;With this structure, I can put each inventory file with its &lt;code&gt;group_vars&lt;/code&gt;\&lt;code&gt;host_vars&lt;/code&gt; in separate directory. To quickly spin up this directory layout, I use the following commands:&lt;/p&gt;

&lt;pre&gt;
  &lt;code&gt;
mkdir -p inventories/{production,staging}/{group_vars,host_vars}
touch inventories/{production,staging}/hosts
mkdir -p group_vars host_vars library module_utils filter_plugins
mkdir -p roles/common/{tasks,handlers,templates,files,vars,defaults,meta,library,module_utils,lookup_plugins}
touch site.yml roles/common/{tasks,handlers,templates,files,vars,defaults,meta}/main.yml
  &lt;/code&gt;
&lt;/pre&gt;

&lt;p&gt;I usually don't do any work on &lt;code&gt;roles/common&lt;/code&gt;, to create a new role I just duplicate &lt;code&gt;common&lt;/code&gt; to a new directory, this way I have a role template that I can use whenever I want to create a new role.&lt;/p&gt;

</description>
      <category>ansible</category>
      <category>bash</category>
    </item>
  </channel>
</rss>
