1
0
Fork 0
mirror of https://github.com/YunoHost-Apps/ethercalc_ynh.git synced 2024-09-03 18:26:36 +02:00

Get this application installing again

This commit is contained in:
Luke Murphy 2019-08-07 15:13:10 +02:00
parent 0e7a4143d4
commit 3e711fd89b
No known key found for this signature in database
GPG key ID: 5E2EF5A63E3718CC
9 changed files with 52 additions and 145 deletions

View file

@ -1,78 +0,0 @@
#!/bin/sh
### BEGIN INIT INFO
# Provides: YUNOAPP
# Required-Start: $local_fs $remote_fs $network $syslog
# Required-Stop: $local_fs $remote_fs $network $syslog
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: starts YUNOAPP
# Description: starts YUNOAPP using start-stop-daemon
### END INIT INFO
PATH="/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/opt/node/bin"
LOGFILE="/var/log/ethercalc/YUNOLOG.log"
EPLITE_DIR="/var/www/YUNOAPP/node_modules/.bin"
EPLITE_BIN="ethercalc"
USER="YUNOAPP"
GROUP="YUNOAPP"
DESC="EtherCalc"
NAME="YUNOAPP"
export NODE_ENV=production
set -e
. /lib/lsb/init-functions
start() {
echo "Starting $DESC... "
start-stop-daemon --start --chuid "$USER:$GROUP" --chdir $EPLITE_DIR --background --make-pidfile --pidfile /var/run/$NAME.pid --startas /bin/bash -- -c "exec $EPLITE_DIR/$EPLITE_BIN --port YUNOPORT --basepath YUNOPATH YUNOEXPIRE > $LOGFILE 2>&1"
echo "done"
}
#We need this function to ensure the whole process tree will be killed
killtree() {
local _pid=$1
local _sig=${2-TERM}
for _child in $(ps -o pid --no-headers --ppid ${_pid}); do
killtree ${_child} ${_sig}
done
kill -${_sig} ${_pid}
}
stop() {
echo "Stopping $DESC... "
if test -f /var/run/$NAME.pid; then
while test -d /proc/$(cat /var/run/$NAME.pid); do
killtree $(cat /var/run/$NAME.pid) 15
sleep 0.5
done
rm /var/run/$NAME.pid
fi
echo "done"
}
status() {
status_of_proc -p /var/run/$NAME.pid "" "$app" && exit 0 || exit $?
}
case "$1" in
start)
start
;;
stop)
stop
;;
restart)
stop
start
;;
status)
status
;;
*)
echo "Usage: $NAME {start|stop|restart|status}" >&2
exit 1
;;
esac
exit 0

2
conf/ethercalc.env Normal file
View file

@ -0,0 +1,2 @@
PATH="/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/opt/node_n/bin"
NODE_ENV=production

View file

@ -1,10 +0,0 @@
YNH_LOGFILE
{
weekly
missingok
rotate 12
notifempty
compress
delaycompress
copytruncate
}

View file

@ -1,7 +1,6 @@
location / {
rewrite ^PATHTOCHANGE$ PATHTOCHANGE/ permanent;
proxy_pass http://localhost:__PORT__;
proxy_set_header Host $host;
proxy_buffering off;
include conf.d/yunohost_panel.conf.inc;
proxy_pass http://localhost:__PORT__;
proxy_set_header Host $host;
proxy_buffering off;
include conf.d/yunohost_panel.conf.inc;
}

View file

@ -1,7 +0,0 @@
location / {
proxy_pass http://localhost:YUNOPORT/;
proxy_set_header Host $host;
# be careful, this line doesn't override any proxy_buffering on set in a conf.d/file.conf
proxy_buffering off;
include conf.d/yunohost_panel.conf.inc;
}

15
conf/systemd.service Normal file
View file

@ -0,0 +1,15 @@
[Unit]
Description=Run Ethercalc, the collaborative spreadsheet editor.
After=network.target
[Service]
Type=simple
User=__APP__
Group=__APP__
ExecStart=/opt/node_n/bin/ethercalc --port __PORT__ --expire __EXPIRE__
EnvironmentFile=/etc/systemd/system/ethercalc.env
RuntimeMaxSec=86400
Restart=always
[Install]
WantedBy=multi-user.target

View file

@ -1,5 +1,10 @@
#!/bin/bash
#=================================================
# COMMON VARIABLES
#=================================================
pkg_dependencies="redis-server"
# =============================================================================
# YUNOHOST 2.7 FORTHCOMING HELPERS

View file

@ -24,26 +24,13 @@ domain=$YNH_APP_ARG_DOMAIN
is_public=$YNH_APP_ARG_IS_PUBLIC
path_url="/"
expire=$YNH_APP_ARG_EXPIRE
# This is a multi-instance app, meaning it can be installed several times independently
# The id of the app as stated in the manifest is available as $YNH_APP_ID
# The instance number is available as $YNH_APP_INSTANCE_NUMBER (equals "1", "2", ...)
# The app instance name is available as $YNH_APP_INSTANCE_NAME
# - the first time the app is installed, YNH_APP_INSTANCE_NAME = ynhexample
# - the second time the app is installed, YNH_APP_INSTANCE_NAME = ynhexample__2
# - ynhexample__{N} for the subsequent installations, with N=3,4, ...
# The app instance name is probably what you are interested the most, since this is
# guaranteed to be unique. This is a good unique identifier to define installation path,
# db names, ...
app=$YNH_APP_INSTANCE_NAME
#=================================================
# CHECK IF THE APP CAN BE INSTALLED WITH THESE ARGS
#=================================================
# Check web path availability
ynh_webpath_available $domain $path_url
# Register (book) web path
ynh_webpath_register $app $domain $path_url
final_path=/var/www/$app
@ -63,60 +50,66 @@ ynh_app_setting_set $app expire $expire
# FIND AND OPEN A PORT
#=================================================
# Find a free port
port=$(ynh_find_port 8095)
# Open this port
sudo yunohost firewall allow --no-upnp TCP $port 2>&1
ynh_app_setting_set $app port $port
#=================================================
# INSTALL NODEJS
#=================================================
ynh_install_nodejs 6.0.0
ynh_install_nodejs 4.8.7
#=================================================
# INSTALL DEPENDENCIES
#=================================================
apt-get -yy install redis-server
ynh_install_app_dependencies $pkg_dependencies
#=================================================
# DOWNLOAD, CHECK AND UNPACK SOURCE
#=================================================
ynh_app_setting_set $app final_path $final_path
ynh_use_nodejs
npm install -g ethercalc
#=================================================
# NGINX CONFIGURATION
#=================================================
# Create a dedicated nginx config
ynh_add_nginx_config
#=================================================
# CREATE DEDICATED USER
#=================================================
# Create a system user
ynh_system_user_create $app
#=================================================
# SPECIFIC SETUP
#=================================================
#=================================================
#=================================================
# INSTALL ETHERCALC
#=================================================
ynh_use_nodejs
npm install -g ethercalc
#=================================================
# CONFIGURE ETHERCALC
# SETUP SYSTEMD BASED SERVICES
#=================================================
ynh_add_systemd_config
ynh_replace_string --match_string="__PORT__" --replace_string=$port --target_file=/etc/systemd/system/ethercalc.service
ynh_replace_string --match_string="__EXPIRE__" --replace_string=$expire --target_file=/etc/systemd/system/ethercalc.service
cp ../conf/ethercalc.env /etc/systemd/system/ethercalc.env
#=================================================
# START SYSTEMD SERVICE
#=================================================
ynh_systemd_action --service_name=ethercalc --action=enable
ynh_systemd_action --service_name=ethercalc --action=start
#=================================================
# GENERIC FINALIZATION
@ -126,7 +119,6 @@ ynh_system_user_create $app
# SETUP LOGROTATE
#=================================================
# Use logrotate to manage application logfile(s)
ynh_use_logrotate
#=================================================
@ -140,13 +132,12 @@ sudo yunohost service add $app --log "/var/log/ethercalc.log"
#=================================================
if [ $is_public -eq 0 ]
then # Remove the public access
then
ynh_app_setting_delete $app skipped_uris
fi
# 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
@ -154,4 +145,4 @@ fi
# RELOAD NGINX
#=================================================
sudo systemctl reload nginx
ynh_systemd_action --service_name=nginx --action=reload

View file

@ -26,7 +26,6 @@ final_path=$(ynh_app_setting_get $app final_path)
# STOP AND REMOVE SERVICE
#=================================================
# Remove the dedicated systemd config
ynh_remove_systemd_config
#=================================================
@ -43,35 +42,30 @@ fi
# REMOVE DEPENDENCIES
#=================================================
# Remove metapackage and its dependencies
ynh_remove_app_dependencies
#=================================================
# REMOVE THE MYSQL DATABASE
#=================================================
# Remove a database if it exists, along with the associated user
ynh_mysql_remove_db $db_name $db_name
#=================================================
# REMOVE APP MAIN DIR
#=================================================
# Remove the app directory securely
ynh_secure_remove "$final_path"
#=================================================
# REMOVE NGINX CONFIGURATION
#=================================================
# Remove the dedicated nginx config
ynh_remove_nginx_config
#=================================================
# REMOVE LOGROTATE CONFIGURATION
#=================================================
# Remove the app-specific logrotate config
ynh_remove_logrotate
#=================================================
@ -90,13 +84,10 @@ fi
# REMOVE THE CRON FILE
#=================================================
# Remove a cron file
ynh_secure_remove "/etc/cron.d/$app"
# Remove a directory securely
ynh_secure_remove "/etc/$app/"
# Remove the log files
ynh_secure_remove "/var/log/$app/"
#=================================================
@ -105,5 +96,4 @@ ynh_secure_remove "/var/log/$app/"
# REMOVE DEDICATED USER
#=================================================
# Delete a system user
ynh_system_user_delete $app