From ea9670225ee46ef8b377ebe76e08ab922bada6f4 Mon Sep 17 00:00:00 2001 From: Michele Marcucci Date: Fri, 2 Jul 2021 15:37:27 +0200 Subject: [PATCH 1/6] Fixes --- .../graphqlModules/Mcu/McuAppVersion.js | 18 ++++++++++++++++++ src/graphql/graphqlModules/Mcu/McuStats.js | 1 - src/store/api/mcu/mcuAppVersion.js | 13 +++++++++++++ src/store/api/mcu/mcuStats.js | 2 -- 4 files changed, 31 insertions(+), 3 deletions(-) create mode 100644 src/graphql/graphqlModules/Mcu/McuAppVersion.js create mode 100644 src/store/api/mcu/mcuAppVersion.js diff --git a/src/graphql/graphqlModules/Mcu/McuAppVersion.js b/src/graphql/graphqlModules/Mcu/McuAppVersion.js new file mode 100644 index 0000000..6916f7a --- /dev/null +++ b/src/graphql/graphqlModules/Mcu/McuAppVersion.js @@ -0,0 +1,18 @@ +module.exports.typeDefs = ` + type McuActions { + version: McuAppVersionOutput! + } + + type McuAppVersionOutput { + result: String + error: Error + } +` + +module.exports.resolvers = { + McuActions: { + version (root, args, { dispatch }) { + return dispatch('api/mcu/version') + } + } +} diff --git a/src/graphql/graphqlModules/Mcu/McuStats.js b/src/graphql/graphqlModules/Mcu/McuStats.js index 112bee6..e7c9518 100644 --- a/src/graphql/graphqlModules/Mcu/McuStats.js +++ b/src/graphql/graphqlModules/Mcu/McuStats.js @@ -13,7 +13,6 @@ module.exports.typeDefs = ` } type McuStats { - currentAppVersion: String, timestamp: String! hostname: String, operatingSystem: String diff --git a/src/store/api/mcu/mcuAppVersion.js b/src/store/api/mcu/mcuAppVersion.js new file mode 100644 index 0000000..a8b7ae6 --- /dev/null +++ b/src/store/api/mcu/mcuAppVersion.js @@ -0,0 +1,13 @@ +const { join } = require('path') +const { exec } = require('child_process') +const axios = require('axios') + +module.exports = ({ define }) => { + define('version', async (payload, { knex, errors, utils }) => { + const gitAppVersion = await axios.get('https://raw.githubusercontent.com/jstefanop/apolloui/production-BTC/package.json'); + const currentAppVersion = (gitAppVersion && gitAppVersion.data) ? gitAppVersion.data.version : null; + return currentAppVersion + }, { + auth: true + }) +} \ No newline at end of file diff --git a/src/store/api/mcu/mcuStats.js b/src/store/api/mcu/mcuStats.js index c0c483c..cfa31f8 100644 --- a/src/store/api/mcu/mcuStats.js +++ b/src/store/api/mcu/mcuStats.js @@ -5,8 +5,6 @@ const axios = require('axios') module.exports = ({ define }) => { define('stats', async (payload, { knex, errors, utils }) => { const stats = await getOsStats() - const gitAppVersion = await axios.get('https://raw.githubusercontent.com/jstefanop/apolloui/production-BTC/package.json'); - stats.currentAppVersion = (gitAppVersion && gitAppVersion.data) ? gitAppVersion.data.version : null; stats.timestamp = new Date().toISOString() return { stats } }, { From fa9c846e351f9dd5af63e4619cc0fd64bbfa764b Mon Sep 17 00:00:00 2001 From: Michele Marcucci Date: Mon, 5 Jul 2021 12:37:39 +0200 Subject: [PATCH 2/6] Changed system commands --- apolloui | 2 +- src/store/api/mcu/mcuReboot.js | 2 +- src/store/api/mcu/mcuShutdown.js | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/apolloui b/apolloui index 1d6eb6b..c0d56f4 160000 --- a/apolloui +++ b/apolloui @@ -1 +1 @@ -Subproject commit 1d6eb6b862f9ed6fdbbd7c6d9f1c6f357e631b3c +Subproject commit c0d56f4c4d3eafdf01a8499ddff32d0fcb19506e diff --git a/src/store/api/mcu/mcuReboot.js b/src/store/api/mcu/mcuReboot.js index b77ab60..3682da6 100644 --- a/src/store/api/mcu/mcuReboot.js +++ b/src/store/api/mcu/mcuReboot.js @@ -2,7 +2,7 @@ const { exec } = require('child_process') module.exports = ({ define }) => { define('reboot', async (payload, { knex, errors, utils }) => { - if (process.env.NODE_ENV === 'production') return exec('/etc/system_reboot.sh'); + if (process.env.NODE_ENV === 'production') return exec('sudo reboot'); return; }, { auth: true diff --git a/src/store/api/mcu/mcuShutdown.js b/src/store/api/mcu/mcuShutdown.js index b9417c5..0ad92f6 100644 --- a/src/store/api/mcu/mcuShutdown.js +++ b/src/store/api/mcu/mcuShutdown.js @@ -2,7 +2,7 @@ const { exec } = require('child_process') module.exports = ({ define }) => { define('shutdown', async (payload, { knex, errors, utils }) => { - if (process.env.NODE_ENV === 'production') return exec('/etc/system_shutdown.sh') + if (process.env.NODE_ENV === 'production') return exec('sudo shutdown -h now') return; }, { auth: true From 442ce7e4ee0e105311d19544164b69291e801384 Mon Sep 17 00:00:00 2001 From: Michele Marcucci Date: Mon, 5 Jul 2021 12:49:21 +0200 Subject: [PATCH 3/6] Added update_system script --- backend/update | 15 ++------------- backend/update_system | 22 ++++++++++++++++++++++ 2 files changed, 24 insertions(+), 13 deletions(-) create mode 100644 backend/update_system diff --git a/backend/update b/backend/update index af1ea49..e27c5fb 100755 --- a/backend/update +++ b/backend/update @@ -60,17 +60,6 @@ yarn build echo "80" > $TMPFILE -### SYSTEMD ### -echo -e "${YELLOW} ---> Updating systemd files${NC}" +echo -e "${YELLOW} ---> Running update_system script${NC}" -cp $APOLLO_DIR/backend/apollo-ui.service /etc/systemd/system/ -cp $APOLLO_DIR/backend/apollo-miner.service /etc/systemd/system/ -cp $APOLLO_DIR/backend/node.service /etc/systemd/system/ - -echo -e "${YELLOW} ---> Reloading systemd${NC}" -systemctl daemon-reload - -echo "100" > $TMPFILE - -echo -e "${YELLOW} ---> Restarting APP${NC}" -systemctl restart apollo-ui \ No newline at end of file +$APOLLO_DIR/backend/update_system \ No newline at end of file diff --git a/backend/update_system b/backend/update_system new file mode 100644 index 0000000..0008b25 --- /dev/null +++ b/backend/update_system @@ -0,0 +1,22 @@ +#!/bin/bash + +### SYSTEM commands ### +# Write down this line the system commands needed + +# Don't touch below this line +echo "90" > $TMPFILE + +### SYSTEMD ### +echo -e "${YELLOW} ---> Updating systemd files${NC}" + +cp $APOLLO_DIR/backend/apollo-ui.service /etc/systemd/system/ +cp $APOLLO_DIR/backend/apollo-miner.service /etc/systemd/system/ +cp $APOLLO_DIR/backend/node.service /etc/systemd/system/ + +echo -e "${YELLOW} ---> Reloading systemd${NC}" +systemctl daemon-reload + +echo "100" > $TMPFILE + +echo -e "${YELLOW} ---> Restarting APP${NC}" +systemctl restart apollo-ui \ No newline at end of file From 13984a37079e561c4b3cf7dae73f74ba8d442262 Mon Sep 17 00:00:00 2001 From: Michele Date: Fri, 9 Jul 2021 05:38:06 +0000 Subject: [PATCH 4/6] Update script --- .gitignore | 1 + backend/update | 2 +- backend/update.fake | 0 backend/update_system | 8 +++++++- 4 files changed, 9 insertions(+), 2 deletions(-) mode change 100644 => 100755 backend/update.fake mode change 100644 => 100755 backend/update_system diff --git a/.gitignore b/.gitignore index bdfdf57..6b828bc 100644 --- a/.gitignore +++ b/.gitignore @@ -66,3 +66,4 @@ typings/ #backed backend/apollo-miner/apollo-miner.* backend/apollo-miner/*config* +backend/apollo-miner/miner.events diff --git a/backend/update b/backend/update index e27c5fb..f7a2231 100755 --- a/backend/update +++ b/backend/update @@ -62,4 +62,4 @@ echo "80" > $TMPFILE echo -e "${YELLOW} ---> Running update_system script${NC}" -$APOLLO_DIR/backend/update_system \ No newline at end of file +bash $APOLLO_DIR/backend/update_system diff --git a/backend/update.fake b/backend/update.fake old mode 100644 new mode 100755 diff --git a/backend/update_system b/backend/update_system old mode 100644 new mode 100755 index 0008b25..69858f7 --- a/backend/update_system +++ b/backend/update_system @@ -1,5 +1,11 @@ #!/bin/bash +YELLOW='\033[1;33m' +RED='\033[0;31m' +NC='\033[0m' +TMPFILE='/tmp/update_progress' +APOLLO_DIR=/opt/apolloapi + ### SYSTEM commands ### # Write down this line the system commands needed @@ -19,4 +25,4 @@ systemctl daemon-reload echo "100" > $TMPFILE echo -e "${YELLOW} ---> Restarting APP${NC}" -systemctl restart apollo-ui \ No newline at end of file +systemctl restart apollo-ui From bd058d8269ce7fa5592c0a6f4ce84426ef18e15c Mon Sep 17 00:00:00 2001 From: Michele Date: Fri, 9 Jul 2021 05:46:23 +0000 Subject: [PATCH 5/6] Fix --- backend/update_system | 2 ++ 1 file changed, 2 insertions(+) diff --git a/backend/update_system b/backend/update_system index 69858f7..c61d1f2 100755 --- a/backend/update_system +++ b/backend/update_system @@ -26,3 +26,5 @@ echo "100" > $TMPFILE echo -e "${YELLOW} ---> Restarting APP${NC}" systemctl restart apollo-ui +systemctl restart node +systemctl restart apollo-miner From 6fdccc818bc4e108e86dbfa71c69a9d2705b6e41 Mon Sep 17 00:00:00 2001 From: John Date: Fri, 23 Jul 2021 12:10:18 -0400 Subject: [PATCH 6/6] Backend Fixes --- backend/apollo-miner.service | 3 +++ backend/node/node_start.sh | 9 ++++++++- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/backend/apollo-miner.service b/backend/apollo-miner.service index ac0ee0d..b8b0576 100644 --- a/backend/apollo-miner.service +++ b/backend/apollo-miner.service @@ -10,6 +10,9 @@ ExecStart=/opt/apolloapi/backend/apollo-miner/miner_start.sh WorkingDirectory=/opt/apolloapi/backend/apollo-miner #Stop: ExecStop=/opt/apolloapi/backend/apollo-miner/miner_stop.sh +#Restart +Restart=always +RestartSec=30s [Install] WantedBy=multi-user.target diff --git a/backend/node/node_start.sh b/backend/node/node_start.sh index ba0babe..5dca69b 100755 --- a/backend/node/node_start.sh +++ b/backend/node/node_start.sh @@ -1,3 +1,10 @@ #!/bin/bash -screen -dmS node /opt/apolloapi/backend/node/bitcoind -datadir=/media/nvme/Bitcoin -conf=/opt/apolloapi/backend/node/bitcoin.conf +DEVICE=/dev/nvme0n1p1 + +if [ -b "$DEVICE" ]; then + screen -dmS node /opt/apolloapi/backend/node/bitcoind -datadir=/media/nvme/Bitcoin -conf=/opt/apolloapi/backend/node/bitcoin.conf +else + exit 0 +fi +