From ff79e14743d051d8bb1302f1493453cadf249703 Mon Sep 17 00:00:00 2001 From: Alexis Tyler Date: Mon, 26 Oct 2020 16:43:11 +1030 Subject: [PATCH] feat(rc): remember env on reboot --- dynamix.unraid.net.plg | 98 ++++++++++++++++++++++++++---------------- 1 file changed, 61 insertions(+), 37 deletions(-) diff --git a/dynamix.unraid.net.plg b/dynamix.unraid.net.plg index 4383a5e44..a59785a16 100644 --- a/dynamix.unraid.net.plg +++ b/dynamix.unraid.net.plg @@ -7,6 +7,7 @@ + @@ -49,15 +50,26 @@ fi &plugins; + + +env="&env;" + $envFile elif [[ $currentEnv = "staging" ]]; then echo "Switching from staging to production" - sed -i -e '0,/env="staging"/s/env="staging"/env="production"/' $rcFile - env="production" + echo 'env="production"' > $envFile fi - start - sleep 1 - status + source $envFile; + reload } -start() { - stop +_start() { + _stop local old_working_directory=$(echo $pwd) + mkdir -p $node_base_directory cd $node_base_directory /usr/local/bin/node/node-api/node_modules/pm2/bin/pm2 start $node_base_directory/node-api/ecosystem.config.js --env=$(echo $env) --no-daemon &> /dev/null & cd $old_working_directory +} +start() { + _start sleep 1 status exit 0 } +_node_api_version() { + # Borrowed from https://gist.github.com/DarrenN/8c6a5b969481725a4413 + local version=$(grep '"version"' $node_base_directory/node-api/package.json | cut -d '"' -f 4) + echo "v$version" +} +_plugins_version() { + # Borrowed from https://gist.github.com/DarrenN/8c6a5b969481725a4413 + local version=$(grep '"version"' $node_base_directory/plugins/package.json | cut -d '"' -f 4) + echo "v$version" +} report() { cat << EOF -<---- Version ----> -$(version) - -<------ OS -------> +<-----UNRAID-API-REPORT-----> +Env $env +Node API $(_node_api_version) +Official plugins $(_plugins_version) Unraid v$(source /etc/unraid-version; echo "$version";) + EOF } startdebug() { - stop + _stop local old_working_directory=$(echo $pwd) cd $node_base_directory /usr/local/bin/node/node-api/node_modules/pm2/bin/pm2 start $node_base_directory/node-api/ecosystem.config.js --env=$(echo $env)-debug --no-daemon cd $old_working_directory } -stop() { +_stop() { local node_api_pid=$(pidof node-api | awk '{print $1}') if [[ $node_api_pid ]]; then local parent_pid=$(cat /proc/$node_api_pid/status | grep PPid | cut -f2) @@ -129,17 +145,25 @@ stop() { fi fi } -reload() { - stop +stop() { + echo "Stopping Unraid-api" + _stop sleep 1 - start + status + exit 0 +} +reload() { + echo "Reloading Unraid-api" + _stop + sleep 1 + _start sleep 1 status exit 0 } install() { # Stop old process - stop + _stop # Install node-api and plugins for download in ${downloads[@]}; do @@ -154,7 +178,12 @@ install() { cp /boot/config/plugins/Unraid.net/wc/* /usr/local/emhttp/webGui/wc # Start new process - start + _start + + # Wait for inital process to boot + sleep 2 + status + exit 0 } uninstall() { stop @@ -168,9 +197,6 @@ case "$1" in 'status') status ;; -'version') - version - ;; 'start') start ;; @@ -185,8 +211,6 @@ case "$1" in ;; 'stop') stop - sleep 1 - status ;; 'reload') reload