Archive for November, 2018

Putty load as default session another session – Save other Putty session configuration to default howto

Thursday, November 29th, 2018

putty-load-button-screenshot

Recently I had to use PuTTY which I haven't used for years to open a number of SSH Pernanent Tunnels necessery for my daily work as a SAP Consultant.

I've saved them under a certain new profile and saved the set SSH Tunnel configuration not in the default Session but in separate named one, therefore had to press Load button every time after clicking over my Putty shortcut icon. 

That was annoying and took few seconds out of my life every next morning for about a week, so finally I found osme time to google it and it seemed it is pretty easy to have any Putty sessoin loaded you like.

Here is how:

1. Create a new Putty Shortcut

putty-screenshot1

putty-shortcut-screenshot-windows

Click over Putty icon while holding CTRL + SHIFT (Control SHIFT keys simultaneously ) and move the mouse somewhere on the desktop to create the shortcut.
 

2. Right click on Putty Shortcut

putty-target-screenshot-windows1

putty-target-screenshot-windows2

 

"C:\Program Files\PuTTY\putty.exe" -load "your_saved_session" "username@your_server_address" -pw "your_password"


fill out "target" field of shortcut using above code (alter to your own properties).
click Apply button.

If you need to pass a user and password from Shortcut itself (which is a bad practice for security but sometimes useful, for not so important Tunnels – for example a tunnel to an Open Proxy), do it by typing in the target field like so:
 

"C:\Program Files\PuTTY\putty.exe" -load "your_saved_session" "username@your_server_address" -pw "your_password"

 

And Hooray !!! After that when you click on PuTTy shortcut it loads your session automatically using given username and password.

Prevent rsync cronjob to run multiple times via cronjob on Linux

Wednesday, November 21st, 2018

prevent-rsync-rsync-to-run-multiple-times-via-cronjob-on-linux

Today I had a report of a server whose Load Avarage keeps at the high level of 86, the machine runs on a bare metal rock solid hardware and even with such high Loads of the kernel it runs fine, but due to the I/O overhead the SANs red from a remote NetApp storage device started to be sluggish and hence it needed to be reviewed, thus I jumped in via the hop station (jump host) into the server.
 

1. Short investation on root cause for high server load


After a short investigation, I've found an rsync job set by someone on a cron job to be routinely run every 30 minutes, thus the old scheduled rsync, which seemed to run multiple times on the server (about 50 processes) of same rsync (file system synchronization was running) and as expected the storage was saddled with mutiple Input / Output requests.

The root cron job was like that:
 

server:~# crontab -u root -l |grep -i rsync
/usr/bin/rsync -ax /var/www/htdocs/directory_to_synchronize / /srv/www/synch_back/directory_to_synchrnize


A process list showed the following high number of running mirrored rsyncs:

 

server:~# ps axuwwf | grep -i rsync | wc -l
80


 

2. The Fix – Set Rsync to only via cron only in case if it is not already running in background


In order to fix it, I had to kill all current running rsync (here luckily only same single instance of rsync was running, but generally I was cautious to check no other rsync jobs are running – otherwise I would have mistakenly killed some other rsync job ongoing …)

Then I set the following new cron job one liner quick shell script that does the job to assign a pid file that is created before rsync and deleted after rsync completion.
 

if [ ! -e /tmp/repo_dba_sync.lock ]; then touch /tmp/repo_dba_sync.lock; /usr/bin/rsync -ax /var/www/htdocs/directory_to_synchronize / /srv/www/synch_back/directory_to_synchrnize ; trap 'rm -f /tmp/repo_dba_sync.lock; fi' EXIT  >/dev/null 2>&1


The cron job looked like so:

 

*/30 * * * * if [ ! -e /tmp/repo_dba_sync.lock ]; then touch /tmp/repo_dba_sync.lock; /usr/bin/rsync -ax /var/www/htdocs/directory_to_synchronize / /srv/www/synch_back/directory_to_synchrnize ; trap 'rm -f /tmp/repo_dba_sync.lock; fi'  EXIT >/dev/null 2>&1

Just in case if you're wondering
a trap should be used to verify that the lock file is removed when the script is exited for any reason.
This way the lock file will be removed even if the script exits before the end of the script.

An alternative and more simple ways to do it is via:
 

pgrep rsync > /dev/null || rsync -ax /var/www/htdocs/directory_to_synchronize / /srv/www/synch_back/directory_to_synchrnize

 

Or if you don't want to use bash's:
 

if []; then; fi


condition but still use a file lock the flock command can be used like so:
 

flock -n lock_file -c "rsync …"

Flight to Dresden German via Munchen and a few impressions about Dresden

Tuesday, November 13th, 2018

Dresden-Germany-side-view

Last week I've flew to Germany to start as a contractor for Itelligence AG a SAP contractor company on its own. 
I've been hired by a small bulgarian company called BST (Business Services and Technologies), but let me skip the details and go to the main goal of article to just share few impressions on my flight from Sofia Airport Terminal 2 (code named SOF), Bulgaria to Germany Munich Airport (Flughafen Munich – codename MMC).

Flight To Munich

My flight was an International one from Sofia to Munich and then a secondary (local Germany Shengen zone flight Dresden -> Munich) and this happens to be my second flight with Lufthansa, previous one was from Sofia -> Poland, Warsaw see my previous blog post Trip from Sofia Bulgaria to Minsk Belarus through Warsaw and how to issue VISA for Belarus.

a320-lufthansa-airbus-plane

Airbus-A320-LH-168-Lufthansa-passengers-placing
Both flights went pretty smoothly and I can confirm the general good reputation of Lufthansa as a flight company, the first flight was the longer one about 2 hours flight on a Airbus A320 which is a relatively big plane.

The second flight which was a short one about an 1 hour time was on a small Charter plane with the funny name Bombardier CRJ 900.

Bombardier_CRJ_900-airplane-Lufthansa_CityLine

Bombardier-CRJ900-plane-placing-Lufthansa

Well I thought good that I've been send for a Company Start-up training but I never planned bombing Germans 🙂 … But well enought jokes, its enough the hell they went through mainly from British and American bombings during  World War II …

Anyways the trip with both planes went smoothly thanks God. This time I travelled with my future colleague Hristos Hristov and as always the travel with someone is less scary and more enjoyable.

The Munich to Dresden flight

The Munich (the German word for Munchen) airport  is the second-busiest airport in Germany in terms of passenger traffic after Franfurt Airport and the 7th busiest airport in Europe and is in the top 40 biggest airports in the world, even though that if compared to Netherlands Schiphol airport it was a cozy and a very easy to orient, the passport control after the flight was a quick and efficient in a German way. We had to further reach for Terminal E on the airport and it happened that to reach the Terminal we need to pick-up a an S-Bahn train (a free one) which moved us to the other opposite passengers building.

Deutschland-DDR_flag

East Germany DDR Times Flag


An Airport Surprise The East German Car of Future 🙂 Trabant !

Arriving in Dresden around 12:30, my first impression was the Trabant car (old cardboard made of car produced in the times of DDR (Deutsche Demokratische Republic) / GDR or (German Democratic Republic) was state a part of the Eastern Bloc (Communist Bloc). 
 

Trabant-Dresden-airport-Germany
Trabant was like the car of the future, it was low cost cheap to produce, very light (a one person could move the car!) used little gasoline to run but it used a lot of oil 🙂
In Bulgaria it was a mass used car during Socialist Times. Nowadays the car is sold mostly in United States as an antique
for its low price. For example in Bulgaria one can buy one of this cardboard cars for 150 EUR or so 🙂

The problem with the car is if you enter an accident with 50 to 70 km you die 100%, so it is only suitable for small villages nowadays or maximum of a small town use for short distances.

Dresden-Trabbi-picture-the-Eastern-Block-cardboard-car

The car is super simplistic and surprisingly has even a baggage space in the back 🙂

Trabant_inside-the-car

Trabant_Engine_Block

For more check what wikipedia says about this magical car Trabant 🙂  …


The Transportation in Dresden (ticket fees and few impressions)

Immediately on Dresden's airport we head to information and asked the nice German old lady on how and where we can buy a monthly all transport ticket for Dresden and Surprise, Surprise the ticket was sold on Information Kiosk itself it costed 61.50 EURO (divided by 30 days that's about 2.05 eur per day), for Germany its a great price.
The normal ticket costs 2.80 eur per single trip and 6 euro for a daily ticket for all transports. 
To arrive to Dresden Central from Airport it was quite quick and efficient with the S-Bahn (S-Train) which is partially kinda of partially underground train similar to Metro for rapid transportation but not exactly. Iit seems this transport is very popular in Germany and Austria).

S-Bahn-Mehrverkehr_03-S-Train-rapid-transit-system

To arrive to Dresden Main (Central) Train Station, we had to travel to Haupbahnhof – the German Word for TrainStation and go down on Dresden Hbf.
Dresden-S-Bahn-Lines.svg

Schema for S-Bahn Dresden Germany


Dresden-autobahnohf-neustadt

We had reservation for Hotel Terrasenufer which is on old socialist times Hotel situated 5 minutes from the Dresden Old City (Alt City) with an unique sideview to Elba River.

Trams-in-Dresden-how-they-look-in-2018.jpg
To reach there, we had to walk about 300 meters and pick up a Tram number 3 and go down on stop the Synagogue tram stop.
Trams in Dresden are clean modern and very fast, so you have a speed which can be a concurrency of a normal Metro.
The overall infrastructure the bus stops and everything is outstanding and designed obviously by great Dresdners great engineering mind.
The city's transportation includes Bus / Tram and Trolley and the frequence of shuttles is really short about 3 / 5 to 10 minutes time.
For most important destinations New / Old / City, I've used Tram or bus number 3 / 7 or 8.

The Synagogue

The Synagogue stop is called that way for a reason as on those stop there is a new rebuild Jewish Synagogue ​
– The Fuhrer Adolf Hitler would definitely not been happy to see it in 2018, but as the War hell is over and German attitudes to Jewish are friendly that's not a problem.

Dresden-Synagogue-building-and-a-bus-station


Hotel Terrasenufer

As I've seen it being lighted and many people to go and go the building it seems the Synagogue is functioning.

Terrasenufer-hotel-near-Dresden-city-center-for-a-non-smoker-hotel

The Terrassenufer is an inner city street in the city center of Dresden directly on the left bank of the Elbe and part of an important inner-city east-west axis. It runs on the northern edge of the districts Inner Old Town and Pirnaische suburb, following the Elbbogen. It is named after the Brühl Terrace, which stands on its south side. On the terrace bank is the mooring of the Saxon steamship. Parts of the terraced shore are protected as a cultural monument.
 

Terrasenufer-hotel-sideview-over-window-and-the-hotel-room

Terrasenufer is famous for being a non-smoker hotel and even though being an old construction inside is a confortable and the big advantage of it is the rooms are big ones for a hotel rooms (in my opinion). As you can see from the picture the sideview to Elba River and City Center Gothic styled buildings is unique, especially in night time.

Am_Terrassenufer-Dresden-Aussenansicht-night-view-to-Dresden

What is impressing in Germany that it is genererally really clean in the city and obviously it is invested in maintaining the greenery parks, trees. People also are really polite and helpful and most of people speak a decent English.

Dresden food prices the old and new city

The prices of the Alt Stadt city center are a little bit expensive especially for us Bulgarians a decent Dinner costs about 10 to 15 euro, but the new city (Neue Stadt)'s is full of relatively cheap fast food a lot of small breakfast rooms offering Shoarma (Duners) / Pizza / Noodes most of which run and served by Pakistans / Turkish or people from far east and a couple of Asian / Viatnamese run by Chineese / Viatnamese.
To grab one of that "fast foods" costs about 3.50 to 6 euro, a food I tried on a few times is 30 Cm Pizza which costs 4.5 euro and the best thing is the beer's price is 1.50 / 2 euro in some of the pizzerias like for example a small one called Pizza Bitte owned by a Pakistanian guys, where we eat many times and it was pretty good. The prices pretty much okay and not far different from Sofia.
We ate a couple of times at a small pizzeria ran by a Pakistani. The pizza price for that quality was fantastic.

donner_kebap-durum-buzek-pide-gozleme-Dresden

I've spend about 1 week now in Dresden and I can say the city is much calmer and "there is no feeling of stress in the air", people here perhaps of the good living standard seems more relaxed and stressed than in Bulgaria. 
As an ex Eastern Bloc country there are some remains of the Soviet times in Dresden before the fall of the Berlin Wall a building Communistic (Soviet) Mosaic near the square of the Old city is a good example of that.

Dresden Socialist Soviet Architecture remains

Dresden-Communism-socialism-mosaic-remains

Of course as a country which was almost a member of the Soviet Union, there is a lot of pannel construction near the end of the city, but even they are nowadays seriously renovated and doesn't look so scary like a lot of the old unmaintained buildings in Bulgaria, Ukraine (Smaller towns in Russia) and even partially Romania.

Dresden-old-communism-times-blocks


Churches in Dresden and few old city landmarks

A notable building in the city is the Frauenkirche (Protestant Cathedral Church) from year 1738 that was fully destroyed in World War 2.

frauenkirche-dresden-Protestant-Cathedral

and rebuild in 1993 – 1994.

Very near is found a majestic architectural master piece the Catholic Church

Kathedrale_Hofkirche-Dresden-Holy-Trinity

the Catholic Church Holy Trinity (Sanctissimae Trinitatis) of the royal court of Saxony / Katholische HofKirche

Near the Roman-Catholic Gothic Style Church is situated the Zwinger Palace, a unique peace of Barocue Art architecture.

Zwinger_palace-dresden2

Zwinger Palace Dresden

Zwinger-palace-dresden-garden
 

The Orthodox Russian Church

The Address of Orthodox Church in Dresden is Fritz-Löffler-Straße 19, 01069 Dresden an information about their and information about the Holy Liturgies, Vespers and Night services is on Dresden's Church official site here. to reach there from Synague Tram stop near Synagogue I've to pick up Tram Number 3.
As an Orthodox Christian both of them does not hold any spiritual interest, even though I personally think Roman-Catholicism is closer to the true faith which is closer to ours the Holy Eastern Orthodoxy.

The best Architectural master piece in the city in my opinion is the Russian Church / Russisch Orthodoxe Kirche – des Heiligen Simeon vom wunderbaren Berge (Saint Simeon Styler the Younger)

Icon-Ikona-swjatogo-saint-Semiona-Divnogorca-Stylpnik-mladshi-Dresden

and just as a proof of the true faith in my opinion it was not a coincidence that those church was the only building within a wide area which remained relatively intact (only the bell tower suffered damge), through the brutal bombing of city in February 1945 by British / American Allied forces. The Church has a historical value as it was build in 1872 – 1874 before Soviet Revolution in 1917 During Russian Empire Tsarist times and (currently is about 147 years old). 

Russian-Church-Dresden-saint-Simeon-Divnogorec

The world famous Russian Composer Rachmaninov himself as he lived a 3 winters in Dresden donated money for a new gas installation of the Church which is in operation to this very day.

saint-Simeon-Divnogorec-Orthodox-Christian-Church-in-Dresden

Russian-Eastern-Orthodox-Church-saint-Simeon-Stylpnik-the-Younger-Divnogorec

In 1875 the Russian Emperor Alexander II visited the Church a memory board donation by him is still present in. It is interesting fact that one of the Great Russian Novelist and perhaps, the greatest psychologist of all times Fyodor Dostoevski named Lubov was baptized in the Orthodox Christian Church

This Sunday I visited the Church for a Sunday Holy Liturgy  and was nicely surprised to find the Church choire was singing like Angels.
The priest is an aged one and seems a very gracious man. The Church was full of people, among which were many young people and parents who brought their kids to receive the Holy Sacraments.

Russian-Church-Dresden-picture-11

Russian-Church-Dresden-picture-12

The Church alter is painted back in the day of Church cration by a German painter the Alter wall of iconostasis is made of marble.

Russian-Church-Dresden-picture-7

As it is often seen in Russian Church, there is a crucifix on one of the sides of the Church in those it was left side and in front as usual were burning candles for remember of deceased.

Russian-Church-Dresden-picture-4

Among the impressing bits of the Dresden Orthodox Church are the Window glass frescos, that are so common for Western Europe Cathedrals, except that the frescos are purely Orthodox, it is the first time I saw such and I can see it is really beautiful.

Dresden-Window-on-Dresden-Orthodox-Church-icons-of-Savior-Jesus-Christ-and-the-Holy-Theotokos

Climate in Dresden

The Climate here is more moderate when compared to Bulgarian and even though at times it is a bit windy with a cold wind, the weather feels quite nice in Autumn seasen time and temperatures are more stable – the temporature is stable at least for my stay and it feels more like an Autumn should be and in that sense resembles Dutch climate. The weather is sunny enough so the Dresdener Germans are privileged to have less of that gloomy Netherlands cloudy weather.

The Military History Museum Dresden

Next after the Sunday Holy Liturgy service, I've visited the War Museum (The Bundeswehr Museum of Military History in Dresden) which on address Olbrichtplatz 2, 01099 Dresden.

Military-War-Museum-Dresden-Heavy-tanks-and-war-vehicles

To reach there the Tram number 7 goes from Synagogue Bus stop, the bus stops about 150 meters from the Musem.
The museum exhibits about 10000 military artefacts and things connected to pre and post WW2. 
In the museum coutryard as common for military objects are some old Tanks and heavy military vehicles, tanks, mine destroying machine, cutters, armored personnel carrier and even a Patriot rocket launcher platform and even a nuclear head transporter.
The tanks were mostly German tanks from 1955 'till late 1980s and few Russian machines T72 and other Soviet equipment.

Inside the museum are exhibited many traditional German flags, remains of Napeleon war times, a few Nazis equipment and more modern American one guns, uniforms etc.

German-War-Flag

Most impressing are the few enormous rockets that are directly in the building. The 5 stages show political stuff related to war, old military cars, nearly 10000 war related paintings, flamethowers and reconstruction dummy models of various submarines, tanks, helicopters, ships and pieces of military art and military time German life and propaganda posters from Nazi times ….
war-museum-1-anti-mining-heavy-vehicle

Mine searching and destroying heavy machine

war-museum-2-german-emperialistic-eagle

The German Eagle and Uniforms

war-museum-3-animals-and-war

Animals used in War – museum section

war-museum-4-rockets

Rockets

war-museum-4-russian-old-gazka

Soviet Union Gazka Emergy Medical Aid

war-museum-5-german-tank

German anti-aircraft missle tank with Radar on top

war-museum-6-rocket

Ballistic Rocket (Maybe?)

war-museum-7-miniature-ship

Model of Old Ship

war-museum-8-rocket-launcher

Rocket Launcher

war-museum-10-war-holder

Nuclear Head Transporter

war-museum-11-nato-military-guns

Machine gun rifles

There is perhaps much more to see on Dresden, the Zoo, the Porcelan Museum, the famous Dresden Painting Gall, the Royalty Zwinger Palace, The Semper Opera, The Socialist Museum, The Museum of Hygiene but I still have time for that once I see some more or get impressions I'll come back to update this article. 
 

Make laptop not to sleep on close on Microsoft Windows 10 / Disable notebook LID close sleep Windows

Thursday, November 8th, 2018

Windows10-Define-power-options-actions-settings

I have to use Windows 10 Enterprise on a notebook for Work purposes once again and use a Docking station connected to an external Display Monitor at the Company Office work location one of the first things to configure is to disable LID Display Sleep on laptop close because otherwise the notebook has to be left opened almost half opened in order to work with the PC to change that unwanted behavior there is an easy way via Windows Control Panel configuration, here is how:

Open

Windows Control Panel 

 


navigate to:

edit-plan-settings-power-settings-windows-10.png

 

 

 

Power Options


choose:

Change advanced power settings, scroll down a bit to:

power-options-power-buttons-and-lid-lid-close-action-do-nothing-windows-10-scresnshot

 

Power Buttons and lid (menu) 


press over it from sub-menu
 

Plugged in

 


Select

 

 

Do nothing

 


That's all from now on closing the notebook when plugged in to the Dock station or to a direct External Monitor will no longer do the sleep.

As you can see from the menus, there is a lot of triggering rules to configure further from Power Management (Advanced Settings) on how applications / USBs / Multimedia and Hard Disks should behave under different power conditions so if you have the time I recommend you go through them and check them for yourself.

Create and Configure SSL bundle file for GoGetSSL issued certificate in Apache Webserver on Linux

Saturday, November 3rd, 2018

gogetssl-install-certificate-on-linux-howto-sslcertificatechainfile-obsolete

I had a small task to configure a new WildCard SSL for domains on a Debian GNU / Linux Jessie running Apache 2.4.25.

The official documentation on how to install the SSL certificate on Linux given by GoGetSSL (which is by COMODO was obsolete as of time of writting this article and suggested as install instructions:
 

SSLEngine on
SSLCertificateKeyFile /etc/ssl/ssl.key/server.key
SSLCertificateFile /etc/ssl/ssl.crt/yourDomainName.crt
SSLCertificateChainFile /etc/ssl/ssl.crt/yourDomainName.ca-bundle


Adding such configuration to domain Vhost and testing with apache2ctl spits an error like:

 

root@webserver:~# apache2ctl configtest
AH02559: The SSLCertificateChainFile directive (/etc/apache2/sites-enabled/the-domain-name-ssl.conf:17) is deprecated, SSLCertificateFile should be used instead
Syntax OK

 


To make issued GoGetSSL work with Debian Linux, hence, here is the few things done:

The files issued by Gogetssl.COM were the following:

 

AddTrust_External_CA_Root.crt
COMODO_RSA_Certification_Authority.crt
the-domain-name.crt


The webserver had already SSL support via mod_ssl Apache module, e.g.:

 

root@webserver:~# ls -al /etc/apache2/mods-available/*ssl*
-rw-r–r– 1 root root 3112 окт 21  2017 /etc/apache2/mods-available/ssl.conf
-rw-r–r– 1 root root   97 сеп 19  2017 /etc/apache2/mods-available/ssl.load
root@webserver:~# ls -al /etc/apache2/mods-enabled/*ssl*
lrwxrwxrwx 1 root root 26 окт 19  2017 /etc/apache2/mods-enabled/ssl.conf -> ../mods-available/ssl.conf
lrwxrwxrwx 1 root root 26 окт 19  2017 /etc/apache2/mods-enabled/ssl.load -> ../mods-available/ssl.load


For those who doesn't have mod_ssl enabled, to enable it quickly run:

 

# a2enmod ssl


The VirtualHost used for the domains had Apache config as below:

 

 

 

NameVirtualHost *:443

<VirtualHost *:443>
    ServerAdmin support@the-domain-name.com
    ServerName the-domain-name.com
    ServerAlias *.the-domain-name.com the-domain-name.com

    DocumentRoot /home/the-domain-namecom/www
    SSLEngine On
#    <Directory />
#        Options FollowSymLinks
#        AllowOverride None
#    </Directory>
    <Directory /home/the-domain-namecom/www>
        Options Indexes FollowSymLinks MultiViews
        AllowOverride None
        Include /home/the-domain-namecom/www/htaccess_new.txt
        Order allow,deny
        allow from all
    </Directory>

    ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/
    <Directory "/usr/lib/cgi-bin">
        AllowOverride None
        Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
        Order allow,deny
        Allow from all
    </Directory>

    ErrorLog ${APACHE_LOG_DIR}/error.log

    # Possible values include: debug, info, notice, warn, error, crit,
    # alert, emerg.
    LogLevel warn

    CustomLog ${APACHE_LOG_DIR}/access.log combined

#    Alias /doc/ "/usr/share/doc/"
#   <Directory "/usr/share/doc/">
#       Options Indexes MultiViews FollowSymLinks
#       AllowOverride None
#       Order deny,allow
#       Deny from all
#       Allow from 127.0.0.0/255.0.0.0 ::1/128
#   </Directory>
SSLCertificateKeyFile /etc/apache2/ssl/the-domain-name.com.key
SSLCertificateFile /etc/apache2/ssl/chain.crt

 

</VirtualHost>

The config directives enabling and making the SSL actually work are:
 

SSLEngine On
SSLCertificateKeyFile /etc/apache2/ssl/the-domain-name.com.key
SSLCertificateFile /etc/apache2/ssl/chain.crt

 

The chain.crt file is actually a bundle file containing a bundle of the gogetssl CA_ROOT and RSA_Certification_Authority 3 files, to prepare that file, I've used bundle.sh small script found on serverfault.com here I've made a mirror of bundle.sh on www.pc-freak.net here   the script content is as follows:

To prepare the chain.crt  bundle, I ran:

 

sh create-ssl-bundle.sh _iq-test_cc.crt chain.crt
sh create-ssl-bundle.sh _iq-test_cc.crt >chain.crt
sh create-ssl-bundle.sh COMODO_RSA_Certification_Authority.crt >> chain.crt
sh create-ssl-bundle.sh bundle.sh AddTrust_External_CA_Root.crt >> chain.crt


Then I copied the file to /etc/apache2/ssl together with the-domain-name.com.key file earlier generated using openssl command earlier explained in my article how to install RapidSSL certificate on Linux

/etc/apache2/ssl was not previously existing (on Debian Linux), so to create it:

 

root@webserver:~# mkdir /etc/apache2/ssl
root@webserver:~# ls -al /etc/apache2/ssl/chain.crt
-rw-r–r– 1 root root 20641 Nov  2 12:27 /etc/apache2/ssl/chain.crt
root@webserver:~# ls -al /etc/apache2/ssl/the-domain-name.com.key
-rw-r–r– 1 root root 6352 Nov  2 20:35 /etc/apache2/ssl/the-domain-name.com.key

 

As I needed to add the SSL HTTPS configuration for multiple domains, further on I've wrote and used a tiny shell script add_new_vhost.sh which accepts as argument the domain name I want to add. The script works with a sample Skele (Template) file, which is included in the script itself and can be easily modified for the desired vhost config.
To add my multiple domains, I've used the script as follows:
 

sh add_new_vhost.sh add-new-site-domain.com
sh add_new_vhost.sh add-new-site-domain1.com


etc.

Here is the complete script as well:

 

#!/bin/sh
# Shell script to add easily new domains for virtual hosting on Debian machines
# arg1 should be a domain name
# This script takes the domain name which you type as arg1 uses it and creates
# Docroot / cgi-bin directory for the domain, create seperate site's apache log directory
# then takes a skele.com file and substitutes a skele.com with your domain name and directories
# This script's aim is to easily enable sysadmin to add new domains in Debian
sites_base_dir=/var/www/jail/home/www-data/sites/;
# the directory where the skele.com file is
skele_dir=/etc/apache2/sites-available;
# base directory where site log dir to be created
cr_sep_log_file_d=/var/log/apache2/sites;
# owner of the directories
username='www-data';
# read arg0 and arg1
arg0=$0;
arg1=$1;
if [[ -z $arg1 ]]; then
echo "Missing domain name";
exit 1;
fi

 

# skele template
echo "#
#  Example.com (/etc/apache2/sites-available/www.skele.com)
#
<VirtualHost *>
        ServerAdmin admin@design.bg
        ServerName  skele.com
        ServerAlias www.skele.com


        # Indexes + Directory Root.
        DirectoryIndex index.php index.htm index.html index.pl index.cgi index.phtml index.jsp index.py index.asp

        DocumentRoot /var/www/jail/home/www-data/sites/skelecom/www/docs
        ScriptAlias /cgi-bin "/var/www/jail/home/www-data/sites/skelecom/cgi-bin"
        
        # Logfiles
        ErrorLog  /var/log/apache2/sites/skelecom/error.log
        CustomLog /var/log/apache2/sites/skelecom/access.log combined
#       CustomLog /dev/null combined
      <Directory /var/www/jail/home/www-data/sites/skelecom/www/docs/>
                Options FollowSymLinks MultiViews -Includes
                AllowOverride None
                Order allow,deny
                allow from all
                # This directive allows us to have apache2's default start page
                # in /apache2-default/, but still have / go to the right place
#               RedirectMatch ^/$ /apache2-default/
        </Directory>

        <Directory /var/www/jail/home/www-data/sites/skelecom/www/docs/>
                Options FollowSymLinks ExecCGI -Includes
                AllowOverride None
                Order allow,deny
                allow from all
        </Directory>

</VirtualHost>
" > $skele_dir/skele.com;

domain_dir=$(echo $arg1 | sed -e 's/\.//g');
new_site_dir=$sites_base_dir/$domain_dir/www/docs;
echo "Creating $new_site_dir";
mkdir -p $new_site_dir;
mkdir -p $sites_base_dir/cgi-bin;
echo "Creating sites's Docroot and CGI directory";
chown -R $username:$username $new_site_dir;
chown -R $username:$username $sites_base_dir/cgi-bin;
echo "Creating site's Log files Directory";
mkdir -p $cr_sep_log_file_d/$domain_dir;
echo "Creating sites's VirtualHost file and adding it for startup";
sed -e "s#skele.com#$arg1#g" -e "s#skelecom#$domain_dir#g" $skele_dir/skele.com >> $skele_dir/$arg1;
ln -sf $skele_dir/$arg1 /etc/apache2/sites-enabled/;
echo "All Completed please restart apache /etc/init.d/apache restart to Load the new virtual domain";

# Date Fri Jan 11 16:27:38 EET 2008


Using the script saves a lot of time to manually, copy vhost file and then edit it to change ServerName directive, for vhosts whose configuration is identical and only the ServerName listener has to change, it is perfect to create all necessery domains, I've created a simple text file with each of the domains and run it in a loop:
 

while :; do sh add_new_vhost.sh $i; done < domain_list.txt