forked from justinmajetich/AirBnB_clone
-
Notifications
You must be signed in to change notification settings - Fork 1
/
part_2.txt
84 lines (69 loc) · 3.43 KB
/
part_2.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
In this file i will try to explain how to proceed
Task0:
1. I should first install ngnix
sudo apt -y update
sudo apt install -y nginx
2. I have to create this folders if don't exist :
-/data/web_static/releases/
-/data/web_static/shared/
-/data/web_static/releases/test/
so to do that i should use mkdir with the -p option
3. I have also to create /data/web_static/releases/test/index.html html file with a simple content for testing my nginx config
4. I should create a symbolic link between
/data/web_static/current -> /data/web_static/releases/test/
5. Change the data ownship folder to user and group
chown -R ubuntu and chgrp -R AND
6. update the Nginx config to serve the content of /data/web_static/current/ to hbnb_static
Inside the file /etc/nginx/sites-avaible/default i should add inside the server block
server {
#Previous content
location /hbnb_static {
alias /data/web_static/current/;
}
}
NB: Before that make sure that /etc/nginx/sites-enabled/default is linked whith /etc/nginx/site-available/default
==> if [ ! -L /etc/nginx/sites-enabled/default ];==> return true if no symbolik link exist.
Task1: Create an archive tgz using fabric
First let's import local because the command should executed in
local.
from fabric.api import local
The archive will be done using tar -czvf web_static_<year><month><day><hour><minute><second>.tgz /data/web_static
==> web_static_<year><month><day><hour><minute><second>.tgz: will be formed using datetime python module since fabric is a python libary and python file. So let's import datetime from datetim
and use it to construct the full name of our archive.
date = datetime.now().strftime("%Y%m%d%H%M%S")
archive_name = f'web_static_{date}.tgz
==> tar -czvf archive_name /data/web_static
Finally the archive should be saved in versions directory.
if not os.path.exists(versions):
local("mkdir versions)
so our fuction do_pack() will be
try:
if not os.path.exists(versions):
local("mkdir versions)
date = datetime.now().strftime("%Y%m%d%H%M%S")
archive_name = f'web_static_{date}.tgz
local ("tar -czvf versions/archive_name web_static"
NB: If your code doesn't work replace this line if not os.path.exists(versions): by ==> if not os.path.isdir("versions") is False:
Task2: distributes an archive to your web servers, using the function do_deploy
1.check iif the archive_path exist:
if not os.path.isfile(archive_name) is False==>return False
2.
a. upload the archive to the /tmp/ directory of web servers
env.hosts = ['IP web01', 'IP web02']
a = put ("archive_path", /tmp/)
if a.failed is True
return FAlse
b. Uncompress the archive to the folder /data/web_static/releases/<archive filename without extension> on the web server
new_path = archive_path.split('/')[-1]
folder = new_path.split(".")[0]
run (tar -xzf /tmp/archive_path -C /data/web_static/releases/)
c. Delete the archive from web server
run ("rm /tmp/archive_path")
d. Delete symbolic link
run ("rm -rf /data/web_static/current
e. Create a new the symbolic link /data/web_static/current on the web server, linked to the new version of your code (/data/ web_static/releases/<archive filename without extension>)
Before creating the symbolic link let's move the uncompressed content to the parent directory
mv /data/web_static/releases/folder/web_static/* /data/web_static/releases/folder
then delete the web_static
rm -rf /data/web_static/releases/folder/web_static
ln -sf /data/web_static/releases/folder/ /data/web_static/current