-
Notifications
You must be signed in to change notification settings - Fork 75
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
69cba8c
commit d9d7fd4
Showing
16 changed files
with
430 additions
and
58 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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*' | ||
] | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.