forked from aymhce/diaspora_ynh
-
Notifications
You must be signed in to change notification settings - Fork 5
/
upgrade
154 lines (123 loc) · 6.38 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
#!/bin/bash
#=================================================
# IMPORT GENERIC HELPERS
#=================================================
source _common.sh
source ynh_install_ruby__2
source /usr/share/yunohost/helpers
#=================================================
# STOP SYSTEMD SERVICE
#=================================================
ynh_script_progression --message="Stopping $app's systemd service..." --weight=1
ynh_systemd_action --service_name="$app.target" --action="stop" --log_path="/var/log/$app/$app.log"
#=================================================
# ENSURE DOWNWARD COMPATIBILITY
#=================================================
ynh_script_progression --message="Ensuring downward compatibility..." --weight=1
if [ -e "$install_dir/.rvm" ]; then
# migrate from rvm to rbenv
ynh_script_progression --message="Remove rvm if needed..." --weight=1
ynh_exec_as "$app" --login rvm implode --force
# remove old gpg keys for rvm
if gpg --list-keys mpapis@gmail.com >/dev/null 2>&1; then
ynh_exec_as "$app" gpg --delete-keys mpapis@gmail.com
ynh_secure_remove "$install_dir/mpapis@gmail.com.pgp"
fi
if gpg --list-keys piotr.kuczynski@gmail.com >/dev/null 2>&1; then
ynh_exec_as "$app" gpg --delete-keys piotr.kuczynski@gmail.com
ynh_secure_remove "$install_dir/piotr.kuczynski@gmail.com.pgp"
fi
fi
# Move from diaspora/ to live/
if ! [ -d "$install_dir/live" ]; then
# NOTE if nobody never uploads anything, this won't exist yet
# creating it anyway, it's simpler if we can assume it exists always
# but we CANNOT assume it exists from previous version
if [ -d "$install_dir/diaspora/public/uploads" ]; then
mv "$install_dir/diaspora/public/uploads" "$install_dir/uploads"
else
mkdir "$install_dir/uploads"
fi
ynh_delete_file_checksum --file="$install_dir/diaspora/config/diaspora.yml"
ynh_delete_file_checksum --file="$install_dir/diaspora/config/database.yml"
mv "$install_dir/diaspora" "$install_dir/live"
ynh_store_file_checksum --file="$install_dir/live/config/diaspora.yml"
ynh_store_file_checksum --file="$install_dir/live/config/database.yml"
fi
ynh_secure_remove "$install_dir/Experimental_helpers"
if [[ -z "${admin:-}" ]]; then
admin=""
ynh_app_setting_set --app="$app" --key=admin --value="$admin"
fi
admin_mail=$(ynh_user_get_info --username="$admin" --key=mail)
#=================================================
# INSTALL DEPENDENCIES
#=================================================
ynh_script_progression --message="Installing Ruby..." --weight=5
ynh_exec_warn_less ynh_install_ruby --ruby_version=$ruby_version
ynh_script_progression --message="Installing NodeJS..." --weight=5
ynh_exec_warn_less ynh_install_nodejs --nodejs_version=$nodejs_version
#=================================================
# DOWNLOAD, CHECK AND UNPACK SOURCE
#=================================================
ynh_script_progression --message="Upgrading source files..." --weight=1
# Download, check integrity, uncompress and patch the source from app.src
ynh_setup_source --dest_dir="$install_dir/live" --full_replace=1 --keep="config/diaspora.yml config/database.yml"
# create upload folder and link it
mkdir -p "$install_dir/uploads"
ln -s "$install_dir/uploads" "$install_dir/live/public"
chmod -R o-rwx "$install_dir"
chown -R "$app:www-data" "$install_dir"
#=================================================
# UPDATE A CONFIG FILE
#=================================================
ynh_script_progression --message="Updating a configuration file..." --weight=1
ynh_add_config --template="diaspora.yml" --destination="$install_dir/live/config/diaspora.yml"
chmod 400 "$install_dir/live/config/diaspora.yml"
chown "$app:$app" "$install_dir/live/config/diaspora.yml"
ynh_add_config --template="database.yml" --destination="$install_dir/live/config/database.yml"
chmod 400 "$install_dir/live/config/database.yml"
chown "$app:$app" "$install_dir/live/config/database.yml"
#=================================================
# BUILD APP
#=================================================
ynh_script_progression --message="Building app..." --weight=40
pushd "$install_dir/live"
ynh_use_ruby
ynh_use_nodejs
ynh_gem install "bundler:$bundler_version"
ynh_exec_warn_less ynh_exec_as "$app" "$ynh_ruby_load_path" "$ld_preload" script/configure_bundler
ynh_exec_warn_less ynh_exec_as "$app" "$ynh_ruby_load_path" "$ld_preload" bin/bundle install --full-index --with=postgresql
ynh_exec_warn_less ynh_exec_as "$app" RAILS_ENV=production "$ynh_ruby_load_path" "$ld_preload" bin/bundle exec rake db:migrate
ynh_exec_warn_less ynh_exec_as "$app" RAILS_ENV=production "$ynh_ruby_load_path" "$ld_preload" bin/rake assets:precompile
popd
#=================================================
# REAPPLY SYSTEM CONFIGURATIONS
#=================================================
ynh_script_progression --message="Upgrading system configurations related to $app..." --weight=1
# Create a dedicated NGINX config
ynh_add_nginx_config
# Create a dedicated systemd config
ynh_add_systemd_config --service="${app}_sidekiq" --template="diaspora_sidekiq.service"
ynh_add_systemd_config --service="${app}_web" --template="diaspora_web.service"
# Create target unit
_ynh_add_systemd_target
yunohost service add "$app.target" --description "Diaspora service (unicorn web and sidekiq)" \
--log "$install_dir/live/log/production.log" \
"$install_dir/live/log/unicorn-stderr.log" \
"$install_dir/live/log/unicorn-stdout.log" \
"$install_dir/live/log/sidekiq.log"
# Create tmpfile
ynh_add_config --template="diaspora.tmpfiles.d" --destination="/etc/tmpfiles.d/${app}.conf"
systemd-tmpfiles --create
#=================================================
# START SYSTEMD SERVICE
#=================================================
ynh_script_progression --message="Starting $app's systemd service..." --weight=1
systemctl restart "${app}.target"
ynh_systemd_action --service_name="${app}_web.service" --action=restart --log_path="$install_dir/live/log/production.log" --line_match="successfully configured the federation library"
ynh_systemd_action --service_name="${app}_sidekiq.service" --action=restart --log_path="systemd" --line_match="Running in ruby"
#=================================================
# END OF SCRIPT
#=================================================
ynh_script_progression --message="Upgrade of $app completed" --last