mirror of
https://github.com/YunoHost-Apps/agendav_ynh.git
synced 2024-09-03 20:36:12 +02:00
use ynh_add_nginx_config and ynh_add_fpm_config
This commit is contained in:
parent
0a8e8a77d3
commit
cd8ffbee1c
4 changed files with 42 additions and 74 deletions
|
@ -1,5 +1,5 @@
|
||||||
location {PATH}/ {
|
location __PATH__/ {
|
||||||
alias {DESTDIR}/web/public/;
|
alias __FINALPATH__/web/public/;
|
||||||
index index.php;
|
index index.php;
|
||||||
|
|
||||||
if ($scheme = http) {
|
if ($scheme = http) {
|
||||||
|
@ -8,21 +8,21 @@ location {PATH}/ {
|
||||||
|
|
||||||
# The seemingly weird syntax is due to a long-standing bug in nginx,
|
# The seemingly weird syntax is due to a long-standing bug in nginx,
|
||||||
# see: https://trac.nginx.org/nginx/ticket/97
|
# see: https://trac.nginx.org/nginx/ticket/97
|
||||||
try_files $uri {PATH}/{PATH}/index.php$is_args$args;
|
try_files $uri __PATH__/__PATH__/index.php$is_args$args;
|
||||||
|
|
||||||
# Another alternative to the weird try_files is to use a rewrite, like this :
|
# Another alternative to the weird try_files is to use a rewrite, like this :
|
||||||
#
|
#
|
||||||
# if (-f $request_filename) {
|
# if (-f $request_filename) {
|
||||||
# break;
|
# break;
|
||||||
# }
|
# }
|
||||||
# rewrite (.*) {LOCATION}/index.php$request_uri;
|
# rewrite (.*) __PATH__/index.php$request_uri;
|
||||||
#
|
#
|
||||||
# But remember that if-is-evil :
|
# But remember that if-is-evil :
|
||||||
# https://www.nginx.com/resources/wiki/start/topics/tutorials/config_pitfalls/#check-if-file-exists
|
# https://www.nginx.com/resources/wiki/start/topics/tutorials/config_pitfalls/#check-if-file-exists
|
||||||
|
|
||||||
location ~ ^{PATH}/index\.php(/|$) {
|
location ~ ^__PATH__/index\.php(/|$) {
|
||||||
fastcgi_split_path_info ^(.+?\.php)(/.*)$;
|
fastcgi_split_path_info ^(.+?\.php)(/.*)$;
|
||||||
fastcgi_pass unix:/var/run/php5-fpm-{POOLNAME}.sock;
|
fastcgi_pass unix:/var/run/php5-fpm-__NAME__.sock;
|
||||||
fastcgi_index index.php;
|
fastcgi_index index.php;
|
||||||
include fastcgi_params;
|
include fastcgi_params;
|
||||||
fastcgi_param REMOTE_USER $remote_user;
|
fastcgi_param REMOTE_USER $remote_user;
|
||||||
|
@ -37,6 +37,3 @@ location {PATH}/ {
|
||||||
# Include SSOWAT user panel.
|
# Include SSOWAT user panel.
|
||||||
include conf.d/yunohost_panel.conf.inc;
|
include conf.d/yunohost_panel.conf.inc;
|
||||||
}
|
}
|
||||||
|
|
||||||
# append trailing slash in case of a subpath
|
|
||||||
location = {LOCATION} { return 302 {PATH}/; }
|
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
[{POOLNAME}]
|
[__NAMETOCHANGE__]
|
||||||
; The address on which to accept FastCGI requests.
|
; The address on which to accept FastCGI requests.
|
||||||
listen = /var/run/php5-fpm-{POOLNAME}.sock
|
listen = /var/run/php5-fpm-__NAMETOCHANGE__.sock
|
||||||
|
|
||||||
; Set permissions for unix socket, if one is used.
|
; Set permissions for unix socket, if one is used.
|
||||||
listen.owner = www-data
|
listen.owner = www-data
|
||||||
|
@ -8,8 +8,8 @@ listen.group = www-data
|
||||||
listen.mode = 0600
|
listen.mode = 0600
|
||||||
|
|
||||||
; Unix user/group of processes.
|
; Unix user/group of processes.
|
||||||
user = {USER}
|
user = __NAMETOCHANGE__
|
||||||
group = {GROUP}
|
group = __NAMETOCHANGE__
|
||||||
|
|
||||||
; Choose how the process manager will control the number of child processes.
|
; Choose how the process manager will control the number of child processes.
|
||||||
pm = dynamic
|
pm = dynamic
|
||||||
|
@ -47,7 +47,7 @@ request_terminate_timeout = 1d
|
||||||
request_slowlog_timeout = 5s
|
request_slowlog_timeout = 5s
|
||||||
|
|
||||||
; The log file for slow requests.
|
; The log file for slow requests.
|
||||||
slowlog = /var/log/nginx/{POOLNAME}.slow.log
|
slowlog = /var/log/nginx/__NAMETOCHANGE__.slow.log
|
||||||
|
|
||||||
; Set open file descriptor rlimit.
|
; Set open file descriptor rlimit.
|
||||||
rlimit_files = 4096
|
rlimit_files = 4096
|
||||||
|
@ -56,7 +56,7 @@ rlimit_files = 4096
|
||||||
rlimit_core = 0
|
rlimit_core = 0
|
||||||
|
|
||||||
; Chdir to this directory at the start.
|
; Chdir to this directory at the start.
|
||||||
chdir = {DESTDIR}
|
chdir = __FINALPATH__
|
||||||
|
|
||||||
; Redirect worker stdout and stderr into main error log.
|
; Redirect worker stdout and stderr into main error log.
|
||||||
catch_workers_output = yes
|
catch_workers_output = yes
|
||||||
|
|
|
@ -38,12 +38,10 @@ ynh_webpath_register "$app" "$domain" "$path"
|
||||||
LOGDIR=/var/log/$app
|
LOGDIR=/var/log/$app
|
||||||
|
|
||||||
# Check destination directory
|
# Check destination directory
|
||||||
DESTDIR="/var/www/${app}"
|
final_path=/var/www/$app
|
||||||
[[ -d "$DESTDIR" ]] && ynh_die \
|
test ! -e "$final_path" || ynh_die "This path already contains a folder"
|
||||||
"The destination directory '${DESTDIR}' already exists.\
|
|
||||||
You should safely delete it before installing this app."
|
|
||||||
|
|
||||||
mkdir -p "$DESTDIR"
|
mkdir -p "$final_path"
|
||||||
|
|
||||||
# Check whether Baïkal or Radicale is installed
|
# Check whether Baïkal or Radicale is installed
|
||||||
baikal_install=$(agendav_app_check_installation "baikal")
|
baikal_install=$(agendav_app_check_installation "baikal")
|
||||||
|
@ -63,7 +61,7 @@ fi
|
||||||
# Install dependencies
|
# Install dependencies
|
||||||
ynh_install_app_dependencies php5-cli
|
ynh_install_app_dependencies php5-cli
|
||||||
|
|
||||||
ynh_setup_source "$DESTDIR"
|
ynh_setup_source "$final_path"
|
||||||
|
|
||||||
# Generate random password and encryption key
|
# Generate random password and encryption key
|
||||||
dbpass=$(ynh_string_random)
|
dbpass=$(ynh_string_random)
|
||||||
|
@ -72,7 +70,7 @@ ynh_app_setting_set "$app" encryptkey "$encryptkey"
|
||||||
ynh_app_setting_set "$app" mysqlpwd "$dbpass"
|
ynh_app_setting_set "$app" mysqlpwd "$dbpass"
|
||||||
|
|
||||||
# Copy and set AgenDAV configuration
|
# Copy and set AgenDAV configuration
|
||||||
conf_path="${DESTDIR}/web/config/settings.php"
|
conf_path="${final_path}/web/config/settings.php"
|
||||||
cp ../conf/settings.php "$conf_path"
|
cp ../conf/settings.php "$conf_path"
|
||||||
sed -i "s/{DBUSER}/${dbuser}/g" "$conf_path"
|
sed -i "s/{DBUSER}/${dbuser}/g" "$conf_path"
|
||||||
sed -i "s/{DBPASS}/${dbpass}/g" "$conf_path"
|
sed -i "s/{DBPASS}/${dbpass}/g" "$conf_path"
|
||||||
|
@ -89,20 +87,20 @@ caldav_url="https://${caldav_domain}${caldav_path%/}"
|
||||||
sed -i "s@{CALDAV_BASEURL}@${caldav_url}${caldav_baseurl}@g" "$conf_path"
|
sed -i "s@{CALDAV_BASEURL}@${caldav_url}${caldav_baseurl}@g" "$conf_path"
|
||||||
sed -i "s@{CALDAV_DOMAIN}@${caldav_domain}@g" "$conf_path"
|
sed -i "s@{CALDAV_DOMAIN}@${caldav_domain}@g" "$conf_path"
|
||||||
|
|
||||||
ynh_system_user_create "$app" "$DESTDIR"
|
ynh_system_user_create "$app" "$final_path"
|
||||||
|
|
||||||
# Protect source code against modifications
|
# Protect source code against modifications
|
||||||
find "${DESTDIR}" -type f -exec chown root:root {} \; -exec chmod 644 {} \;
|
find "${final_path}" -type f -exec chown root:root {} \; -exec chmod 644 {} \;
|
||||||
find "${DESTDIR}" -type d -exec chown root:root {} \; -exec chmod 755 {} \;
|
find "${final_path}" -type d -exec chown root:root {} \; -exec chmod 755 {} \;
|
||||||
|
|
||||||
# Only agendav user should write here
|
# Only agendav user should write here
|
||||||
chown -hR $app: "${DESTDIR}/web/var/cache/"{profiler,twig}
|
chown -hR $app: "${final_path}/web/var/cache/"{profiler,twig}
|
||||||
chmod -R 750 "${DESTDIR}/web/var/cache/"{profiler,twig}
|
chmod -R 750 "${final_path}/web/var/cache/"{profiler,twig}
|
||||||
|
|
||||||
# The agendav user should read here, but does not need to write
|
# The agendav user should read here, but does not need to write
|
||||||
# Other users should not be able to read as it stores passwords.
|
# Other users should not be able to read as it stores passwords.
|
||||||
find "${DESTDIR}/web/config" -type f -exec chown root:$app {} \; -exec chmod 640 {} \;
|
find "${final_path}/web/config" -type f -exec chown root:$app {} \; -exec chmod 640 {} \;
|
||||||
find "${DESTDIR}/web/config" -type d -exec chown root:$app {} \; -exec chmod 750 {} \;
|
find "${final_path}/web/config" -type d -exec chown root:$app {} \; -exec chmod 750 {} \;
|
||||||
|
|
||||||
# Create log directory
|
# Create log directory
|
||||||
install -m 750 -o $app -g adm -d "$LOGDIR"
|
install -m 750 -o $app -g adm -d "$LOGDIR"
|
||||||
|
@ -112,27 +110,15 @@ ynh_mysql_create_db "$dbname" "$dbuser" "$dbpass"
|
||||||
|
|
||||||
# Run database migrations
|
# Run database migrations
|
||||||
(
|
(
|
||||||
cd $DESTDIR
|
cd $final_path
|
||||||
php agendavcli migrations:migrate --no-interaction
|
php agendavcli migrations:migrate --no-interaction
|
||||||
)
|
)
|
||||||
|
|
||||||
# Copy and set nginx configuration
|
# Copy and set nginx configuration
|
||||||
nginx_conf="/etc/nginx/conf.d/${domain}.d/${app}.conf"
|
ynh_add_nginx_config
|
||||||
sed -i "s@{PATH}@${path}@g" ../conf/nginx.conf
|
|
||||||
sed -i "s@{LOCATION}@${path:-/}@g" ../conf/nginx.conf
|
|
||||||
sed -i "s@{DESTDIR}@${DESTDIR}@g" ../conf/nginx.conf
|
|
||||||
sed -i "s@{POOLNAME}@${app}@g" ../conf/nginx.conf
|
|
||||||
# comment redirection in case of an installation at root
|
|
||||||
[[ -n "$path" ]] || sed -i '$s/^/#/' ../conf/nginx.conf
|
|
||||||
cp ../conf/nginx.conf "$nginx_conf"
|
|
||||||
|
|
||||||
# Copy and set php-fpm configuration
|
# Copy and set php-fpm configuration
|
||||||
phpfpm_conf="/etc/php5/fpm/pool.d/${app}.conf"
|
ynh_add_fpm_config
|
||||||
sed -i "s@{POOLNAME}@${app}@g" ../conf/php-fpm.conf
|
|
||||||
sed -i "s@{DESTDIR}@${DESTDIR}/@g" ../conf/php-fpm.conf
|
|
||||||
sed -i "s@{USER}@${app}@g" ../conf/php-fpm.conf
|
|
||||||
sed -i "s@{GROUP}@${app}@g" ../conf/php-fpm.conf
|
|
||||||
cp ../conf/php-fpm.conf "$phpfpm_conf"
|
|
||||||
|
|
||||||
if [ "$is_public" -eq 0 ]
|
if [ "$is_public" -eq 0 ]
|
||||||
then # Remove the public access
|
then # Remove the public access
|
||||||
|
|
|
@ -37,12 +37,10 @@ fi
|
||||||
LOGDIR=/var/log/$app
|
LOGDIR=/var/log/$app
|
||||||
|
|
||||||
# Check destination directory
|
# Check destination directory
|
||||||
DESTDIR="/var/www/$app"
|
final_path=/var/www/$app
|
||||||
[[ ! -d $DESTDIR ]] && ynh_die \
|
test ! -e "$final_path" || ynh_die "This path already contains a folder"
|
||||||
"The destination directory '$DESTDIR' does not exist.\
|
|
||||||
The app is not correctly installed, you should remove it first."
|
|
||||||
|
|
||||||
mkdir -p "$DESTDIR"
|
mkdir -p "$final_path"
|
||||||
|
|
||||||
# Check whether Baïkal or Radicale is installed
|
# Check whether Baïkal or Radicale is installed
|
||||||
baikal_install=$(agendav_app_check_installation "baikal")
|
baikal_install=$(agendav_app_check_installation "baikal")
|
||||||
|
@ -62,10 +60,10 @@ fi
|
||||||
# Install dependencies
|
# Install dependencies
|
||||||
ynh_install_app_dependencies php5-cli
|
ynh_install_app_dependencies php5-cli
|
||||||
|
|
||||||
ynh_setup_source "$DESTDIR"
|
ynh_setup_source "$final_path"
|
||||||
|
|
||||||
# Copy and set AgenDAV configuration
|
# Copy and set AgenDAV configuration
|
||||||
conf_path="${DESTDIR}/web/config/settings.php"
|
conf_path="${final_path}/web/config/settings.php"
|
||||||
cp ../conf/settings.php "$conf_path"
|
cp ../conf/settings.php "$conf_path"
|
||||||
sed -i "s/{DBUSER}/${dbuser}/g" "$conf_path"
|
sed -i "s/{DBUSER}/${dbuser}/g" "$conf_path"
|
||||||
sed -i "s/{DBPASS}/${dbpass}/g" "$conf_path"
|
sed -i "s/{DBPASS}/${dbpass}/g" "$conf_path"
|
||||||
|
@ -82,49 +80,36 @@ caldav_url="https://${caldav_domain}${caldav_path%/}"
|
||||||
sed -i "s@{CALDAV_BASEURL}@${caldav_url}${caldav_baseurl}@g" "$conf_path"
|
sed -i "s@{CALDAV_BASEURL}@${caldav_url}${caldav_baseurl}@g" "$conf_path"
|
||||||
sed -i "s@{CALDAV_DOMAIN}@${caldav_domain}@g" "$conf_path"
|
sed -i "s@{CALDAV_DOMAIN}@${caldav_domain}@g" "$conf_path"
|
||||||
|
|
||||||
ynh_system_user_create "$app" "$DESTDIR"
|
ynh_system_user_create "$app" "$final_path"
|
||||||
|
|
||||||
# Protect source code against modifications
|
# Protect source code against modifications
|
||||||
find "${DESTDIR}" -type f -exec chown root:root {} \; -exec chmod 644 {} \;
|
find "${final_path}" -type f -exec chown root:root {} \; -exec chmod 644 {} \;
|
||||||
find "${DESTDIR}" -type d -exec chown root:root {} \; -exec chmod 755 {} \;
|
find "${final_path}" -type d -exec chown root:root {} \; -exec chmod 755 {} \;
|
||||||
|
|
||||||
# Only agendav user should write here
|
# Only agendav user should write here
|
||||||
chown -hR $app: "${DESTDIR}/web/var/cache/"{profiler,twig}
|
chown -hR $app: "${final_path}/web/var/cache/"{profiler,twig}
|
||||||
chmod -R 750 "${DESTDIR}/web/var/cache/"{profiler,twig}
|
chmod -R 750 "${final_path}/web/var/cache/"{profiler,twig}
|
||||||
|
|
||||||
# The agendav user should read here, but does not need to write
|
# The agendav user should read here, but does not need to write
|
||||||
# Other users should not be able to read as it stores passwords.
|
# Other users should not be able to read as it stores passwords.
|
||||||
find "${DESTDIR}/web/config" -type f -exec chown root:$app {} \; -exec chmod 640 {} \;
|
find "${final_path}/web/config" -type f -exec chown root:$app {} \; -exec chmod 640 {} \;
|
||||||
find "${DESTDIR}/web/config" -type d -exec chown root:$app {} \; -exec chmod 750 {} \;
|
find "${final_path}/web/config" -type d -exec chown root:$app {} \; -exec chmod 750 {} \;
|
||||||
|
|
||||||
# Create log directory
|
# Create log directory
|
||||||
install -m 750 -o $app -g adm -d "$LOGDIR"
|
install -m 750 -o $app -g adm -d "$LOGDIR"
|
||||||
|
|
||||||
# Run database migrations
|
# Run database migrations
|
||||||
(
|
(
|
||||||
cd $DESTDIR
|
cd $final_path
|
||||||
php agendavcli migrations:migrate --no-interaction
|
php agendavcli migrations:migrate --no-interaction
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
# Copy and set nginx configuration
|
# Copy and set nginx configuration
|
||||||
nginx_conf="/etc/nginx/conf.d/${domain}.d/${app}.conf"
|
ynh_add_nginx_config
|
||||||
sed -i "s@{PATH}@${path}@g" ../conf/nginx.conf
|
|
||||||
sed -i "s@{LOCATION}@${path:-/}@g" ../conf/nginx.conf
|
|
||||||
sed -i "s@{DESTDIR}@${DESTDIR}@g" ../conf/nginx.conf
|
|
||||||
sed -i "s@{POOLNAME}@${app}@g" ../conf/nginx.conf
|
|
||||||
# comment redirection in case of an installation at root
|
|
||||||
[[ -n "$path" ]] || sed -i '$s/^/#/' ../conf/nginx.conf
|
|
||||||
cp ../conf/nginx.conf "$nginx_conf"
|
|
||||||
|
|
||||||
# Copy and set php-fpm configuration
|
# Copy and set php-fpm configuration
|
||||||
phpfpm_conf="/etc/php5/fpm/pool.d/${app}.conf"
|
ynh_add_fpm_config
|
||||||
sed -i "s@{POOLNAME}@${app}@g" ../conf/php-fpm.conf
|
|
||||||
sed -i "s@{DESTDIR}@${DESTDIR}/@g" ../conf/php-fpm.conf
|
|
||||||
sed -i "s@{USER}@${app}@g" ../conf/php-fpm.conf
|
|
||||||
sed -i "s@{GROUP}@${app}@g" ../conf/php-fpm.conf
|
|
||||||
cp ../conf/php-fpm.conf "$phpfpm_conf"
|
|
||||||
|
|
||||||
|
|
||||||
if [ $is_public -eq 0 ]
|
if [ $is_public -eq 0 ]
|
||||||
then # Remove the public access
|
then # Remove the public access
|
||||||
|
|
Loading…
Add table
Reference in a new issue