peertube-search-index_ynh/scripts/install

88 lines
2.9 KiB
Bash

#!/bin/bash
#=================================================
# GENERIC START
#=================================================
# IMPORT GENERIC HELPERS
#=================================================
source _common.sh
source /usr/share/yunohost/helpers
#=================================================
# INSTALL NODEJS
#=================================================
ynh_script_progression --message="Installing NodeJS..."
ynh_install_nodejs --nodejs_version="$NODEJS_VERSION"
#=================================================
# START ELASTICSEARCH
#=================================================
ynh_script_progression --message="Starting elasticsearch..."
# Fix permissions in case of remove/reinstall
chown -R elasticsearch:elasticsearch /var/lib/elasticsearch
systemctl enable elasticsearch.service --quiet
systemctl start elasticsearch.service
#=================================================
# DOWNLOAD, CHECK AND UNPACK SOURCE
#=================================================
ynh_script_progression --message="Setting up source files..."
_git_clone_or_pull "$install_dir/sources"
chmod -R o-rwx "$install_dir"
chown -R "$app:$app" "$install_dir"
#=================================================
# BUILDING
#=================================================
ynh_script_progression --message="Building..."
pushd "$install_dir/sources"
ynh_use_nodejs
ynh_exec_as "$app" env "$ynh_node_load_PATH" yarn install --pure-lockfile
ynh_exec_as "$app" mkdir -p "dist"
ynh_exec_as "$app" env "$ynh_node_load_PATH" "$ynh_npm" run build
popd
#=================================================
# ADD A CONFIGURATION
#=================================================
ynh_script_progression --message="Adding a config file..."
ynh_add_config --template="default.yaml" --destination="$install_dir/sources/config/production.yaml"
chmod 400 "$install_dir/sources/config/production.yaml"
chown "$app:$app" "$install_dir/sources/config/production.yaml"
#=================================================
# SYSTEM CONFIGURATION
#=================================================
ynh_script_progression --message="Adding 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
yunohost service add "$app" --description="$app search index daemon"
# Use logrotate to manage application logfile(s)
ynh_use_logrotate
#=================================================
# START SYSTEMD SERVICE
#=================================================
ynh_script_progression --message="Starting $app's systemd service..."
# Start a systemd service
ynh_systemd_action --service_name="$app" --action="start" --log_path="systemd" --line_match="Server listening on port"
#=================================================
# END OF SCRIPT
#=================================================
ynh_script_progression --message="Installation of $app completed"