Turn Off The Lights

After upgrading to macOS Sierra, and having Apex fail to work locally anymore, I decided it was time to build a dev instance, on EBS within EC2. I found a good idea from CloudSSH, but I really wanted to allow my instance to run docker commands while I was away. I decided to add the "--no-stop" flag to CloudSSH and just handle terminating the instances myself using a cronscript.


Here's the script:

#!/bin/sh
# Don't even bother checking if we haven't been up for more than
# 3500 seconds (just under 1 hour)
UPTIME=`cat /proc/uptime|awk '{printf "%i", $1}'`
if [ "$UPTIME" -gt "3500" ]
then
  if [ -z "$(who)" ]
  then
    if [ -z "$(docker ps -q)" ]
    then
      shutdown -P now
    fi
  fi

fi

And here's the /etc/cron.d/turn-off-the-lights file:

*/5 * * * * root /usr/local/bin/turn-off-the-lights


I also set up a nice little bash function to handle automatically configuring most of the common things I did for CloudSSH. I did this instead of an alias because I have multiple AWS profiles that I connect to:

# Connect to a "Cloud Environment"
typeset -A CLOUD_INSTANCE_ID
CLOUD_INSTANCE_ID+=(aci i-MY-DEV-INSTANCE)
CLOUD_INSTANCE_ID+=(newstex i-OTHER-DEV-INSTANCE)
cloud(){
  export AWS_REGION=us-east-1
  export AWS_PROFILE=$1
  $HOME/bin/cloudssh --no-stop ec2-user@${CLOUD_INSTANCE_ID[$1]}.us-east-1 -- -i ~/.ssh/$1-cmoyer.pem -o HostKeyAlias=${CLOUD_INSTANCE_ID[$1]}
}
cloud_profiles=(aci newstex)
compctl -k cloud_profiles cloud


Now I can just type "cloud aci" and automatically get logged into my ACI dev instance. Note that using "HostKeyAlias" allows me to not have to re-verify the host key every time the IP address changes.

Comments

There is also our famous QA team, checking on zipjob review every essay and paper written by our writers before sending the final draft over to a customer.
unknown said…
Before the writer, I was the best developer but recently I changed our field for some issues. When the last week also took law writing service from the best law essay writing services Manchester the reason is that I'm not a professional in the law writing.
hastenchemical said…
Taking inspiration from CloudSSH and customizing it with the "--no-stop" flag demonstrates resourcefulness in allowing for uninterrupted usage of Docker commands. Similarly, Refrigerated Courier Services – Texas provide customized and reliable transportation solutions for temperature-sensitive goods, adapting to specific needs and ensuring seamless delivery across different locations and timeframes.
Steven Paul said…
It's impressive that you were able to adjust to macOS Sierra's new features and find a workaround for your development instance on EBS within EC2. Instance termination is handled by a cron script, and the addition of the "--no-stop" argument to CloudSSH demonstrates your proactive nature. The Fast X Jason Statham Beige Jacket is a great addition to your wardrobe if you're looking to step up your fashion game.