-
Notifications
You must be signed in to change notification settings - Fork 3.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
chore: Remove shelljs
from more appsmithctl
commands
#37383
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,66 +1,49 @@ | ||
// Init function export mongodb | ||
const shell = require('shelljs'); | ||
const fsPromises = require("fs/promises"); | ||
const Constants = require('./constants'); | ||
const utils = require('./utils'); | ||
|
||
function export_database() { | ||
async function exportDatabase() { | ||
console.log('export_database ....'); | ||
dbUrl = utils.getDburl(); | ||
shell.mkdir('-p', [Constants.BACKUP_PATH]); | ||
const cmd = `mongodump --uri='${dbUrl}' --archive='${Constants.BACKUP_PATH}/${Constants.DUMP_FILE_NAME}' --gzip`; | ||
shell.exec(cmd); | ||
const dbUrl = utils.getDburl(); | ||
await fsPromises.mkdir(Constants.BACKUP_PATH, { recursive: true }); | ||
await utils.execCommand([ | ||
"mongodump", | ||
"--uri=" + dbUrl, | ||
`--archive=${Constants.BACKUP_PATH}/${Constants.DUMP_FILE_NAME}`, | ||
"--gzip", | ||
]) | ||
console.log('export_database done'); | ||
} | ||
|
||
function stop_application() { | ||
console.log('stop_application ....'); | ||
shell.exec('/usr/bin/supervisorctl stop backend rts'); | ||
console.log('stop_application done'); | ||
} | ||
async function run() { | ||
let errorCode = 0; | ||
|
||
function start_application() { | ||
console.log('start_application ....'); | ||
shell.exec('/usr/bin/supervisorctl start backend rts'); | ||
console.log('start_application done'); | ||
} | ||
await utils.ensureSupervisorIsRunning(); | ||
|
||
// Main application workflow | ||
function run() { | ||
let errorCode = 0; | ||
try { | ||
check_supervisord_status_cmd = '/usr/bin/supervisorctl >/dev/null 2>&1 '; | ||
shell.exec(check_supervisord_status_cmd, function (code) { | ||
if (code > 0) { | ||
shell.echo('application is not running, starting supervisord'); | ||
shell.exec('/usr/bin/supervisord'); | ||
} | ||
}); | ||
|
||
shell.echo('stop backend & rts application before export database'); | ||
stop_application(); | ||
export_database(); | ||
shell.echo('start backend & rts application after export database'); | ||
shell.echo(); | ||
shell.echo('\033[0;33m++++++++++++++++++++ NOTE ++++++++++++++++++++'); | ||
shell.echo(); | ||
shell.echo( | ||
console.log('stop backend & rts application before export database'); | ||
await utils.stop(["backend", "rts"]); | ||
await exportDatabase(); | ||
console.log('start backend & rts application after export database'); | ||
console.log(); | ||
console.log('\033[0;33m++++++++++++++++++++ NOTE ++++++++++++++++++++'); | ||
console.log(); | ||
console.log( | ||
'Please remember to also copy APPSMITH_ENCRYPTION_SALT and APPSMITH_ENCRYPTION_PASSWORD variables from the docker.env file to the target instance where you intend to import this database dump.', | ||
); | ||
shell.echo(); | ||
shell.echo('++++++++++++++++++++++++++++++++++++++++++++++\033[0m'); | ||
shell.echo(); | ||
console.log(); | ||
console.log('++++++++++++++++++++++++++++++++++++++++++++++\033[0m'); | ||
console.log(); | ||
} catch (err) { | ||
shell.echo(err); | ||
console.log(err); | ||
errorCode = 1; | ||
} finally { | ||
start_application(); | ||
await utils.start(["backend", "rts"]); | ||
process.exit(errorCode); | ||
} | ||
} | ||
|
||
module.exports = { | ||
run, | ||
exportDatabase: export_database, | ||
stopApplication: stop_application, | ||
startApplication: start_application, | ||
}; | ||
exportDatabase, | ||
}; |
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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🛠️ Refactor suggestion
Improve error handling in finally block
The error handling and application restart logic could be more robust.
📝 Committable suggestion