When a server is rebooting, we have to make sure that the disks are mountet correctly on the server. We have made a script called boot.sh that will take care of the mounting on reboot. The script is run automaticly on every reboot, because of crontab. Below is the crontab file we have on our three servers:
```
# Crontab file for worker nodes, is automaticly updated
The script boot.sh will try to mount the disks of they are not already mountet(probably not). Then the script will sleep for 5 seconds, to give the commands time to finish. Then an if-sentence will check whether the volumes are mounted or not, and send a message to our Bookface Discord-webhook. After the disks are mountet(or not), cockroach will start. In the case of a failed mount, this script will simply exit without attempting again. This was done to avoid infinite looping, and in the case that the mount has failed, we suspect that direct involvement is neccecary anyways. As such it's easier to simply have the script ping our discord in the case of an error.
# Week 11 - Docker Swarm
## Task 1
Install Docker on all the servers with these commands:
To make sure that we are able to download Docker images from other places, we have to add the code below to the file ```/etc/docker/daemon.json``` on every server:
```
{
"insecure-registries":["192.168.128.23:5000"]
}
```
Then restart Docker: ```systemctl restart docker```
## Task 2
Docker starts as a service automaticly every time the server is rebooting. We dont want this, because we dont want a server to run any containers before Gluster is connected properly. We therefore have to turn of the automatic restart of Gluster when the server is rebooting. We do this by running these commands:
```
systemctl disable docker
systemctl disable docker.service
systemctl disable docker.socket
```
We add this line of code in the boot.sh script mentioned above:
```
systemctl start docker
```
This line will start Docker every time the script is run, but after the volumes are mounted and everything is ok.
## Task 3 - Make the Docker swarm
Now we are ready to create the swarm. We run this code on server 1: ```docker swarm init```. Server 1 is now going to be the manager in the swarm, server 2 and server 3 is going to be the workers. When we run the docker swarm init command, we get the following output(on server 1):
Now we will import the data from our current bookface setup, to the new setup. First we have to fix a small issue from week 9. The table "posts" did not include a column for pictures, this we have to fix. Go to the database in the new cluster(on server 1):
```
cockroach sql --insecure --host=localhost:26257
```
We delete the old table called posts, and make a new table with an extra column for pictures:
```
use bf;
drop table posts;
CREATE table posts ( postID INT PRIMARY KEY DEFAULT unique_rowid(), userID INT, text STRING(300), name STRING(150), image STRING(32), postDate TIMESTAMP DEFAULT NOW());
GRANT SELECT,UPDATE,INSERT on TABLE bf.* to bfuser;
```
Now we have to make it not possible to get a bookface to import from another solution without a "password". We write this in the cockroach shell:
```
insert into config ( key, value ) values ( 'migration_key', 'mjau' );
```
In the command above, "mjau" is our secret password. A bookface will not be able to import data from antother solution without this key.
Then log out from the cockroach shell.
### Database Migration
It is time to upgrade the current bookface version to version 17. Run this code on server1:
In the code above, BF_DB_HOST means old database ip adderess, BF_DB_USER means username on old database, BF_MEMCACHE_SERVER means memcache server ip address, and BF_DB_NAME means old database name.
Now verify that the docker container started with ```docker ps```, and run this command to verify that the old bookface still is up:
```
curl localhost:20080
```
After this, we are now ready to import the old bookface database to the new gluster cluster. Do this on server 1:
In the command above, entrypoint means the ip address to where the help-container is running, in this case on server 1. Key is the secret password we made earlier, mjau.
Now, the bookface data is gonna be replicated to all three server thanks to GlusterFS. This command is gonna take a while, probably half an hour or so.
## Task 8 - Openstack balancer
Now we have to stop using the old balancer server, and use the balanser functionality on Openstack instead. This is for efficiency and simplicity. If we still use the old balancer server, bookface is gonna shut down if the balancer shuts down. We avoid this by using the openstack balancer.
Kopier først "RC"-filen fra manager til server1 med scp. Inne i server1 må dere "source" filen og sjekke at alt er i orden med kommandoen:
Do this on manager: Copy the RC file from manager to server 1: