Skip to content

Commit

Permalink
Docs and tweaks
Browse files Browse the repository at this point in the history
  • Loading branch information
begriffs committed Apr 22, 2015
1 parent 2ee3443 commit 6e14e4a
Show file tree
Hide file tree
Showing 3 changed files with 68 additions and 33 deletions.
39 changes: 39 additions & 0 deletions README.md
@@ -0,0 +1,39 @@
### Capture Full Log of Route 27 at Powell

Deploys an EC2 box that checks each minute the position, speed,
orientation and predicted arrival of route 27. This bus has messed
with me one too many times and now it's time to get even.

1. Sign up for Amazon Web Services free tier [here](http://aws.amazon.com/free/).
It is **extremely important** to ensure the region in your
Amazon Web Console is set to "N. California" as the defaults
are all configured to use this region in future steps. If you decide
to use a different region you will need to specify the region in future
steps when noted.

2. Create Amazon IAM credentials for deployment.
Assuming you are signed into the AWS console, visit the [user
admin](https://console.aws.amazon.com/iam/home#users) page. Create
a new user and note their security credentials (ID and secret key).
Then attach a user policy of "Power User" to the newly created user.

3. [Create EC2 keypair](https://console.aws.amazon.com/ec2/v2/home?region=us-west-1#KeyPairs:sort=keyName).

4. Clone this repo including its chef recipe submodules.
```bash
git clone --recursive https://github.com/begriffs/microservice-template.git
```

5. Install <a href="https://www.packer.io/" target="_blank">Packer</a>.
On a Mac you can use homebrew:
```bash
brew tap homebrew/binary
brew install packer
```
6. Build the AMI
```bash
packer build -var 'aws_access_key=xxx' -var 'aws_secret_key=xxx' stalker.json
```

7. Launch the AMI from the Amazon Web Console. Then go watch the
files accumulate on your S3 bucket.
6 changes: 2 additions & 4 deletions sources/savepoint.sh
@@ -1,9 +1,7 @@
export WHEN=`date +%s`
curl "http://webservices.nextbus.com/service/publicXMLFeed?command=predictions&a=sf-muni&r=27&s=3813" > r27-p-3813-${WHEN}.xml
curl "http://webservices.nextbus.com/service/publicXMLFeed?command=predictions&a=sf-muni&r=27&s=3612" > r27-p-3612-${WHEN}.xml
curl "http://webservices.nextbus.com/service/publicXMLFeed?command=vehicleLocations&a=sf-muni&r=27&t=0" > r27-l-${WHEN}.xml
curl -i "http://webservices.nextbus.com/service/publicXMLFeed?command=predictions&a=sf-muni&r=27&s=3612" > r27-p-3612-${WHEN}.xml
curl -i "http://webservices.nextbus.com/service/publicXMLFeed?command=vehicleLocations&a=sf-muni&r=27&t=0" > r27-l-${WHEN}.xml

aws s3 cp r27-p-3813-${WHEN}.xml s3://route-27-history/r27-p-3813-${WHEN}.xml
aws s3 cp r27-p-3612-${WHEN}.xml s3://route-27-history/r27-p-3612-${WHEN}.xml
aws s3 cp r27-l-${WHEN}.xml s3://route-27-history/r27-l-${WHEN}.xml

Expand Down
56 changes: 27 additions & 29 deletions stalker.json
@@ -1,9 +1,7 @@
{
"variables": {
"aws_access_key": "",
"aws_secret_key": "",
"broker_id": "",
"base_ami": ""
"aws_secret_key": ""
},
"builders": [{
"type": "amazon-ebs",
Expand All @@ -13,36 +11,36 @@
"source_ami": "ami-4b6f650e",
"instance_type": "t2.micro",
"ssh_username": "ec2-user",
"ami_name": "Bus Stalker {{timestamp}}",
"ami_groups": ["all"]
"ami_name": "Bus Stalker {{timestamp}}"
}],
"provisioners": [{
"type": "file",
"source": "sources/savepoint.sh",
"destination": "/home/ec2-user/savepoint.sh"
}, {
"type": "chef-solo",
"cookbook_paths": ["cookbooks"],
"run_list": [
"recipe[awscli]"
],
"json": {
"awscli": {
"config_profiles": {
"default" : {
"region" : "us-west-1",
"aws_access_key_id" : "{{user `aws_access_key`}}",
"aws_secret_access_key" : "{{user `aws_secret_key`}}",
"user" : "ec2-user"
"type": "file",
"source": "sources/savepoint.sh",
"destination": "/home/ec2-user/savepoint.sh"
}, {
"type": "chef-solo",
"cookbook_paths": ["cookbooks"],
"run_list": [
"recipe[awscli]"
],
"json": {
"awscli": {
"config_profiles": {
"default" : {
"region" : "us-west-1",
"aws_access_key_id" : "{{user `aws_access_key`}}",
"aws_secret_access_key" : "{{user `aws_secret_key`}}",
"user" : "ec2-user"
}
}
}
}
}, {
"type": "shell",
"inline": [
"chmod a+x /home/ec2-user/savepoint.sh",
"sudo sh -c 'echo \"* * * * * ec2-user /home/ec2-user/savepoint.sh\" > /etc/crontab'"
]
}
}, {
"type": "shell",
"inline": [
"chmod a+x /home/ec2-user/savepoint.sh",
"sudo sh -c 'echo \"* * * * * ec2-user /home/ec2-user/savepoint.sh\" > /etc/crontab'"
]
}]
]
}

0 comments on commit 6e14e4a

Please sign in to comment.