Skip to content
This repository was archived by the owner on Mar 6, 2022. It is now read-only.

#198 Option to delay shutdown if there are active SSH sessions #199

Merged
merged 1 commit into from
Feb 7, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 28 additions & 23 deletions cmd/deploy.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ var (
coreConfigRepo, customConfigRepo string
coreConfigRepoBranch, customConfigRepoBranch string
outputDir string
instanceDebugDelayTermination bool
// TODO: apv workaround - remove once alternative is built
apvRemote, apvBranch, apvRevision string
)
Expand Down Expand Up @@ -113,6 +114,9 @@ func deployInit() {

flags.BoolVar(&dryRun, "dry-run", false, "only generate the output files, but do not deploy with terraform.")

flags.BoolVar(&instanceDebugDelayTermination, "instance-debug-delay-termination", false, "delay instance shutdown/termination if there are active SSH sessions")
_ = viper.BindPFlag("instance-debug-delay-termination", flags.Lookup("instance-debug-delay-termination"))

// TODO: apv workaround - remove once alternative is built
flags.StringVar(&apvRemote, "apv-remote", "", "remote that contains android-prepare-vendor repo (e.g. https://github.com/example/)")
_ = viper.BindPFlag("apv-remote", flags.Lookup("apv-remote"))
Expand Down Expand Up @@ -228,29 +232,30 @@ var deployCmd = &cobra.Command{
log.Infof("all generated files will be placed in %v", configuredOutputDir)

templateConfig := &templates.Config{
Version: stackVersion,
Name: viper.GetString("name"),
Region: viper.GetString("region"),
Device: viper.GetString("device"),
DeviceDetails: supportedDevices.GetDeviceDetails(viper.GetString("device")),
Email: viper.GetString("email"),
InstanceType: viper.GetString("instance-type"),
InstanceRegions: viper.GetString("instance-regions"),
SkipPrice: viper.GetString("skip-price"),
MaxPrice: viper.GetString("max-price"),
SSHKey: viper.GetString("ssh-key"),
Schedule: viper.GetString("schedule"),
ChromiumBuildDisabled: viper.GetBool("chromium-build-disabled"),
ChromiumVersion: viper.GetString("chromium-version"),
CoreConfigRepo: viper.GetString("core-config-repo"),
CoreConfigRepoBranch: viper.GetString("core-config-repo-branch"),
CustomConfigRepo: viper.GetString("custom-config-repo"),
CustomConfigRepoBranch: viper.GetString("custom-config-repo-branch"),
ReleasesURL: viper.GetString("releases-url"),
Cloud: viper.GetString("cloud"),
ApvRemote: viper.GetString("apv-remote"),
ApvBranch: viper.GetString("apv-branch"),
ApvRevision: viper.GetString("apv-revision"),
Version: stackVersion,
Name: viper.GetString("name"),
Region: viper.GetString("region"),
Device: viper.GetString("device"),
DeviceDetails: supportedDevices.GetDeviceDetails(viper.GetString("device")),
Email: viper.GetString("email"),
InstanceType: viper.GetString("instance-type"),
InstanceRegions: viper.GetString("instance-regions"),
SkipPrice: viper.GetString("skip-price"),
MaxPrice: viper.GetString("max-price"),
SSHKey: viper.GetString("ssh-key"),
Schedule: viper.GetString("schedule"),
ChromiumBuildDisabled: viper.GetBool("chromium-build-disabled"),
ChromiumVersion: viper.GetString("chromium-version"),
CoreConfigRepo: viper.GetString("core-config-repo"),
CoreConfigRepoBranch: viper.GetString("core-config-repo-branch"),
CustomConfigRepo: viper.GetString("custom-config-repo"),
CustomConfigRepoBranch: viper.GetString("custom-config-repo-branch"),
ReleasesURL: viper.GetString("releases-url"),
Cloud: viper.GetString("cloud"),
InstanceDebugDelayTermination: viper.GetBool("instance-debug-delay-termination"),
ApvRemote: viper.GetString("apv-remote"),
ApvBranch: viper.GetString("apv-branch"),
ApvRevision: viper.GetString("apv-revision"),
}

templateRenderer, err := templates.New(templateConfig, templatesFiles, configuredOutputDir)
Expand Down
2 changes: 2 additions & 0 deletions internal/templates/templates.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,8 @@ type Config struct {
ReleasesURL string
// Cloud specifies which cloud to build on (only aws supported right now)
Cloud string
// Delay instance shutdown/termination if there are active SSH sessions
InstanceDebugDelayTermination bool
// TODO: apv workaround - remove once alternative is built
// ApvRemote is the git remote that contains an android-prepare-vendor repo
ApvRemote string
Expand Down
7 changes: 6 additions & 1 deletion templates/generated_vars_and_funcs.sh
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,11 @@ cleanup() {
if [ $rv -ne 0 ]; then
notify "RattlesnakeOS Build FAILED" 1
fi
<% if .InstanceDebugDelayTermination -%>
while pgrep -u ubuntu sshd > /dev/null 2>&1; do
sleep 300
done
<%- end %>
sudo shutdown -h now
<%- else %>
echo "todo"
Expand Down Expand Up @@ -142,4 +147,4 @@ delete_build_artifact() {
<%- else %>
echo "todo"
<%- end %>
}
}