Little Docker Swarm walkthru

I’ll try to setup a two node docker swarm. quiet easy and done in 10 minutes. i used 2 ubuntu 16.4 64 bit vm’s.

HostnameExternal IPInternal IP
scw-5fd012212.47.239.15310.2.37.217
scw-095a80212.47.240.21810.2.222.81

i also assume u installed docker.

you need to decide which one will be the manager.

i choose scw-5fd012. on that node i enter a

root@scw-5fd012:~# docker swarm init --advertise-addr 10.2.37.217
Swarm initialized: current node (5lpm87bmugszxrx920k2zmx6k) is now a manager.

To add a worker to this swarm, run the following command:

docker swarm join \
--token SWMTKN-1-4mqfnpv0kthd2of2rc7ji9qj5mhlry2o1ktmpofn80hzmopd1d-913n0w2l4x3if7dog5emgw781 \
10.2.37.217:2377

To add a manager to this swarm, run 'docker swarm join-token manager' and follow the instructions.

Thats it!
the docker swarm is created and scw-5fd012 is the manager.

on scw-095a80 i just enter a

docker swarm join --token SWMTKN-1-4mqfnpv0kthd2of2rc7ji9qj5mhlry2o1ktmpofn80hzmopd1d-913n0w2l4x3if7dog5emgw781 10.2.37.217:2377

and i have my docker swarm set up

on the master i can check if everyhting is working with a simple

root@scw-5fd012:~# docker node ls                                                                                            
ID                           HOSTNAME    STATUS  AVAILABILITY  MANAGER STATUS                                                
5lpm87bmugszxrx920k2zmx6k *  scw-5fd012  Ready   Active        Leader                                                        
f0ogny4uxy5zg956hf8m16eka    scw-095a80  Ready   Active                                                                      
root@scw-5fd012:~#                                                                                                           
Posted in commandline, linux | Tagged , , | Leave a comment

delete all msg in the postfix queue

just type a simple “postsuper -d ALL” and they are gone 😉

Posted in commandline, linux, postfix, snipped | Leave a comment

Bash infinite loop

#!/bin/bash
while :
do
	echo "Press [CTRL+C] to stop.."
	sleep 1
done

This is a loop that will forever print “Press [CTRL+C] to stop..”. Please note that : is the null command. The null command does nothing and its exit status is always set to true. You can modify the above as follows to improve the readability:

#!/bin/bash
while true
do
	echo "Press [CTRL+C] to stop.."
	sleep 1
done

A single-line bash infinite while loop syntax is as follows:

 while :; do echo 'Hit CTRL+C'; sleep 1; done

OR

 while true; do echo 'Hit CTRL+C'; sleep 1; done

Bash for infinite loop example

#!/bin/bash
 
for (( ; ; ))
do
   echo "Pres CTRL+C to stop..."
   sleep 1
done

How Do I Escape the Loop?

A for or while loop may be escaped with a break statement when certain condition is satisfied:

 ### for loop example ###
for (( ; ; ))
do
   echo "Pres CTRL+C to stop..."
   sleep 1
   if (disaster-condition)
   then
	break       	   #Abandon the loop.
   fi
done

OR

 ### while loop example ###
while :
do
   echo "Pres CTRL+C to stop..."
   sleep 1
   if (disaster-condition)
   then
	break       	   #Abandon the loop.
   fi
done
Posted in commandline, linux, snipped | Tagged | 1 Comment

How to execute a command whenever a file changes?

while inotifywait -e close_write myfile.py; do ./myfile.py; done

or

inotifywait -q -m -e close_write myfile.py |
while read -r filename event; do
  ./myfile.py         # or "./$filename"
done

The first snippet is simpler, but it has a significant downside: it will miss changes performed while inotifywait isn’t running (in particular while myfile is running). The second snippet doesn’t have this defect.

Posted in commandline, linux, snipped | Leave a comment

sed replace word / string syntax

The syntax is as follows:
sed -i 's/old-word/new-word/g' *.txt

GNU sed command can edit files in place (makes backup if extension supplied) using the -i option. If you are using an old UNIX sed command version try the following syntax:

sed 's/old/new/g' input.txt > output.txt

Posted in commandline, linux, snipped | Leave a comment

How can I find the oldest file in a directory tree

find -type f -printf '%T+ %p\n' | sort | head -n 1
Posted in commandline, linux, snipped | Leave a comment

Backups with tar

tar -cvpzf backup.tar.gz --exclude=/backup.tar.gz --one-file-system /

 

Posted in commandline, linux, snipped | Leave a comment

Hello Again !

This is now my 3rd attempt to run this personal Blog

Posted in Uncategorized | Leave a comment