/
install
139 lines (105 loc) · 4.86 KB
/
install
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
#!/bin/bash
#=================================================
# GENERIC START
#=================================================
# IMPORT GENERIC HELPERS
#=================================================
source _common.sh
source /usr/share/yunohost/helpers
#=================================================
# RETRIEVE ARGUMENTS FROM THE MANIFEST
#=================================================
secret=$(ynh_string_random)
#=================================================
# STORE SETTINGS FROM MANIFEST
#=================================================
ynh_app_setting_set --app=$app --key=always_encrypt --value=$always_encrypt
ynh_app_setting_set --app=$app --key=secret --value="$secret"
ynh_app_setting_set --app=$app --key=overwrite_settings --value=1
ynh_app_setting_set --app=$app --key=overwrite_nginx --value=1
ynh_app_setting_set --app=$app --key=overwrite_systemd --value=1
ynh_app_setting_set --app=$app --key=admin_mail_html --value=1
#=================================================
# DOWNLOAD, CHECK AND UNPACK SOURCE
#=================================================
ynh_script_progression --message="Setting up source files..."
# Download, check integrity, uncompress and patch the source from app.src
ynh_setup_source --dest_dir="$install_dir"
chmod -R o-rwx "$install_dir"
chown -R $app:$app "$install_dir"
#=================================================
# NGINX CONFIGURATION
#=================================================
ynh_script_progression --message="Configuring NGINX web server..." --weight=2
# Create a dedicated NGINX config
ynh_add_nginx_config
#=================================================
# SPECIFIC SETUP
#=================================================
# ADD A CONFIGURATION
#=================================================
ynh_script_progression --message="Adding a configuration file..." --weight=2
workers="$(( $(nproc) * 2 ))"
ynh_add_config --template="../conf/lutim.conf.template" --destination="$install_dir/lutim.conf"
chmod 400 "$install_dir/lutim.conf"
chown $app:$app "$install_dir/lutim.conf"
#=================================================
# SETUP CRON
#=================================================
ynh_add_config --template="../conf/cron_lutim" --destination="/etc/cron.d/$app"
chmod +x $install_dir/script/lutim
#=================================================
# INSTALL LUTIM WITH CARTON
#=================================================
ynh_script_progression --message="Installing $app with Carton..." --weight=60
mkdir -p /var/log/$app/
(cd $install_dir
carton install 2>&1 | tee -a "/var/log/$app/setup_carton.log")
# Use a perl path adapted to the system architecture
arch_dir=$(ls -1 $install_dir/local/lib/perl5/ | grep linux-gnu)
if [ "$?" -ne 0 ]
then
ynh_die --message="Unable to find the perl directory for your architecture."
fi
ynh_replace_string --match_string="__ARCHDIR__" --replace_string="$arch_dir" --target_file="$install_dir/script/lutim"
#=================================================
# SETUP LOG FILE
#=================================================
# Making log a symbolic link to /var/log
touch /var/log/$app/production.log
chown $app -R /var/log/$app
ln -s /var/log/$app/production.log "$install_dir/log/production.log"
#=================================================
# SETUP SYSTEMD
#=================================================
ynh_script_progression --message="Configuring a systemd service..." --weight=2
# Create a dedicated systemd config
ynh_add_systemd_config
#=================================================
# GENERIC FINALIZATION
#=================================================
# SETUP LOGROTATE
#=================================================
ynh_script_progression --message="Configuring log rotation..." --weight=2
# Use logrotate to manage application logfile(s)
ynh_use_logrotate
#=================================================
# INTEGRATE SERVICE IN YUNOHOST
#=================================================
ynh_script_progression --message="Integrating service in YunoHost..."
yunohost service add $app --log="$install_dir/log/production.log"
#=================================================
# START SYSTEMD SERVICE
#=================================================
ynh_script_progression --message="Starting a systemd service..." --weight=6
# Wait for lutim to be fully started
ynh_systemd_action --action=restart --line_match="Manager.*started" --log_path="/var/log/$app/production.log" --timeout="120"
ynh_systemd_action --action=stop
# Set right permissions on new files created at first start
chown -R $app:$app $install_dir
# Wait for lutim to be fully started
ynh_systemd_action --action=restart --line_match="Manager.*started" --log_path="/var/log/$app/production.log" --timeout="120"
#=================================================
# END OF SCRIPT
#=================================================
ynh_script_progression --message="Installation of $app completed" --last