From 2f43dd097072617a995906f8367cd38300dcc26f Mon Sep 17 00:00:00 2001 From: Chalith Desaman Date: Tue, 22 Nov 2022 10:35:56 +0530 Subject: [PATCH] Restart the deployment cluster when machine restarts (#20) --- docker/scripts/cluster.sh | 2 +- npm/lib/common.js | 7 +++++-- npm/package-lock.json | 4 ++-- npm/package.json | 2 +- 4 files changed, 9 insertions(+), 6 deletions(-) diff --git a/docker/scripts/cluster.sh b/docker/scripts/cluster.sh index 6115214..eeab654 100644 --- a/docker/scripts/cluster.sh +++ b/docker/scripts/cluster.sh @@ -86,7 +86,7 @@ function create_instance { # Create container for hotpocket instance. local container_name="${container_prefix}_$node" docker container create --name $container_name --privileged \ - -p $user_port:$user_port --network $network --network-alias node$node \ + -p $user_port:$user_port --network $network --network-alias node$node --restart unless-stopped \ --mount type=volume,src=$volume,dst=$volume_mount $hotpocket_image run $(contract_dir_mount_path $node) } diff --git a/npm/lib/common.js b/npm/lib/common.js index 0729608..7e4bf6e 100644 --- a/npm/lib/common.js +++ b/npm/lib/common.js @@ -20,7 +20,7 @@ const CONSTANTS = { prerequisiteInstaller: "install.sh" }; -function runOnContainer(name, detached, autoRemove, mountStock, mountVolume, entryCmd, entryPoint, interactive = true) { +function runOnContainer(name, detached, autoRemove, mountStock, mountVolume, entryCmd, entryPoint, interactive = true, restart = null) { command = `docker run`; if (interactive) @@ -46,6 +46,9 @@ function runOnContainer(name, detached, autoRemove, mountStock, mountVolume, ent else command += " --entrypoint /bin/bash"; + if (restart) + command += ` --restart ${restart}`; + command += ` -e CLUSTER=${appenv.cluster} -e CLUSTER_SIZE=${appenv.clusterSize} -e DEFAULT_NODE=${appenv.defaultNode} -e VOLUME=${CONSTANTS.volume} -e NETWORK=${CONSTANTS.network}`; command += ` -e CONTAINER_PREFIX=${CONSTANTS.containerPrefix} -e VOLUME_MOUNT=${CONSTANTS.volumeMount} -e BUNDLE_MOUNT=${CONSTANTS.bundleMount} -e HOTPOCKET_IMAGE=${appenv.instanceImage}`; command += ` -e CONFIG_OVERRIDES_FILE=${CONSTANTS.confOverrideFile} -e CODEGEN_OUTPUT=${CONSTANTS.codegenOutputDir}`; @@ -89,7 +92,7 @@ function initializeDeploymentCluster() { runOnContainer(CONSTANTS.deploymentContainerName, null, true, true, null, 'cluster stop ; cluster create', null); // Spin up management container. - runOnContainer(CONSTANTS.deploymentContainerName, true, false, true, true, null, null); + runOnContainer(CONSTANTS.deploymentContainerName, true, false, true, true, null, null, true, 'unless-stopped'); // Bind the instance mesh network config together. executeOnContainer(CONSTANTS.deploymentContainerName, 'cluster bindmesh'); diff --git a/npm/package-lock.json b/npm/package-lock.json index b1e757b..021dcd7 100644 --- a/npm/package-lock.json +++ b/npm/package-lock.json @@ -1,12 +1,12 @@ { "name": "hpdevkit", - "version": "0.5.5", + "version": "0.5.6", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "hpdevkit", - "version": "0.5.5", + "version": "0.5.6", "hasInstallScript": true, "license": "MIT", "dependencies": { diff --git a/npm/package.json b/npm/package.json index fa3f6c5..f6f714a 100644 --- a/npm/package.json +++ b/npm/package.json @@ -1,6 +1,6 @@ { "name": "hpdevkit", - "version": "0.5.5", + "version": "0.5.6", "description": "Developer toolkit for HotPocket smart contract development", "scripts": { "install": "node scripts/install.js"