Saturday, September 02, 2017

EMACS Basic



To run script C-c C-x
C-f Move forward a character
C-b Move backward a character

M-f Move forward a word
M-b Move backward a word

C-n Move to next line
C-p Move to previous line

C-a Move to beginning of line
C-e Move to end of line

M-a Move back to beginning of sentence
M-e Move forward to end of sentence

M-< Go to beginning of file
M-> Go to end of file




QUIT -> C-x C-c
SEARCH -> M-x regex. C-s (C-r for reverse)( Type C-s and then word. Now type C-s agin to step through it)
UNDO -> C-x u
NEW / OPEN FILE -> C-x C-f test.emacs RET
SAVE FILE -> C-x C-s  C-x C-w C-x s


SHOW Line and column number -> M-x line-number-mode   M-x column-number-mode

YANKING
Paste: C-y
Paste the paste M-y


MULTI WINDOWS
C-x 1, C-x 2


DEBUG Emac
emacs —debug-init
M-x goto-char 
 M-x list-packages to list all package in emacs

To get documentation on your current major mode, type C-h m.



Mark a Region

C-Space C-Space
Now use arrow key to block the region and then use command to act on block.
Eg Use C-x TAB to indent

Mail in Emacs

C-x m
Begin composing mail (compose-mail).
C-x 4 m
Likewise, in another window (compose-mail-other-window).
C-x 5 m
Likewise, but in a new frame (compose-mail-other-frame).
C-c C-s
In the mail buffer, send the message (message-send).
C-c C-c
In the mail buffer, send the message and bury the buffer (message-send-and-exit).


Docker Swarm


Docker Swarm creation

docker-machine create --driver virtualbox manager1 ( Driver can be hyperv)
docker-machine create --driver virtualbox manager1
docker-machine create --driver virtualbox worker1
docker-machine create --driver virtualbox worker2
docker-machine create --driver virtualbox worker3
docker-machine create --driver virtualbox worker4
docker-machine create --driver virtualbox worker5

docker-machine ls docker-machine ls 
docker-machine ip manager1
docker-machine ssh manager1

From inside manager1 do init of swarm
docker swarm init --advertise-addr MANAGER_IP
docker node ls

Now get the token for worker joining in manager.
docker swarm join-token worker
docker swarm join-token manager

To join worker1 to manager ssh into worker1 in a new terminal 
docker-machine ssh worker1
docker swarm join --token SWMTKN-1-69hfhzjl83310rnx2b4t07qxmmi1xmgjkg5def1spotpiwki-dg29ra0thuptzmux2jq7brn1g 192.168.99.100:2377   (This is token from docker swarm join-token worker)
Continue with all workers

Now in manager do 
docker info
docker node ls


Create a Service
Now that we have our swarm up and running, it is time to schedule our containers on it. This is the whole beauty of the orchestration layer. We are going to focus on the app and not worry about where the application is going to run.
All we are going to do is tell the manager to run the containers for us and it will take care of scheduling out the containers, sending the commands to the nodes and distributing it.

To start a service, you would need to have the following:
  • What is the Docker image that you want to run. In our case, we will run the standard nginx image that is officially available from the Docker hub.
  • We will expose our service on port 80.
  • We can specify the number of containers (or instances) to launch. This is specified via the replicas parameter.
  • We will decide on the name for our service. And keep that handy.
What I am going to do then is to launch 5 replicas of the nginx container. To do that, I am again in the SSH session for my manager1 node. And I give the following docker service create command:


docker service create --replicas 5 -p 80:80 --name web nginx
docker service ls
docker service ps web
docker ps
docker service inspect --pretty web

To scale up the service use below command
docker service scale web=8

Checking:
docker service inspect --pretty web
docker node inspect manager1 --format "{{ .ManagerStatus.Reachability }}"
docker node inspect worker1 --format "{{ .Status.State }}"


Drain:
docker node update --availability drain worker5
docker node update —availability active worker5




To leave (stop) a node go to manager node and issue below command
docker node demote worker5
docker node rm --force worker5  (This has to be done after sometime from previous command)

Before you forcefully remove a manager node, you must first demote it to the worker role. Make sure that you always have an odd number of manager nodes if you demote or remove a manager.





Docker Container commands:
docker container ls
docker container stop
docker container rm
docker container rm image