From d9d7fd44d3661b8b967675c1d13416ec78128af7 Mon Sep 17 00:00:00 2001 From: Vladimir Lelicanin Date: Fri, 20 Jul 2018 17:52:45 +0200 Subject: [PATCH] Docker (#393) --- .env.example | 10 +- .env.travis | 2 +- Dockerfile | 23 +++-- check-updates.js | 127 +++++++++++++++++++++++++ modules/RemoteControl.js | 5 +- modules/Update.js | 63 +++++++++++++ modules/Utilities.js | 16 ++++ newrelic.js | 53 +++++++++++ ot-node.js | 13 ++- package.json | 12 ++- seeders/20180407124949-node-config.js | 4 +- testnet/install-arango.sh | 12 ++- testnet/papertrail.yml | 6 ++ testnet/register-node.js | 130 +++++++++++++++++++------- testnet/start.sh | 7 ++ testnet/supervisord.conf | 5 + 16 files changed, 430 insertions(+), 58 deletions(-) create mode 100644 check-updates.js create mode 100644 modules/Update.js create mode 100644 newrelic.js create mode 100644 testnet/papertrail.yml create mode 100644 testnet/start.sh diff --git a/.env.example b/.env.example index b320a8fd51..f396f79993 100644 --- a/.env.example +++ b/.env.example @@ -34,7 +34,8 @@ TRUFFLE_MNEMONIC= RINKEBY_ACCESS_KEY= # GENERAL SETTINGS -IMPORT_WHITELIST=127.0.0.1 +IMPORT_WHITELIST=54.93.223.161,127.0.0.1 + # test feature, it is not yet reliable TRAVERSE_NAT_ENABLED=0 @@ -43,8 +44,11 @@ TRAVERSE_NAT_ENABLED=0 TEST_NETWORK_ENABLED=1 # Bootstrap node to connect -BOOTSTRAP_NODE=http://ou66zqo3r7nxmmnuvnvdoqjm662aem3nef4zsyxekdzjv3ngwue7hqyd.onion:443/#fd0fb28ecedf298f70218abf3947c81b50064d41 +BOOTSTRAP_NODE=http://l7j34pimur6qllxr2uyhuujpsmx4ga4olve5em4igbjnmfokllj4bead.onion:443/#694085c1f0379dad80b917ab747ed80cd2c2ed04,http://bev4uwc77b7ag66pkwijry5hfgxmpnehiw63mhgjv4qquxedsnrxoeid.onion:443/#a3405151e3adaff757e3bef2e928143e2b3d3f97 + +# Is this a bootstrap node +IS_BOOTSTRAP_NODE=0 -# Sent logs to OriginTrail - TestNet +# Sent logs to OriginTrail - TestNet SEND_LOGS=1 LOGS_LEVEL_DEBUG=1 diff --git a/.env.travis b/.env.travis index a485533e1a..9989174edb 100644 --- a/.env.travis +++ b/.env.travis @@ -45,7 +45,7 @@ TRAVERSE_NAT_ENABLED=0 TEST_NETWORK_ENABLED=1 # Bootstrap node to connect -BOOTSTRAP_NODE=http://ou66zqo3r7nxmmnuvnvdoqjm662aem3nef4zsyxekdzjv3ngwue7hqyd.onion:443/#fd0fb28ecedf298f70218abf3947c81b50064d41 +BOOTSTRAP_NODE=http://l7j34pimur6qllxr2uyhuujpsmx4ga4olve5em4igbjnmfokllj4bead.onion:443/#694085c1f0379dad80b917ab747ed80cd2c2ed04,http://bev4uwc77b7ag66pkwijry5hfgxmpnehiw63mhgjv4qquxedsnrxoeid.onion:443/#a3405151e3adaff757e3bef2e928143e2b3d3f97 # Sent logs to OriginTrail - TestNet SEND_LOGS=1 diff --git a/Dockerfile b/Dockerfile index 8e23cc5e02..d0a268c02b 100644 --- a/Dockerfile +++ b/Dockerfile @@ -4,7 +4,7 @@ MAINTAINER OriginTrail RUN apt-get -qq update && apt-get -qq -y install curl RUN curl -sL https://deb.nodesource.com/setup_9.x | bash - -RUN apt-get -qq update && apt-get -qq -y install wget apt-transport-https software-properties-common build-essential git nodejs sqlite unzip +RUN apt-get -qq update && apt-get -qq -y install wget apt-transport-https software-properties-common build-essential git nodejs sqlite unzip nano RUN add-apt-repository -y ppa:ethereum/ethereum && apt-get -qq update && apt-get install -y -qq ethereum geth #ArangoDB ADD testnet/install-arango.sh /install-arango.sh @@ -17,17 +17,24 @@ RUN apt-get update && apt install -y -qq supervisor RUN mkdir -p /var/log/supervisor COPY testnet/supervisord.conf /etc/supervisor/conf.d/supervisord.conf -#Clone the project -RUN wget https://codeload.github.com/OriginTrail/ot-node/zip/docker && echo " " -RUN unzip docker -d . && rm docker && mv ot-node-docker ot-node +COPY package.json /tmp/package.json +RUN cd /tmp && npm install + +RUN wget https://github.com/papertrail/remote_syslog2/releases/download/v0.20/remote_syslog_linux_amd64.tar.gz +RUN tar xzf ./remote_syslog_linux_amd64.tar.gz && cd remote_syslog && cp ./remote_syslog /usr/local/bin +ADD testnet/papertrail.yml /etc/log_files.yml +#Clone the project RUN wget https://codeload.github.com/OriginTrail/ot-node/zip/develop RUN unzip develop -d . && rm develop && mv ot-node-develop ot-node +RUN cp -a /tmp/node_modules /ot-node + WORKDIR /ot-node RUN mkdir keys data &> /dev/null -RUN cp .env.example .env && npm install - +RUN cp .env.example .env +COPY testnet/start.sh /ot-node/testnet/start.sh +RUN chmod 400 testnet/start.sh -EXPOSE 4043 8900 3000 3010 -CMD ["/usr/bin/supervisord"] +EXPOSE 5278 8900 3000 4043 3010 +CMD ["sh", "/ot-node/testnet/start.sh"] diff --git a/check-updates.js b/check-updates.js new file mode 100644 index 0000000000..b9b7889a72 --- /dev/null +++ b/check-updates.js @@ -0,0 +1,127 @@ +const AutoUpdater = require('auto-updater'); +const rimraf = require('rimraf'); +const npm = require('npm-cmd'); +const Utilities = require('./modules/Utilities'); + +const log = Utilities.getLogger(); + +const Umzug = require('umzug'); + +const Models = require('./models'); + +const umzug_migrations = new Umzug({ + + storage: 'sequelize', + + storageOptions: { + sequelize: Models.sequelize, + }, + + migrations: { + params: [Models.sequelize.getQueryInterface(), Models.sequelize.constructor, () => { + throw new Error('Migration tried to use old style "done" callback. Please upgrade to "umzug" and return a promise instead.'); + }], + path: './migrations', + pattern: /\.js$/, + }, + +}); + +class AutoUpdate { + static update() { + return new Promise(async (resolve, reject) => { + var autoupdater = new AutoUpdater({ + pathToJson: '', + autoupdate: false, + checkgit: true, + jsonhost: 'raw.githubusercontent.com', + contenthost: 'codeload.github.com', + progressDebounce: 0, + devmode: false, + }); + + // State the events + autoupdater.on('git-clone', () => { + log.warn("You have a clone of the repository. Use 'git pull' to be up-to-date"); + resolve(true); + }); + autoupdater.on('check.up-to-date', (v) => { + log.info(`You have the latest version: ${v}`); + resolve(true); + }); + autoupdater.on('check.out-dated', (v_old, v) => { + log.warn(`Your version is outdated. ${v_old} of ${v}`); + autoupdater.fire('download-update'); // If autoupdate: false, you'll have to do this manually. + // Maybe ask if the'd like to download the update. + }); + autoupdater.on('update.downloaded', () => { + log.warn('Update downloaded and ready for install'); + autoupdater.fire('extract'); // If autoupdate: false, you'll have to do this manually. + }); + autoupdater.on('update.not-installed', () => { + log.warn("The Update was already in your folder! It's ready for install"); + autoupdater.fire('extract'); // If autoupdate: false, you'll have to do this manually. + }); + autoupdater.on('update.extracted', () => { + log.warn('Update extracted successfully!'); + npm.install([], { + cwd: '/ot-node', + save: true, + }, (err) => { + if (err) { + console.log(err); + log.error('Installation failed.'); + } else { + log.info('Installation succeeded!'); + log.warn('RESTARTING THE APP!'); + umzug_migrations.up().then((migrations) => { + log.warn('Database migrated.'); + rimraf.sync('./data/*'); + rimraf.sync('./keys/*'); + this.restartNode(); + }); + } + }); + }); + autoupdater.on('download.start', (name) => { + log.warn(`Starting downloading: ${name}`); + }); + autoupdater.on('download.progress', (name, perc) => { + process.stdout.write(`Downloading ${perc}% \x1B[0G`); + }); + autoupdater.on('download.end', (name) => { + log.warn(`Downloaded ${name}`); + }); + autoupdater.on('download.error', (err) => { + log.error(`Error when downloading: ${err}`); + resolve(true); + }); + autoupdater.on('end', () => { + log.warn('The app is ready to function'); + resolve(true); + }); + autoupdater.on('error', (name, e) => { + log.error(name, e); + resolve(true); + }); + + // Start checking + autoupdater.fire('check'); + }); + } + restartNode() { + setTimeout(() => { + process.on('exit', () => { + /* eslint-disable-next-line */ + require('child_process').spawn(process.argv.shift(), process.argv, { + cwd: process.cwd(), + detached: true, + stdio: 'inherit', + }); + }); + process.exit(0); + }, 5000); + } +} + +module.exports = AutoUpdate; diff --git a/modules/RemoteControl.js b/modules/RemoteControl.js index 58172c6d78..48433e515c 100644 --- a/modules/RemoteControl.js +++ b/modules/RemoteControl.js @@ -89,6 +89,7 @@ class RemoteControl { this.node = this.network.kademlia(); app.listen(config.remote_control_port); await remote.on('connection', (socket) => { + this.log.important('This is Houston. Roger. Out.'); this.socket.initialize(socket); this.getProtocolInfo().then((res) => { socket.emit('system', { info: res }); @@ -295,8 +296,8 @@ class RemoteControl { stdio: 'inherit', }); }); - process.exit(2); - }, 5000); + process.exit(1); + }, 2000); } /** diff --git a/modules/Update.js b/modules/Update.js new file mode 100644 index 0000000000..5a4b0ab1e5 --- /dev/null +++ b/modules/Update.js @@ -0,0 +1,63 @@ +const Utilities = require('./Utilities'); + +class Update { + /** + * Check for updates + */ + checkForUpdates(autoupdater) { + this.autoupdater = autoupdater; + this.registerEvents(); + // Start checking + this.autoupdater.fire('check'); + } + + /** + * Register update events + */ + registerEvents() { + this.log = Utilities.getLogger(); + // State the events + this.autoupdater.on('git-clone', () => { + this.log.warn("You have a clone of the repository. Use 'git pull' to be up-to-date"); + }); + this.autoupdater.on('check.up-to-date', (v) => { + this.log.info(`You have the latest version of OTNode: ${v}`); + }); + this.autoupdater.on('check.out-dated', (v_old, v) => { + this.log.warn(`Your OTNode version is outdated. ${v_old} of ${v}`); + this.autoupdater.fire('download-update'); // If autoupdate: false, you'll have to do this manually. + // Maybe ask if the'd like to download the update. + }); + this.autoupdater.on('update.downloaded', () => { + this.log.log('Update downloaded and ready for install'); + this.autoupdater.fire('extract'); // If autoupdate: false, you'll have to do this manually. + }); + this.autoupdater.on('update.not-installed', () => { + this.log.log("The Update was already in your folder! It's ready for install"); + this.autoupdater.fire('extract'); // If autoupdate: false, you'll have to do this manually. + }); + this.autoupdater.on('update.extracted', () => { + this.log.log('Update extracted successfully!'); + console.warn('RESTART THE APP!'); + }); + this.autoupdater.on('download.start', (name) => { + this.log.log(`Starting downloading: ${name}`); + }); + this.autoupdater.on('download.progress', (name, perc) => { + process.stdout.write(`Downloading ${perc}% \x1B[0G`); + }); + this.autoupdater.on('download.end', (name) => { + this.log.log(`Downloaded ${name}`); + }); + this.autoupdater.on('download.error', (err) => { + this.log.error(`Error when downloading: ${err}`); + }); + this.autoupdater.on('end', () => { + this.log.log('The app is ready to function'); + }); + this.autoupdater.on('error', (name, e) => { + this.log.error(name, e); + }); + } +} +module.exports = new Update(); diff --git a/modules/Utilities.js b/modules/Utilities.js index b50794a5b1..976d7d1018 100644 --- a/modules/Utilities.js +++ b/modules/Utilities.js @@ -123,6 +123,22 @@ class Utilities { } + /** + * Check if there is a new version of ot-node + * @returns {Promise} + */ + + static checkForUpdates() { + return new Promise(async (resolve, reject) => { + // eslint-disable-next-line + const Update = require('../check-updates'); + const res = await Update.update(); + if (res) { + resolve(res); + } + }); + } + /** * Returns winston logger * @returns {*} - log function diff --git a/newrelic.js b/newrelic.js new file mode 100644 index 0000000000..8acc435b6c --- /dev/null +++ b/newrelic.js @@ -0,0 +1,53 @@ +'use strict' +/** + * New Relic agent configuration. + * + * See lib/config/default.js in the agent distribution for a more complete + * description of configuration variables and their potential values. + */ +exports.config = { + /** + * Array of application names. + */ + app_name: ['OtNode'], + /** + * Your New Relic license key. + */ + license_key: '667969272b632a620fb549b26c4655b8f24a1991', + logging: { + /** + * Level at which to log. 'trace' is most useful to New Relic when diagnosing + * issues with the agent, 'info' and higher will impose the least overhead on + * production applications. + */ + level: 'info' + }, + /** + * When true, all request headers except for those listed in attributes.exclude + * will be captured for all traces, unless otherwise specified in a destination's + * attributes include/exclude lists. + */ + allow_all_headers: true, + attributes: { + /** + * Prefix of attributes to exclude from all destinations. Allows * as wildcard + * at end. + * + * NOTE: If excluding headers, they must be in camelCase form to be filtered. + * + * @env NEW_RELIC_ATTRIBUTES_EXCLUDE + */ + exclude: [ + 'request.headers.cookie', + 'request.headers.authorization', + 'request.headers.proxyAuthorization', + 'request.headers.setCookie*', + 'request.headers.x*', + 'response.headers.cookie', + 'response.headers.authorization', + 'response.headers.proxyAuthorization', + 'response.headers.setCookie*', + 'response.headers.x*' + ] + } +} diff --git a/ot-node.js b/ot-node.js index 90c9e43dfa..09c357baa5 100644 --- a/ot-node.js +++ b/ot-node.js @@ -33,6 +33,8 @@ const pjson = require('./package.json'); const log = Utilities.getLogger(); const Web3 = require('web3'); +global.__basedir = __dirname; + process.on('unhandledRejection', (reason, p) => { if (reason.message.startsWith('Invalid JSON RPC response')) { return; @@ -114,6 +116,15 @@ class OTNode { process.exit(1); } + // check for Updates + try { + log.info('Checking for updates'); + await Utilities.checkForUpdates(); + } catch (err) { + console.log(err); + process.exit(1); + } + if (Utilities.isBootstrapNode()) { await this.startBootstrapNode(); this.startRPC(); @@ -510,7 +521,7 @@ class OTNode { Utilities.validateNumberParameter(req.body.total_escrow_time_in_minutes) && Utilities.validateStringParameter(req.body.max_token_amount_per_dh) && Utilities.validateStringParameter(req.body.dh_min_stake_amount) && - Utilities.validateNumberParameter(req.body.dh_min_reputation)) { + Utilities.validateNumberParameterAllowZero(req.body.dh_min_reputation)) { const queryObject = { import_id: req.body.import_id, total_escrow_time: req.body.total_escrow_time_in_minutes * 60000, diff --git a/package.json b/package.json index b6869de973..ea7ed0ba06 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "origintrail-node-1.0bRC", - "version": "1.0.1", + "version": "1.1.0", "description": "OriginTrail node", "main": ".eslintrc.js", "scripts": { @@ -48,6 +48,7 @@ "ajv": "^5.5.2", "arangojs": "^5.8.0", "async": "^2.6.0", + "auto-updater": "git+https://github.com/schrink/auto-updater.git", "awilix": "^3.0.8", "axios": "^0.18.0", "barcoder": "^2.0.1", @@ -81,9 +82,11 @@ "ms": "^2.1.1", "nedb": "^1.8.0", "neo4j-driver": "^1.5.0", + "newrelic": "^4.2.0", "node-rsa": "^0.4.2", "nodeify": "^1.0.1", "npm": "^6.0.0", + "npm-cmd": "^0.2.0", "number-to-bn": "^1.7.0", "pem": "^1.12.3", "python-shell": "^0.5.0", @@ -97,10 +100,11 @@ "sequelize-cli": "^4.0.0", "sleep-async": "^1.0.5", "socket.io": "^2.1.0", + "socket.io-client": "^2.1.1", "socks": "^2.1.6", "solidity-sha3": "^0.4.1", "sqldown": "^2.1.0", - "sqlite3": "^4.0.0", + "sqlite3": "^4.0.1", "superagent": "^3.8.3", "truffle-hdwallet-provider": "0.0.5", "umzug": "^2.1.0", @@ -112,5 +116,9 @@ "winston": "^2.4.3", "winston-loggly-bulk": "^2.0.2", "xml2js": "^0.4.19" + }, + "auto-updater": { + "repo": "origintrail/ot-node", + "branch": "docker" } } diff --git a/seeders/20180407124949-node-config.js b/seeders/20180407124949-node-config.js index 0a60277359..04d1377977 100644 --- a/seeders/20180407124949-node-config.js +++ b/seeders/20180407124949-node-config.js @@ -83,7 +83,7 @@ module.exports = { }, { key: 'onion_virtual_port', - value: '443', + value: '4043', }, { key: 'traverse_nat_enabled', value: process.env.TRAVERSE_NAT_ENABLED ? process.env.TRAVERSE_NAT_ENABLED : '0', @@ -107,7 +107,7 @@ module.exports = { value: '', }, { key: 'onion_enabled', - value: '0', + value: '1', }, { key: 'test_network', value: process.env.TEST_NETWORK_ENABLED ? process.env.TEST_NETWORK_ENABLED : '1', diff --git a/testnet/install-arango.sh b/testnet/install-arango.sh index 993181304a..12eec433ac 100644 --- a/testnet/install-arango.sh +++ b/testnet/install-arango.sh @@ -1,8 +1,12 @@ #!bin/bash -wget https://www.arangodb.com/repositories/arangodb3/xUbuntu_16.04/Release.key -apt-key add Release.key -apt-add-repository 'deb https://www.arangodb.com/repositories/arangodb3/xUbuntu_16.04/ /' +curl -OL https://download.arangodb.com/arangodb33/xUbuntu_16.04/Release.key +apt-key add - < Release.key +echo 'deb https://download.arangodb.com/arangodb33/xUbuntu_16.04/ /' | tee /etc/apt/sources.list.d/arangodb.list +apt-get install apt-transport-https -y apt-get update -y +echo arangodb3 arangodb3/backup boolean false | debconf-set-selections +echo arangodb3 arangodb3/upgrade boolean true | debconf-set-selections +echo arangodb3 arangodb3/storage_engine select mmfiles | debconf-set-selections echo arangodb3 arangodb3/password password root | debconf-set-selections echo arangodb3 arangodb3/password_again password root | debconf-set-selections -apt-get install arangodb3 -y --allow-unauthenticated \ No newline at end of file +apt-get install arangodb3=3.3.12 -y \ No newline at end of file diff --git a/testnet/papertrail.yml b/testnet/papertrail.yml new file mode 100644 index 0000000000..3bc13663c4 --- /dev/null +++ b/testnet/papertrail.yml @@ -0,0 +1,6 @@ +files: + - /ot-node/node.log +destination: + host: logs4.papertrailapp.com + port: 39178 + protocol: tls \ No newline at end of file diff --git a/testnet/register-node.js b/testnet/register-node.js index 2fca79192b..f9f99875cb 100644 --- a/testnet/register-node.js +++ b/testnet/register-node.js @@ -1,4 +1,5 @@ require('dotenv').config(); +require('newrelic'); process.env.NODE_TLS_REJECT_UNAUTHORIZED = '0'; const axios = require('axios'); @@ -6,6 +7,7 @@ const envfile = require('envfile'); const externalip = require('externalip'); const fs = require('fs'); +const socket = require('socket.io-client')('wss://station.origintrail.io:3010'); const Web3 = require('web3'); @@ -39,6 +41,8 @@ const umzug_seeders = new Umzug({ storageOptions: { sequelize: Models.sequelize, + modelName: 'SeedsMeta', + tableName: 'SeedsMeta', }, migrations: { @@ -53,44 +57,29 @@ const umzug_seeders = new Umzug({ class RegisterNode { constructor() { - this.generateWallet().then((result) => { - this.registerNode(result.ip, result.wallet); + this.setConfig().then((result) => { + web3.eth.getBalance(process.env.NODE_WALLET).then((balance) => { + if (balance <= 0) { + this.registerNode(result.ip, result.wallet); + } else { + this.runNode(); + } + }); }); } + socketSend(wallet, nodeIp) { + console.log('Entering sockets...'); + socket.emit('presence', { walletAddress: wallet, ipAddress: nodeIp, connected: true }); + // socket.on('connect', () => { + // socket.emit('presence', { walletAddress: wallet, ipAddress: nodeIp, connected: true }); + // }); + } generateWallet() { return new Promise(async (resolve, reject) => { - const env = envfile.parseFileSync('.env'); - if (!env.NODE_WALLET) { - const account = await web3.eth.accounts.create(); - env.NODE_WALLET = account.address; - env.NODE_PRIVATE_KEY = account.privateKey.substr(2); - env.NODE_IP = await this.getExternalIp(); - env.DB_PASSWORD = 'root'; - - process.env.NODE_WALLET = account.address; - process.env.NODE_PRIVATE_KEY = account.privateKey.substr(2); - process.env.NODE_IP = env.NODE_IP; - process.env.DB_PASSWORD = 'root'; - - const envF = envfile.stringifySync(env); - console.log(env); - fs.writeFile('.env', envF, (err) => { - umzug_migrations.up().then((migrations) => { - umzug_seeders.up().then((migrations) => { - console.log('Configuration loaded...'); - resolve({ - ip: env.NODE_IP, - wallet: env.NODE_WALLET, - }); - }); - }); - }); - } else { - // eslint-disable-next-line - require('../ot-node'); - } + const account = await web3.eth.accounts.create(); + resolve({ wallet: account.address, pk: account.privateKey.substr(2) }); }); } @@ -105,7 +94,7 @@ class RegisterNode { registerNode(ip, wallet) { console.log(ip, wallet); - axios.post('https://spacestation.origintrail.io/api/node/register', { + axios.post('https://station.origintrail.io/api/node/register', { ip, wallet, }).then((result) => { // console.log(result.data); @@ -113,8 +102,7 @@ class RegisterNode { web3.eth.getBalance(process.env.NODE_WALLET).then((balance) => { if (balance > 0) { clearInterval(checkBalanceInterval); - // eslint-disable-next-line - require('../ot-node'); + this.runNode(); } }); }, 20000); @@ -123,6 +111,78 @@ class RegisterNode { }); } + setConfig() { + return new Promise(async (resolve, reject) => { + const env = envfile.parseFileSync('.env'); + if (!env.NODE_WALLET) { + const { wallet, pk } = await this.generateWallet(); + env.NODE_WALLET = wallet; + env.NODE_PRIVATE_KEY = pk; + } + + if (process.env.INSTALLATION === 'local') { + env.NODE_IP = '127.0.0.1'; + } else { + env.NODE_IP = await this.getExternalIp(); + } + + env.DB_PASSWORD = 'root'; + env.BOOTSTRAP_NODE = 'http://l7j34pimur6qllxr2uyhuujpsmx4ga4olve5em4igbjnmfokllj4bead.onion:443/#694085c1f0379dad80b917ab747ed80cd2c2ed04,http://bev4uwc77b7ag66pkwijry5hfgxmpnehiw63mhgjv4qquxedsnrxoeid.onion:443/#a3405151e3adaff757e3bef2e928143e2b3d3f97'; + + for (const prop in env) { + if (Object.prototype.hasOwnProperty.call(env, prop)) { + process.env[prop] = env[prop]; + } + } + + const envF = envfile.stringifySync(env); + console.log(envF); + + fs.writeFile('.env', envF, (err) => { + if (fs.existsSync('modules/Database/system.db')) { + if (process.env.UPDATE !== undefined) { + umzug_seeders.down({ to: 0 }).then((migrations) => { + Models.sequelize.query('delete from sqlite_sequence where name=\'node_config\';'); + Models.sequelize.query('delete from sqlite_sequence where name=\'blockchain_data\';'); + Models.sequelize.query('delete from sqlite_sequence where name=\'graph_database\';'); + umzug_seeders.up().then((migrations) => { + console.log('Configuration loaded...'); + resolve({ + ip: env.NODE_IP, + wallet: env.NODE_WALLET, + }); + }); + }); + } else { + console.log('Configuration not changed...'); + resolve({ + ip: env.NODE_IP, + wallet: env.NODE_WALLET, + }); + } + } else { + umzug_migrations.up().then((migrations) => { + umzug_seeders.up().then((migrations) => { + console.log('Configuration loaded...'); + resolve({ + ip: env.NODE_IP, + wallet: env.NODE_WALLET, + }); + }); + }); + } + }); + }); + } + + runNode() { + const nodeIp = process.env.NODE_IP; + const wallet = process.env.NODE_WALLET; + this.socketSend(wallet, nodeIp); + // eslint-disable-next-line + require('../ot-node'); + } + getExternalIp() { return new Promise((resolve, reject) => { externalip((err, ip) => { diff --git a/testnet/start.sh b/testnet/start.sh new file mode 100644 index 0000000000..ce948e88c9 --- /dev/null +++ b/testnet/start.sh @@ -0,0 +1,7 @@ +#!/usr/bin/env bash +cd / +wget https://raw.githubusercontent.com/origintrail/ot-node/develop/testnet/register-node.js -q +rm /ot-node/testnet/register-node.js +mv /register-node.js /ot-node/testnet/register-node.js +cd /ot-node +/usr/bin/supervisord \ No newline at end of file diff --git a/testnet/supervisord.conf b/testnet/supervisord.conf index a6740b5761..347b6a94af 100644 --- a/testnet/supervisord.conf +++ b/testnet/supervisord.conf @@ -14,3 +14,8 @@ command=arangod stdout_logfile=/dev/null stdout_logfile_maxbytes=0 +[program:remote_syslog] +command=remote_syslog -D +stdout_logfile=/dev/null +stdout_logfile_maxbytes=0 +