-
Notifications
You must be signed in to change notification settings - Fork 60
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
mardizzone/pos-1040: dev: add: stop/start EC2 VMs using terraform (#133)
* dev: add: pos-1040 feature to remotely start/stop aws ec2 instances using express-cli * dev: add: pos-1040 only restart services in non-dockerized envs * dev: add: pos-1040 README * dev: chg: pos-1040 formatting * dev: add: support for archive nodes on new changes * dev: chg: prettier fix
- Loading branch information
1 parent
bd6bc39
commit 69bfeda
Showing
7 changed files
with
131 additions
and
5 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,47 @@ | ||
// noinspection JSUnresolvedFunction | ||
|
||
import { loadDevnetConfig } from '../common/config-utils' | ||
import { restartAll } from './restart' | ||
import { maxRetries, runSshCommand } from '../common/remote-worker' | ||
|
||
const shell = require('shelljs') | ||
|
||
const timer = (ms) => new Promise((resolve) => setTimeout(resolve, ms)) | ||
|
||
async function startGanache(doc) { | ||
const ip = `${doc.ethHostUser}@${doc.devnetBorHosts[0]}` | ||
console.log('📍Running ganache in machine ' + ip + ' ...') | ||
const command = 'sudo systemctl start ganache.service' | ||
await runSshCommand(ip, command, maxRetries) | ||
} | ||
|
||
export async function startInstances() { | ||
console.log('📍Starting instances...') | ||
require('dotenv').config({ path: `${process.cwd()}/.env` }) | ||
const devnetType = | ||
process.env.TF_VAR_DOCKERIZED === 'yes' ? 'docker' : 'remote' | ||
const doc = await loadDevnetConfig(devnetType) | ||
const instances = doc.instancesIds.toString().replace(/,/g, ' ') | ||
|
||
shell.exec(`aws ec2 start-instances --instance-ids ${instances}`) | ||
if (shell.error() !== null) { | ||
console.log( | ||
`📍Starting instances ${doc.instancesIds.toString()} didn't work. Please check AWS manually` | ||
) | ||
} else { | ||
console.log(`📍Instances ${doc.instancesIds.toString()} are starting...`) | ||
} | ||
|
||
if (devnetType === 'remote') { | ||
console.log('📍Waiting 30s before restarting all services...') | ||
await timer(30000) | ||
await startGanache(doc) | ||
await restartAll(true) | ||
} else { | ||
console.log('📍Waiting 20s to ensure instances are started...') | ||
await timer(20000) | ||
console.log( | ||
'📍You can now ssh into the machine and restart the dockerized services...' | ||
) | ||
} | ||
} |
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,27 @@ | ||
// noinspection JSUnresolvedFunction | ||
|
||
import { loadDevnetConfig } from '../common/config-utils' | ||
|
||
const shell = require('shelljs') | ||
|
||
const timer = (ms) => new Promise((resolve) => setTimeout(resolve, ms)) | ||
|
||
export async function stopInstances() { | ||
console.log('📍Stopping instances...') | ||
require('dotenv').config({ path: `${process.cwd()}/.env` }) | ||
const devnetType = | ||
process.env.TF_VAR_DOCKERIZED === 'yes' ? 'docker' : 'remote' | ||
const doc = await loadDevnetConfig(devnetType) | ||
const instances = doc.instancesIds.toString().replace(/,/g, ' ') | ||
|
||
shell.exec(`aws ec2 stop-instances --instance-ids ${instances}`) | ||
if (shell.error() !== null) { | ||
console.log( | ||
`📍Stopping instances ${doc.instancesIds.toString()} didn't work. Please check AWS manually` | ||
) | ||
} else { | ||
console.log('📍Waiting 20s to ensure instances are stopped...') | ||
await timer(20000) | ||
console.log(`📍Instances ${doc.instancesIds.toString()} are stopping...`) | ||
} | ||
} |
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