From af9583feacb9146384fd58eb834dea8ccc4979f6 Mon Sep 17 00:00:00 2001 From: Luke Murphy Date: Wed, 7 Aug 2019 14:28:32 +0200 Subject: [PATCH 1/3] Fix variable definition --- scripts/install | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/install b/scripts/install index 2521d5e..9416a2b 100644 --- a/scripts/install +++ b/scripts/install @@ -23,7 +23,7 @@ ynh_abort_if_errors domain=$YNH_APP_ARG_DOMAIN is_public=$YNH_APP_ARG_IS_PUBLIC path_url="/" -expire=YNH_APP_ARG_EXPIRE +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 From 0e7a4143d4b1dc2b4c130f8d43615597ec07abd6 Mon Sep 17 00:00:00 2001 From: Luke Murphy Date: Wed, 7 Aug 2019 14:58:31 +0200 Subject: [PATCH 2/3] Add place holders --- scripts/backup | 3 +++ scripts/change_url | 3 +++ scripts/restore | 3 +++ 3 files changed, 9 insertions(+) create mode 100644 scripts/backup create mode 100644 scripts/change_url create mode 100644 scripts/restore diff --git a/scripts/backup b/scripts/backup new file mode 100644 index 0000000..9549643 --- /dev/null +++ b/scripts/backup @@ -0,0 +1,3 @@ +#!/bin/bash + +#TODO diff --git a/scripts/change_url b/scripts/change_url new file mode 100644 index 0000000..9549643 --- /dev/null +++ b/scripts/change_url @@ -0,0 +1,3 @@ +#!/bin/bash + +#TODO diff --git a/scripts/restore b/scripts/restore new file mode 100644 index 0000000..9549643 --- /dev/null +++ b/scripts/restore @@ -0,0 +1,3 @@ +#!/bin/bash + +#TODO From 3e711fd89b5a6a801a39445b5b6167f59a639453 Mon Sep 17 00:00:00 2001 From: Luke Murphy Date: Wed, 7 Aug 2019 15:13:10 +0200 Subject: [PATCH 3/3] Get this application installing again --- conf/ethercalc | 78 ------------------------------------------- conf/ethercalc.env | 2 ++ conf/logrotate | 10 ------ conf/nginx.conf | 9 +++-- conf/nginx.conf-nosub | 7 ---- conf/systemd.service | 15 +++++++++ scripts/_common.sh | 5 +++ scripts/install | 61 +++++++++++++++------------------ scripts/remove | 10 ------ 9 files changed, 52 insertions(+), 145 deletions(-) delete mode 100644 conf/ethercalc create mode 100644 conf/ethercalc.env delete mode 100644 conf/logrotate delete mode 100644 conf/nginx.conf-nosub create mode 100644 conf/systemd.service diff --git a/conf/ethercalc b/conf/ethercalc deleted file mode 100644 index 7c176ff..0000000 --- a/conf/ethercalc +++ /dev/null @@ -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 diff --git a/conf/ethercalc.env b/conf/ethercalc.env new file mode 100644 index 0000000..45e7535 --- /dev/null +++ b/conf/ethercalc.env @@ -0,0 +1,2 @@ +PATH="/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/opt/node_n/bin" +NODE_ENV=production diff --git a/conf/logrotate b/conf/logrotate deleted file mode 100644 index 99e9209..0000000 --- a/conf/logrotate +++ /dev/null @@ -1,10 +0,0 @@ -YNH_LOGFILE -{ -weekly -missingok -rotate 12 -notifempty -compress -delaycompress -copytruncate -} diff --git a/conf/nginx.conf b/conf/nginx.conf index 66bffa9..070736c 100644 --- a/conf/nginx.conf +++ b/conf/nginx.conf @@ -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; } diff --git a/conf/nginx.conf-nosub b/conf/nginx.conf-nosub deleted file mode 100644 index cbdccdc..0000000 --- a/conf/nginx.conf-nosub +++ /dev/null @@ -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; -} diff --git a/conf/systemd.service b/conf/systemd.service new file mode 100644 index 0000000..7f3282c --- /dev/null +++ b/conf/systemd.service @@ -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 diff --git a/scripts/_common.sh b/scripts/_common.sh index 14a446e..69c30cc 100644 --- a/scripts/_common.sh +++ b/scripts/_common.sh @@ -1,5 +1,10 @@ #!/bin/bash +#================================================= +# COMMON VARIABLES +#================================================= + +pkg_dependencies="redis-server" # ============================================================================= # YUNOHOST 2.7 FORTHCOMING HELPERS diff --git a/scripts/install b/scripts/install index 9416a2b..3a8e1a5 100644 --- a/scripts/install +++ b/scripts/install @@ -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 diff --git a/scripts/remove b/scripts/remove index 409e5fb..2e18171 100644 --- a/scripts/remove +++ b/scripts/remove @@ -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