diff --git a/conf/ethercalc b/conf/ethercalc index 71b27fd..39ac15f 100644 --- a/conf/ethercalc +++ b/conf/ethercalc @@ -14,11 +14,11 @@ PATH="/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/opt/node/bin LOGFILE="/var/log/ethercalc/YUNOLOG.log" EPLITE_DIR="/usr/local/bin" EPLITE_BIN="ethercalc" -USER="www-data" -GROUP="www-data" +USER="$app" +GROUP="$app" DESC="EtherCalc" NAME="$app" - +export NODE_ENV=production set -e . /lib/lsb/init-functions diff --git a/conf/logrotate b/conf/logrotate new file mode 100644 index 0000000..99e9209 --- /dev/null +++ b/conf/logrotate @@ -0,0 +1,10 @@ +YNH_LOGFILE +{ +weekly +missingok +rotate 12 +notifempty +compress +delaycompress +copytruncate +} diff --git a/scripts/install b/scripts/install index e649fca..c7d4d32 100644 --- a/scripts/install +++ b/scripts/install @@ -16,17 +16,30 @@ if [[ ! $? -eq 0 ]]; then exit 1 fi -# Save specific settings +echo "Register configuration..." sudo yunohost app setting $app_id_forked is_public -v $is_public +sudo yunohost app setting $app_id_forked port -v $port # Remove trailing "/" for next commands path=${path%/} -# Install dependances +echo "Install dependencies..." +sudo apt-get update sudo apt-get install nodejs-legacy npm redis-server -y -sudo npm i -g $app_id -# Copy files to the right place +echo "Installing EtherCalc with NPM..." +final_path=/var/www/$app_id_forked +sudo mkdir -p $final_path +sudo useradd -d $final_path $app_id_forked +su --shell /bin/bash --command "cd $final_path/ && npm install --production $app_id" $app_id_forked + +echo "Cleaning up install tree..." +sudo rm -rf $final_path/.npm +find $final_path -type d | grep "test$" | xargs sudo rm -rf +find $final_path -type d | grep "tests$" | xargs sudo rm -rf + +echo "Setting up init script..." +logfile=/var/log/$app_id/$app_id_forked.log sed -i "s@YUNOPORT@$port@g" ../conf/$app_id sed -i "s@YUNOLOG@$app_id_forked@g" ../conf/$app_id sed -i "s@YUNOPATH@$path@g" ../conf/$app_id @@ -36,10 +49,17 @@ sudo update-rc.d $app_id_forked defaults if [ ! -d "/var/log/$app_id/" ]; then sudo mkdir /var/log/$app_id/ fi -sudo touch /var/log/$app_id/$app_id_forked.log -sudo chown www-data /var/log/$app_id/$app_id_forked.log +sudo touch $logfile +sudo chown $app_id_forked $logfile +sudo service $app_id_forked stop +sudo service $app_id_forked start +sudo yunohost service add $app_id_forked -l $logfile -# Modify Nginx configuration file and copy it to Nginx conf directory +echo "Setting up logrotate configuration..." +sed -i "s@YNH_LOGFILE@$logfile@g" ../conf/logrotate +sudo cp ../conf/logrotate /etc/logrotate.d/$app_id_forked + +echo "Nginx configuration ..." sed -i "s@PATHTOCHANGE@$path@g" ../conf/nginx.conf* sed -i "s@ALIASTOCHANGE@$final_path/@g" ../conf/nginx.conf* sed -i "s@YUNOPORT@$port@g" ../conf/nginx.conf* @@ -50,12 +70,10 @@ else sudo cp ../conf/nginx.conf /etc/nginx/conf.d/$domain.d/$app_id_forked.conf fi -# Reload Nginx and regenerate SSOwat conf +echo "Reloading Nginx..." sudo service nginx reload if [ "$is_public" = "Yes" ]; then sudo yunohost app setting ethercalc skipped_uris -v "/" fi -sudo service $app_id_forked stop -sudo service $app_id_forked start sudo yunohost app ssowatconf diff --git a/scripts/remove b/scripts/remove index de27e0b..2803bce 100644 --- a/scripts/remove +++ b/scripts/remove @@ -7,9 +7,11 @@ name+="calc" domain=$(sudo yunohost app setting $app domain) sudo rm -f /etc/nginx/conf.d/$domain.d/$app.conf -sudo rm -Rf /var/log/$name/$app +sudo rm -Rf /var/log/$name/$app.log* sudo update-rc.d $app remove sudo service $app stop sudo rm /etc/init.d/$app +sudo yunohost service remove $app +sudo userdel --remove $app