-
Notifications
You must be signed in to change notification settings - Fork 0
/
packer-graphite.json
134 lines (129 loc) · 7.87 KB
/
packer-graphite.json
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
/*
This is my source version of the packer-graphite build. It contains
comments which are stripped out of the file before it's fed to the
Packer.io build process. There should also be an graphite.json file
in this directory. That file is the same as this one, sans comments.
If you want to run the build, but don't have the strip-json-comments
program installed, you should build it using the graphite.json file.
Author: Kevin S. Clarke <[email protected]>
*/
{
/* These variables should be defined in the vars.json file */
"variables": {
"graphite_version": "0.9.10",
/* Below are variables supplied by your vars.json file */
"aws_access_key": "{{env `AWS_ACCESS_KEY`}}",
"aws_secret_key": "{{env `AWS_SECRET_KEY`}}",
"aws_security_group_id": "{{env `AWS_SECURITY_GROUP_ID`}}",
"aws_region": "{{env `AWS_REGION`}}",
"aws_instance_type": "{{env `AWS_INSTANCE_TYPE`}}",
"aws_source_ami": "{{env `AWS_SOURCE_AMI`}}",
"aws_virtualization_type": "{{env `AWS_VIRTUALIZATION_TYPE`}}",
"server_admin_email": "{{env `PACKER_GRAPHITE_EMAIL`}}",
"packer_build_name": "{{env `PACKER_GRAPHITE_BUILD_NAME`}}",
/* These passwords will be autogenerated if left empty */
"graphite_admin_password": "",
"graphite_secret_key_password": ""
},
"builders": [{
"type": "amazon-ebs",
"access_key": "{{user `aws_access_key`}}",
"secret_key": "{{user `aws_secret_key`}}",
/* Below should be the actual ID, not the group name */
"security_group_id": "{{user `aws_security_group_id`}}",
"region": "{{user `aws_region`}}",
"associate_public_ip_address": "true",
/* Make sure the next three values are compatible */
"source_ami": "{{user `aws_source_ami`}}",
"instance_type": "{{user `aws_instance_type`}}",
"ami_virtualization_type": "{{user `aws_virtualization_type`}}",
"ssh_username": "ubuntu",
"ami_name": "{{user `packer_build_name`}}-graphite-{{timestamp}}",
"ami_description": "A Graphite deployment built with Packer.io",
"tags": {
"OS_Version": "Ubuntu",
"Release": "Graphite {{user `graphite_version`}}"
}
}],
"provisioners": [{
"type": "shell",
"inline": [
"sleep 30",
/* Update all the Ubuntu packages before we begin */
"sudo apt-get update -y --fix-missing",
/* Upgrade any security issues since AMI release */
"sudo unattended-upgrade",
/* Install some generic systems stuff */
"sudo apt-get install -y nano htop nmap",
/* Remove landscape-client but keep landscape-common */
"sudo apt-get remove -y --purge landscape-client",
"sudo rm -f /etc/update-motd.d/51-cloudguest",
/* We're going to hack the landscape login message */
"sudo truncate -s 0 `sudo find /usr/lib -name landscapelink.py`",
"curl -o /tmp/landscapelink.py https://raw.githubusercontent.com/fcrepo4-labs/fcrepo4-packer-graphite/master/scripts/landscape-hack",
"sudo mv /tmp/landscapelink.py `sudo find /usr/lib -name landscapelink.py`",
/* Install Apache and other necessary dependencies */
"sudo apt-get install -y apache2-mpm-prefork libapache2-mod-wsgi python-cairo python2.7 python-django python-django-tagging",
"sudo apt-get install -y python-memcache python-ldap python-txamqp python-setuptools python-rrdtool python-pip python-simplejson",
/* Install Graphite from pip */
"sudo pip install https://github.com/graphite-project/ceres/tarball/master",
"sudo pip install whisper",
"sudo pip install carbon",
"sudo pip install graphite-web",
"sudo pip install daemonize",
/* Copy over the Graphite config files */
"cd /opt/graphite",
"sudo chown -R ubuntu:ubuntu *",
"cd /opt/graphite/conf",
"cp carbon.conf.example carbon.conf",
"cp storage-schemas.conf.example storage-schemas.conf",
"cp graphite.wsgi.example graphite.wsgi",
"cd /opt/graphite/webapp/graphite",
"cp local_settings.py.example local_settings.py",
/* Extend the data retention period to more than the default of one day */
/* "/opt/graphite/conf/storage-schemas.conf", */
/* The next step is to configure Apache like we want it */
"sudo rm /etc/apache2/sites-available/000-default.conf",
"curl https://raw.githubusercontent.com/fcrepo4-labs/fcrepo4-packer-graphite/master/scripts/graphite-apache-config.sh | SERVER_ADMIN_EMAIL=\"{{user `server_admin_email`}}\" bash >/tmp/000-default.conf",
"sudo mv /tmp/000-default.conf /etc/apache2/sites-available/000-default.conf",
/* Put a symlink to the Graphite logs in the expected /var/log location */
"sudo ln -s /opt/graphite/storage/log/webapp /var/log/graphite",
/* Configure local_settings.py to add SECRET_KEY, logging section, and database config */
"printf \"\n\nSECRET_KEY = '{{user `graphite_secret_key_password`}}'\" | sudo tee -a /opt/graphite/webapp/graphite/local_settings.py >/dev/null",
"printf \"\nLOG_RENDERING_PERFORMANCE = True\" | sudo tee -a /opt/graphite/webapp/graphite/local_settings.py >/dev/null",
"printf \"\nLOG_CACHE_PERFORMANCE = True\" | sudo tee -a /opt/graphite/webapp/graphite/local_settings.py >/dev/null",
"printf \"\nLOG_METRIC_ACCESS = True\" | sudo tee -a /opt/graphite/webapp/graphite/local_settings.py >/dev/null",
"printf \"\n\nDATABASES = {\" | sudo tee -a /opt/graphite/webapp/graphite/local_settings.py >/dev/null",
"printf \"\n 'default': {\" | sudo tee -a /opt/graphite/webapp/graphite/local_settings.py >/dev/null",
"printf \"\n 'NAME': '/opt/graphite/storage/graphite.db',\" | sudo tee -a /opt/graphite/webapp/graphite/local_settings.py >/dev/null",
"printf \"\n 'ENGINE': 'django.db.backends.sqlite3',\" | sudo tee -a /opt/graphite/webapp/graphite/local_settings.py >/dev/null",
"printf \"\n 'USER': 'graphiteAdmin',\" | sudo tee -a /opt/graphite/webapp/graphite/local_settings.py >/dev/null",
"printf \"\n 'PASSWORD': '{{user `graphite_admin_password`}}',\" | sudo tee -a /opt/graphite/webapp/graphite/local_settings.py >/dev/null",
"printf \"\n 'HOST': '',\" | sudo tee -a /opt/graphite/webapp/graphite/local_settings.py >/dev/null",
"printf \"\n 'PORT': ''\" | sudo tee -a /opt/graphite/webapp/graphite/local_settings.py >/dev/null",
"printf \"\n }\" | sudo tee -a /opt/graphite/webapp/graphite/local_settings.py >/dev/null",
"printf \"\n}\" | sudo tee -a /opt/graphite/webapp/graphite/local_settings.py >/dev/null",
/* Create the Graphite database and the super user account */
"cd /opt/graphite/webapp/graphite",
"sudo python manage.py syncdb --noinput",
"echo \"from django.contrib.auth.models import User; User.objects.create_superuser('graphiteAdmin', '{{user `server_admin_email`}}', '{{user `graphite_admin_password`}}')\" | sudo python manage.py shell",
/* Make Graphite's storage directory writeable by the Web server */
"cd /opt/graphite/storage",
"sudo chown -R www-data:www-data .",
/* Fix some incompatibilities between django 1.6 and graphite 0.9.10 */
"sudo sed -i -e 's/from twisted.scripts._twistd_unix import daemonize/import daemonize/' /opt/graphite/lib/carbon/util.py",
"find /opt/graphite/webapp/graphite -type f -print0 | xargs -0 sudo sed -i 's/from django.conf.urls.defaults import/from django.conf.urls import/'",
/* Start the data collector */
"cd /opt/graphite/bin/",
"sudo -u www-data python carbon-cache.py start",
/* Restart Apache */
"sudo service apache2 restart",
/* Create the init.d script for the data collector */
"curl -o /tmp/carbon-cache https://raw.githubusercontent.com/fcrepo4-labs/fcrepo4-packer-graphite/master/scripts/carbon-cache-initd",
"sudo mv /tmp/carbon-cache /etc/init.d/carbon-cache",
"sudo chown root:root /etc/init.d/carbon-cache",
"sudo chmod 755 /etc/init.d/carbon-cache",
"sudo update-rc.d carbon-cache defaults"
]
}]
}