Developing on AWS or GCE

jseldess edited this page Jul 22, 2016 · 4 revisions

When running benchmarks or resource intensive stress tests, it can be helpful to run on a GCE or AWS instance -- trying to do anything else (even just web browsing) can be difficult, plus laptops have highly variable performance (both due to running other things and hardware doing thermal/power management) making their timings unreliable.

Auto-shutdown when not in use

Since usage is billed by the hour, automatically shutting down when not in use saves $. A cron job can check if you are logged in and start a shutdown if not. Waiting 10mins prevents shutting down before you get a chance to login or if you briefly disconnect, and checking if /.active exists allows easily disabling this temporarily when you want to leave something running unattended.

  1. Put the following in /root/idle.sh:

    #!/bin/bash
    
    who=david
    
    # bail if I'm logged in or I've signaled I want to stay running.
    if w | grep -q $who || [[ -f /.active ]]; then exit; fi
    
    echo "shutdown in 10 min" | wall
    sleep 600
    
    if w | grep -q $who || [[ -f /.active ]]; then exit; fi
    
    /sbin/shutdown -h now
  2. Make it executable: chmod +x /root/idle.sh

  3. Edit root's cron with sudo crontab -e to add:

    * * * * * /root/idle.sh 2>&1 >> /root/idle.log
    
  4. Add sudo rm /.active to your ~/.bashrc (or whatever) to clear the .active file on next login.

You can’t perform that action at this time.
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.
Press h to open a hovercard with more details.