/
upgrade
221 lines (168 loc) · 7.57 KB
/
upgrade
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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
#!/bin/bash
#=================================================
# GENERIC START
#=================================================
# IMPORT GENERIC HELPERS
#=================================================
source _common.sh
source /usr/share/yunohost/helpers
#=================================================
# LOAD SETTINGS
#=================================================
app=$YNH_APP_INSTANCE_NAME
domain=$(ynh_app_setting_get $app domain)
path_url=$(ynh_app_setting_get $app path)
admin=$(ynh_app_setting_get $app admin)
is_public=$(ynh_app_setting_get $app is_public)
final_path=$(ynh_app_setting_get $app final_path)
db_name=$(ynh_app_setting_get $app db_name)
db_pwd=$(ynh_app_setting_get $app db_pwd)
port=$(ynh_app_setting_get $app port)
#=================================================
# ENSURE DOWNWARD COMPATIBILITY
#=================================================
# Fix is_public as a boolean value
if [ "$is_public" = "Yes" ]; then
ynh_app_setting_set $app is_public 1
is_public=1
elif [ "$is_public" = "No" ]; then
ynh_app_setting_set $app is_public 0
is_public=0
fi
# If db_name doesn't exist, create it
if [ -z $db_name ]; then
db_name=$(ynh_sanitize_dbid $app)
ynh_app_setting_set $app db_name $db_name
fi
# If final_path doesn't exist, create it
if [ -z $final_path ]; then
final_path=/var/www/$app
ynh_app_setting_set $app final_path $final_path
fi
#=================================================
# BACKUP BEFORE UPGRADE THEN ACTIVE TRAP
#=================================================
# Backup the current version of the app
ynh_backup_before_upgrade
ynh_clean_setup () {
# restore it if the upgrade fails
ynh_restore_upgradebackup
}
# Exit if an error occurs during the execution of the script
ynh_abort_if_errors
#=================================================
# CHECK THE PATH
#=================================================
# Normalize the URL path syntax
path_url=$(ynh_normalize_url_path $path_url)
#=================================================
# STANDARD UPGRADE STEPS
#=================================================
# DOWNLOAD, CHECK AND UNPACK SOURCE
#=================================================
# Download, check integrity, uncompress and patch the source from app.src
ynh_setup_source "$final_path"
#=================================================
# NGINX CONFIGURATION
#=================================================
# Create a dedicated nginx config
ynh_add_nginx_config
#=================================================
# UPGRADE DEPENDENCIES
#=================================================
ynh_install_app_dependencies libjpeg-dev zlib1g-dev libfreetype6-dev default-libmysqlclient-dev python-dev
ynh_install_app_dependencies python-setuptools python-virtualenv
#=================================================
# CREATE DEDICATED USER
#=================================================
# Create a dedicated user (if not existing)
ynh_system_user_create $app $final_path
#=================================================
# PHP-FPM CONFIGURATION
#=================================================
# Create a dedicated php-fpm config
#ynh_add_fpm_config
#=================================================
# SPECIFIC UPGRADE
#=================================================
# ...
#=================================================
# Delete the old environnement
sudo rm -rf "$final_path/venv"
# Creates the directory for Python Virtual Environment.
sudo mkdir -p "$final_path/venv"
# Set permissions mediadrop directory
sudo chown -R $app: $final_path
# Create a new virtual environment:
sudo -u $app virtualenv --distribute --no-site-packages $final_path/venv
# Prepare mediacore to be upgarded
sudo sed -i "s@allow_hosts = static.mediadrop.net@#allow_hosts = static.mediadrop.net@g" "${final_path}/setup.cfg"
# Move to final_path
pushd ${final_path}
# Now, activate that virtual environment
sudo bash -c "source ${final_path}/venv/bin/activate && pip install uwsgi && python setup.py develop"
# To create Basic Configuration File deployment.ini in your current dir
sudo bash -c "source ${final_path}/venv/bin/activate && paster make-config mediacore ${final_path}/deployment.ini"
# Adapt config Mediadrop
sudo sed -i 's,host = 0.0.0.0,host = 127.0.0.1,' $final_path/deployment.ini
sudo sed -i 's,port = 8080,port = '${port}',' $final_path/deployment.ini
sudo sed -i 's,email_to = you@yourdomain.com,email_to = '${admin}'@'${domain}',' $final_path/deployment.ini
sudo sed -i 's,error_email_from = paste@localhost,error_email_from = '${admin}'@'${domain}',' $final_path/deployment.ini
sudo sed -i 's,mysql://username:pass@localhost/dbname?charset=utf8\&use_unicode=0,mysql://'${db_name}':'${db_pwd}'@localhost/'${db_name}'?charset=utf8\&use_unicode=0,' $final_path/deployment.ini
sudo sed -i 's,file_serve_method = default,file_serve_method = nginx_redirect,' $final_path/deployment.ini
sudo sed -i 's,# nginx_serve_path = __mediadrop_serve__,nginx_serve_path = __mediadrop_serve__,' $final_path/deployment.ini
sudo sed -i 's,static_files = true,static_files = false,' $final_path/deployment.ini
sudo sed -i 's,enable_gzip = true,enable_gzip = false,' $final_path/deployment.ini
sudo sed -i 's,static_files = false,static_files = true,' $final_path/deployment.ini
sudo sed -i "s,cache_dir = %(here)s/data,cache_dir = $final_path/data/," $final_path/deployment.ini
sudo sed -i "s,image_dir = %(here)s/data/images,image_dir = $final_path/data/images/," $final_path/deployment.ini
sudo sed -i "s,media_dir = %(here)s/data/media,media_dir = $final_path/data/media/," $final_path/deployment.ini
sudo sed -i 's,sqlalchemy.pool_recycle = 3600,sqlalchemy.pool_recycle = 200,' $final_path/deployment.ini
# Load Initial Data
sudo bash -c "source ${final_path}/venv/bin/activate && paster setup-app ${final_path}/deployment.ini"
# Move to script folder
popd
# Add uwsgi into deployment.ini (end of file)
sudo su -c "cat ../conf/uwsgi >> ${final_path}/deployment.ini"
sudo rm -fr /root/.python-eggs
sudo rm -fr /root/.cache/Python-Eggs
### Verify the checksum of a file, stored by `ynh_store_file_checksum` in the install script.
### And create a backup of this file if the checksum is different. So the file will be backed up if the admin had modified it.
ynh_backup_if_checksum_is_different "$final_path/deployment.ini"
# Recalculate and store the checksum of the file for the next upgrade.
ynh_store_file_checksum "$final_path/deployment.ini"
#=================================================
# SETUP LOGROTATE
#=================================================
# Use logrotate to manage app-specific logfile(s)
ynh_use_logrotate --non-append
#=================================================
# SETUP SYSTEMD
#=================================================
# Create a dedicated systemd config
ynh_add_systemd_config "$app" "mediadrop.service"
ynh_add_systemd_config "$app-uwsgi" "mediadrop-uwsgi.service"
systemctl stop "$app" "$app-uwsgi"
systemctl start "$app" "$app-uwsgi"
# Waiting start all services
sleep 30
#=================================================
# GENERIC FINALIZATION
#=================================================
# SECURE FILES AND DIRECTORIES
#=================================================
# Set permissions on app files
chown -R root: $final_path
#=================================================
# SETUP SSOWAT
#=================================================
# Make app public if necessary
if [ $is_public -eq 1 ]
then
# unprotected_uris allows SSO credentials to be passed anyway
ynh_app_setting_set $app unprotected_uris "/"
fi
#=================================================
# RELOAD NGINX
#=================================================
systemctl reload nginx