-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathatom.xml
More file actions
508 lines (388 loc) · 36.5 KB
/
atom.xml
File metadata and controls
508 lines (388 loc) · 36.5 KB
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
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
<title><![CDATA[Lucas' Thoughts]]></title>
<link href="http://www.eagleton.org/atom.xml" rel="self"/>
<link href="http://www.eagleton.org/"/>
<updated>2013-06-16T11:43:11+10:00</updated>
<id>http://www.eagleton.org/</id>
<author>
<name><![CDATA[MuzzleFork]]></name>
</author>
<generator uri="http://octopress.org/">Octopress</generator>
<entry>
<title type="html"><![CDATA[Using SSH tunnels as a proxy]]></title>
<link href="http://www.eagleton.org/2013/06/using-ssh-tunnels-as-a-proxy/"/>
<updated>2013-06-16T10:16:00+10:00</updated>
<id>http://www.eagleton.org/2013/06/using-ssh-tunnels-as-a-proxy</id>
<content type="html"><![CDATA[<p>In my day job, our application is hosted in Amazon’s AWS service using an autoscaled cluster and their RDS service for MySQL (among many other aspects of their environment). In this configuration the web servers boot up and shut down in order to respond to the current load of our users. This is great and all, but means that their IP addresses are always changing.</p>
<p>Our RDS is configured such that only the machines in our autoscaling group are allowed to access it. This is also great, but it means that if I want to look into something in the production database, I need to SSH to one of the web servers (after working out its IP address) and <em>then</em> connect to RDS.</p>
<p>This can be so much easier.<!-- More --></p>
<p>SSH tunnels sounded like the easy option here, but by default, that lets you access services on a remote machine. In this setup, we want to access services not <em>on</em> a machine, but <em>via</em> that machine. We also don’t really care to keep that terminal session open.</p>
<figure class='code'><figcaption><span></span></figcaption><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
</pre></td><td class='code'><pre><code class='bash'><span class='line'>ssh -i <keyfile> -o <span class="nv">StrictHostKeyChecking</span><span class="o">=</span>no -f -L <your <span class="nb">local </span>port>:<proxied-to-host>:<proxied-to-port> <proxy-user>@<proxy-host> -N &
</span></code></pre></td></tr></table></div></figure>
<p>Explanation of each of the parts of that command:</p>
<ul>
<li><code>-i <keyfile></code> Include this if your default key isn’t the one that can access your proxy (<proxy-user>@<proxy-host>).</li>
<li><code>-o StrictHostKeyChecking=no</code> This is useful when you’re always connecting to a new host and don’t want to type yes each time it happens to be a new host.</li>
<li><code>-f</code> As per the man page, Requests ssh to go to background just before command execution. This is useful if ssh is going to ask for passwords or passphrases, but the user wants it in the background.</li>
<li><code>-L</code> This is what sets up the proxy instead of just getting you to the remote host.</li>
<li><code><your local port></code> As per normal tunnels, you need to specify a local port that you want to access this service on.</li>
<li><code><proxied-to-host></code> This is the host name for the service you want to access via this proxy. In my case, it’s an RDS host.</li>
<li><code><proxied-to-port></code> This is the remote port for the service you want to access via this proxy. In my case, it’s <code>3306</code>.</li>
<li><code><proxy-user></code> This is the username of the account you can normally SSH to. If you’re using standard AWS AMIs, this is likely <code>ec2-user</code>.</li>
<li><code><proxy-host></code> This is the hostname of the account you can SSH to.</li>
<li><code>-N</code> As per the man page, Do not execute a remote command. This is useful for just forwarding ports.</li>
</ul>
<p>This means that the command for me to access my RDS instance locally becomes something like:</p>
<figure class='code'><figcaption><span></span></figcaption><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
</pre></td><td class='code'><pre><code class='bash'><span class='line'>ssh -i ~/.ssh/ec2-ap-southeast-2.pem -o <span class="nv">StrictHostKeyChecking</span><span class="o">=</span>no -f -L 3000:myhostname-southeast-2.rds.amazonaws.com:3306 [email protected] -N &
</span></code></pre></td></tr></table></div></figure>
<p>After running this, I can connect to port 3000 on my local machine which will be routed via my EC2 instance and straight to the RDS instance I have configured, allowing me to use local tools like phpMyAdmin or Sequel Pro etc in order to access the database instead of having to do it all through the shell. (I don’t hate the shell, it can just be easier some times to have a GUI for interacting with the DB).</p>
<p>One thing the above doesn’t solve however is how to get the host name when the host names keep changing due to autoscaling.</p>
<p>Assuming you have the AWS utilities installed, you can do something like the following:</p>
<figure class='code'><figcaption><span></span></figcaption><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
<span class='line-number'>2</span>
<span class='line-number'>3</span>
<span class='line-number'>4</span>
<span class='line-number'>5</span>
</pre></td><td class='code'><pre><code class='bash'><span class='line'><span class="nb">export </span><span class="nv">AWS_ACCESS_KEY</span><span class="o">=</span><span class="s2">"xxxxxxxxx"</span>
</span><span class='line'><span class="nb">export </span><span class="nv">AWS_SECRET_KEY</span><span class="o">=</span><span class="s2">"yyyyyyyyyyyy"</span>
</span><span class='line'><span class="nb">export </span><span class="nv">EC2_HOME</span><span class="o">=</span><span class="s2">"/usr/local/share/aws/ec2-api-tools"</span>
</span><span class='line'><span class="nb">export </span><span class="nv">JAVA_HOME</span><span class="o">=</span>/usr
</span><span class='line'>/usr/local/share/aws/ec2-api-tools/bin/ec2-describe-instances --region ap-southeast-2 --show-empty-fields -H --filter <span class="s2">"tag:Name=<whatever you've named your cluster>"</span> --hide-tags |grep INSTANCE | awk <span class="s1">'{print $4}'</span> |head -n 1
</span></code></pre></td></tr></table></div></figure>
<p>This will give you the first node in your autoscaling cluster.</p>
<p>I’ve combined this into a neat little script for my use which will go discover a valid, current node then establish the tunnel.</p>
<p>The MySQL client is also so good that if the tunnel drops out (eg autoscaling shuts down that node), all you have to do it reestablish the tunnel with another node and you can continue using it.</p>
<p>If you’re using autoscaling and will need to periodically reestablish these tunnels, try adding something like the following to the start of your script:</p>
<figure class='code'><figcaption><span></span></figcaption><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
</pre></td><td class='code'><pre><code class='bash'><span class='line'><span class="nb">kill</span> <span class="sb">`</span>lsof -t -i tcp:3000<span class="sb">`</span>
</span></code></pre></td></tr></table></div></figure>
<p>This kills whatever is running on that port - most likely your dead tunnel.</p>
<p>Good luck, let me know in the comments if it worked for you.</p>
]]></content>
</entry>
<entry>
<title type="html"><![CDATA[Using git's post-receive hooks to deploy code]]></title>
<link href="http://www.eagleton.org/2013/06/using-gits-post-receive-hooks-to-deploy-code/"/>
<updated>2013-06-09T13:24:00+10:00</updated>
<id>http://www.eagleton.org/2013/06/using-gits-post-receive-hooks-to-deploy-code</id>
<content type="html"><![CDATA[<p>I’ve recently started self-hosting some sites on some cheap, cool hosting provided by <a href="https://www.digitalocean.com/?refcode=1d72a90eb581">Digital Ocean</a>. On one of their VPSs, I’ve set up some bare git repositories and made some git hooks to automate deployment of sites to that server.<!-- more --></p>
<p>This information isn’t limited to only working on Digital Ocean, but my walk-through is based on that environment - using their LAMP stack image based on Ubuntu 12.04 using an SSH key (makes life so much easier :))</p>
<p>This setup uses Apache and some virtual hosts to handle each site. The default setup in Ubuntu for apache involves 2 folders - <code>/etc/apache2/sites-available</code> (where you can put a virtual host directive) and <code>/etc/apache2/sites-enabled</code> (where you symlink files from the sites-available folder in order to enable them). Using the <code>sites-available</code>/<code>sites-enabled</code> combo allows you to disable sites without removing them. This functionality isn’t required here since we’re going to use git to version control and getting old versions out of config is easy.</p>
<h2>Set up git repository for the virtual hosts</h2>
<p>I’m using <code>/var/repos</code> for all of my repos. You’re welcome to use any other path you see fit.</p>
<figure class='code'><figcaption><span></span></figcaption><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
<span class='line-number'>2</span>
<span class='line-number'>3</span>
</pre></td><td class='code'><pre><code class='bash'><span class='line'>mkdir -p /var/repos/virtualhosts.git
</span><span class='line'><span class="nb">cd</span> /var/repos/virtualhosts.git
</span><span class='line'>git init --bare
</span></code></pre></td></tr></table></div></figure>
<p>This creates a bare repository (doesn’t include a working folder) ready for use.</p>
<p>While you’re in there, modify the post-receive hook (my favourite editor is vim = <code>vim hooks/post-receive</code>)
Put the following code in there</p>
<figure class='code'><figcaption><span></span></figcaption><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
<span class='line-number'>2</span>
<span class='line-number'>3</span>
<span class='line-number'>4</span>
<span class='line-number'>5</span>
<span class='line-number'>6</span>
<span class='line-number'>7</span>
<span class='line-number'>8</span>
<span class='line-number'>9</span>
<span class='line-number'>10</span>
<span class='line-number'>11</span>
</pre></td><td class='code'><pre><code class='bash'><span class='line'><span class="nv">GIT_WORK_TREE</span><span class="o">=</span>/etc/apache2/sites-available git checkout -f
</span><span class='line'>
</span><span class='line'><span class="c"># a2dissite all files in /etc/apache2/sites-enabled</span>
</span><span class='line'><span class="nb">cd</span> /etc/apache2/sites-enabled
</span><span class='line'><span class="k">for </span>f in * ; <span class="k">do </span>a2dissite <span class="nv">$f</span>; <span class="k">done</span>
</span><span class='line'>
</span><span class='line'><span class="c"># ensite the ones that are present now in /etc/apache2/sites-available</span>
</span><span class='line'><span class="nb">cd</span> /etc/apache2/sites-available
</span><span class='line'><span class="k">for </span>f in * ; <span class="k">do </span>a2ensite <span class="nv">$f</span>; <span class="k">done</span>
</span><span class='line'>
</span><span class='line'>service apache2 reload
</span></code></pre></td></tr></table></div></figure>
<p>Then you’ll have to give it execute permission</p>
<figure class='code'><figcaption><span></span></figcaption><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
</pre></td><td class='code'><pre><code class='bash'><span class='line'>chmod +x hooks/post-receive
</span></code></pre></td></tr></table></div></figure>
<p>This will:</p>
<ol>
<li>Check out the files in the repo to <code>/etc/apache2/sites-available</code></li>
<li>Disable all the existing sites that are linked</li>
<li>Enable all the sites that are present in <code>/etc/apache2/sites-available</code>.</li>
<li>Tell Apache to reload its configuration</li>
</ol>
<p>Now, on your development machine, you’ll need to set this up as a remote and start pushing virtual host configurations to it.</p>
<figure class='code'><figcaption><span></span></figcaption><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
</pre></td><td class='code'><pre><code class='bash'><span class='line'>git clone ssh://user@host-name/var/repos/virtualhosts.git
</span></code></pre></td></tr></table></div></figure>
<p>You’re now ready to start adding virtual host directives into that repo. When you push to <code>origin</code>, it’ll restart Apache with the updated config.</p>
<p>Here’s a sample - this is modified from the default:</p>
<figure class='code'><figcaption><span></span></figcaption><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
<span class='line-number'>2</span>
<span class='line-number'>3</span>
<span class='line-number'>4</span>
<span class='line-number'>5</span>
<span class='line-number'>6</span>
<span class='line-number'>7</span>
<span class='line-number'>8</span>
<span class='line-number'>9</span>
<span class='line-number'>10</span>
<span class='line-number'>11</span>
<span class='line-number'>12</span>
<span class='line-number'>13</span>
<span class='line-number'>14</span>
<span class='line-number'>15</span>
<span class='line-number'>16</span>
<span class='line-number'>17</span>
<span class='line-number'>18</span>
<span class='line-number'>19</span>
<span class='line-number'>20</span>
<span class='line-number'>21</span>
<span class='line-number'>22</span>
<span class='line-number'>23</span>
<span class='line-number'>24</span>
<span class='line-number'>25</span>
<span class='line-number'>26</span>
<span class='line-number'>27</span>
<span class='line-number'>28</span>
<span class='line-number'>29</span>
<span class='line-number'>30</span>
<span class='line-number'>31</span>
<span class='line-number'>32</span>
<span class='line-number'>33</span>
<span class='line-number'>34</span>
<span class='line-number'>35</span>
<span class='line-number'>36</span>
<span class='line-number'>37</span>
<span class='line-number'>38</span>
<span class='line-number'>39</span>
<span class='line-number'>40</span>
<span class='line-number'>41</span>
<span class='line-number'>42</span>
<span class='line-number'>43</span>
<span class='line-number'>44</span>
<span class='line-number'>45</span>
<span class='line-number'>46</span>
<span class='line-number'>47</span>
<span class='line-number'>48</span>
<span class='line-number'>49</span>
</pre></td><td class='code'><pre><code class='apacheconf'><span class='line'><span class="nt"><VirtualHost</span> <span class="s">*:80</span><span class="nt">></span>
</span><span class='line'> <span class="nb">ServerAdmin</span> [email protected]
</span><span class='line'>
</span><span class='line'> <span class="nb">DocumentRoot</span> <span class="sx">/var/sites/</span><some-domain-name>
</span><span class='line'> <span class="nb">ServerName</span> <some-domain-name>
</span><span class='line'> <span class="nb">ServerAlias</span> www.<some-domain-name>
</span><span class='line'>
</span><span class='line'> <span class="nb">SetEnv</span> db.name xxxxx
</span><span class='line'> <span class="nb">SetEnv</span> db.user xxxxx
</span><span class='line'> <span class="nb">SetEnv</span> db.password xxxxx
</span><span class='line'> <span class="nb">SetEnv</span> db.host localhost
</span><span class='line'>
</span><span class='line'> <span class="nt"><Directory</span> <span class="s">/</span><span class="nt">></span>
</span><span class='line'> <span class="nb">Options</span> FollowSymLinks
</span><span class='line'> <span class="nb">AllowOverride</span> <span class="k">None</span>
</span><span class='line'> <span class="nt"></Directory></span>
</span><span class='line'> <span class="nt"><Directory</span> <span class="s">/var/</span><span class="nt">></span>
</span><span class='line'> <span class="nb">Options</span> Indexes FollowSymLinks MultiViews
</span><span class='line'> <span class="nb">AllowOverride</span> <span class="k">All</span>
</span><span class='line'> <span class="nb">Order</span> allow,deny
</span><span class='line'> <span class="nb">allow</span> from <span class="k">all</span>
</span><span class='line'> <span class="nt"></Directory></span>
</span><span class='line'>
</span><span class='line'> <span class="nb">ScriptAlias</span> <span class="sx">/cgi-bin/</span> <span class="sx">/usr/lib/cgi-bin/</span>
</span><span class='line'> <span class="nt"><Directory</span> <span class="s">"/usr/lib/cgi-bin"</span><span class="nt">></span>
</span><span class='line'> <span class="nb">AllowOverride</span> <span class="k">None</span>
</span><span class='line'> <span class="nb">Options</span> +ExecCGI -MultiViews +SymLinksIfOwnerMatch
</span><span class='line'> <span class="nb">Order</span> allow,deny
</span><span class='line'> <span class="nb">Allow</span> from <span class="k">all</span>
</span><span class='line'> <span class="nt"></Directory></span>
</span><span class='line'>
</span><span class='line'> <span class="nb">ErrorLog</span> ${APACHE_LOG_DIR}/error.log
</span><span class='line'>
</span><span class='line'> <span class="c"># Possible values include: debug, info, notice, warn, error, crit,</span>
</span><span class='line'> <span class="c"># alert, emerg.</span>
</span><span class='line'> <span class="nb">LogLevel</span> <span class="k">warn</span>
</span><span class='line'>
</span><span class='line'> <span class="nb">CustomLog</span> ${APACHE_LOG_DIR}/access.log combined
</span><span class='line'>
</span><span class='line'> <span class="nb">Alias</span> <span class="sx">/doc/</span> <span class="s2">"/usr/share/doc/"</span>
</span><span class='line'> <span class="nt"><Directory</span> <span class="s">"/usr/share/doc/"</span><span class="nt">></span>
</span><span class='line'> <span class="nb">Options</span> Indexes MultiViews FollowSymLinks
</span><span class='line'> <span class="nb">AllowOverride</span> <span class="k">None</span>
</span><span class='line'> <span class="nb">Order</span> deny,allow
</span><span class='line'> <span class="nb">Deny</span> from <span class="k">all</span>
</span><span class='line'> <span class="nb">Allow</span> from <span class="m">127.0.0.0/255</span>.0.0.0 ::1/128
</span><span class='line'> <span class="nt"></Directory></span>
</span><span class='line'>
</span><span class='line'><span class="nt"></VirtualHost></span>
</span></code></pre></td></tr></table></div></figure>
<h2>Set up git repo for each site</h2>
<p>So, we can see that virtual hosts are added to Apache whenever you add a new config, but those virtual host configurations are pointing to locations that don’t yet exist. Let’s fix that now, back to your remote server.</p>
<figure class='code'><figcaption><span></span></figcaption><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
<span class='line-number'>2</span>
<span class='line-number'>3</span>
<span class='line-number'>4</span>
</pre></td><td class='code'><pre><code class='bash'><span class='line'>mkdir -p /var/sites/<some-domain-name>
</span><span class='line'>mkdir -p /var/repos/<some-domain-name>.git
</span><span class='line'><span class="nb">cd</span> /var/repos/<some-domain-name>.git
</span><span class='line'>git init --bare
</span></code></pre></td></tr></table></div></figure>
<p>And to have this git repo deploy whenever it is pushed to, <code>vim hooks/post-deploy</code></p>
<figure class='code'><figcaption><span></span></figcaption><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
<span class='line-number'>2</span>
</pre></td><td class='code'><pre><code class='bash'><span class='line'><span class="c">#!/bin/sh</span>
</span><span class='line'><span class="nv">GIT_WORK_TREE</span><span class="o">=</span>/var/sites/<some-domain-name> git checkout -f master
</span></code></pre></td></tr></table></div></figure>
<p>Don’t forget to make it executable:</p>
<figure class='code'><figcaption><span></span></figcaption><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
</pre></td><td class='code'><pre><code class='bash'><span class='line'>chmod +x hooks/post-deploy
</span></code></pre></td></tr></table></div></figure>
<p>It’s ready to go! To check it out locally, you can:</p>
<figure class='code'><figcaption><span></span></figcaption><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
</pre></td><td class='code'><pre><code class='bash'><span class='line'>git clone ssh://user@host-name/var/repos/<some-domain-name>.git
</span></code></pre></td></tr></table></div></figure>
<p>or you could add it as a remote for an existing repository</p>
<figure class='code'><figcaption><span></span></figcaption><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
</pre></td><td class='code'><pre><code class='bash'><span class='line'>git remote add <repo-name> ssh://user@host-name/var/repos/<some-domain-name>.git
</span></code></pre></td></tr></table></div></figure>
<p>Push to that remote whenever you’re ready for your changes to go live.</p>
]]></content>
</entry>
<entry>
<title type="html"><![CDATA[Renewed interest]]></title>
<link href="http://www.eagleton.org/2013/06/renewed-interest/"/>
<updated>2013-06-09T11:52:00+10:00</updated>
<id>http://www.eagleton.org/2013/06/renewed-interest</id>
<content type="html"><![CDATA[<p>Well, it looks like the <a href="http://www.eagleton.org/2012/11/another-new-blogging-engine/">pledge</a> I made when I replaced WordPress with Octopress for my blog didn’t last too long - i.e. I didn’t even get one article out after making that pledge. That’s pretty poor.<!-- More --></p>
<p>Over the last few weekends, I’ve caught up with an <a href="https://twitter.com/sammyjarrett">old buddy</a> to get our nerd on and work on some nerdy things. This weekend, we looked at Octopress (in the interest of setting it up for him) and it got me interested in posting more. So, here’s a new theme (so it’s not stock-standard Octopress flavour) and hopefully more of a commitment to getting some content out there..</p>
<p>I’ve recently completed Certified Scrum Master training and have deployed some websites to a new hosting setup with <a href="https://www.digitalocean.com/?refcode=1d72a90eb581">Digital Ocean</a> (NB: Referral code embedded in that link) which I’ve found to be a fast, cheap and easy way to manage a host for the nerdier amongst us. Expect some posts in the coming weeks covering some of those topics.</p>
]]></content>
</entry>
<entry>
<title type="html"><![CDATA[Another new blogging engine]]></title>
<link href="http://www.eagleton.org/2012/11/another-new-blogging-engine/"/>
<updated>2012-11-05T21:11:00+11:00</updated>
<id>http://www.eagleton.org/2012/11/another-new-blogging-engine</id>
<content type="html"><![CDATA[<p>This blog tends to get updated… sporadically. I get the energy to post more often and that generally results in transferring the content from one blog engine to another - sometimes the new blog doesn’t even get a new post. This time, I’m changing from wordpress to octopress, living in GitHub pages and I guess, once again, I’ll pledge to post more often.</p>
<!-- more -->
<h2>Benefits</h2>
<ul>
<li>I can hack away on posts in <a href="http://www.sublimetext.com/">Sublime Text 2</a> and deploy them whenever I’m ready.</li>
<li>I can write my posts in markdown which is great.</li>
<li>I found a great <a href="https://github.com/blueplanet/sublime-text-2-octopress">octopress plugin for sublime</a> which is really handy and to which I’ve been able to contribute some changes and features to.</li>
<li>Octopress and Jekyll are in ruby, ST2 plugins are in python and the existing templates use LESS. A nice change to my day-to-day life as a PHP developer to hack around in some new technologies.</li>
<li>Performance of effectively static media via GitHub pages is much better than loading pages through wordpress’ database driven structure. See if you can tell when I changed the hosting arrangement in the graph below.</li>
</ul>
<p><img src="http://www.eagleton.org/images/wordpress-octopress-performance.png" width="678" height="454" title="Page load performance improvement - guess when I changed the hosting arrangement" ></p>
<h2>Detractors</h2>
<ul>
<li>I actually really liked wordpress’ stats available through JetPack. I’ve set up Google Analytics, but while it’s probably a better product, it’s just not as friendly.</li>
<li>Wordpress has so many themes available. This is possibly a benefit though - I used to get <a href="http://en.wikipedia.org/wiki/Analysis_paralysis">analysis paralysis</a> in attempting to decide which one to use.</li>
</ul>
<p>Let’s see how I go. Hereby pledging (once again) to post more often, keeping it technical.</p>
]]></content>
</entry>
<entry>
<title type="html"><![CDATA[MySQL Performance on OS X]]></title>
<link href="http://www.eagleton.org/2012/01/mysql-performance-on-os-x/"/>
<updated>2012-01-25T22:50:00+11:00</updated>
<id>http://www.eagleton.org/2012/01/mysql-performance-on-os-x</id>
<content type="html"><![CDATA[<p>Ever wondered why performance of MySQL on OS X was so much worse than a Linux or windows counterpart - especially when doing DROP/CREATE statements (ie in the setup of integration tests etc)? It turns out Mac OS has a safer file creation function than is available on other operating systems and the use of that slows down performance of file operations in MySQL.</p>
<p>You can fix this quickly by adding the following to your <strong>my.cnf</strong> file in the<strong> [server]</strong> block. It’s probably best not to do this in production, but who actually uses OS X as a production web server anyway?</p>
<pre>skip-sync-frm=OFF</pre>
<p>Source: <a href="http://bugs.mysql.com/bug.php?id=56550">The original MySQL bug report</a> (although it’s not really a bug).</p>
]]></content>
</entry>
<entry>
<title type="html"><![CDATA[Problems with the default virtual host on MAMP Pro 2.0.5]]></title>
<link href="http://www.eagleton.org/2012/01/problems-with-the-default-virtual-host-on-mamp-pro-2-0-5/"/>
<updated>2012-01-23T00:00:00+11:00</updated>
<id>http://www.eagleton.org/2012/01/problems-with-the-default-virtual-host-on-mamp-pro-2-0-5</id>
<content type="html"><![CDATA[<p>I’ve recently upgraded to MAMP Pro and I like how I can easily add virtual hosts in its UI - something I had previously done in code in the free version and on older machines running windows, Linux etc. I ran into a strange problem with MAMP though.</p>
<p>In the project I’m working on, I expect to have the default behaviour for unmatched host names go to the first virtual host (a default behaviour of the apache virtual host system) and to have some custom virtual host configurations for my Zend Framework app to work (namely “SetEnv APPLICATION_ENV development”). After pulling my hair out for a while, I found out why my environment variables weren’t being sent through to apache and PHP when I was getting the default virtual host: MAMP Pro adds an extra first virtual host above your collection of virtual hosts (trying to be helpful, I assume) which doesn’t have the custom virtual host directory settings in it and as such, requests will fail.<!--more--></p>
<p>To fix it, go to</p>
<p><img src="http://www.eagleton.org/images/mamp-edit-conf.png" width="546" height="110"></p>
<p>and make the following change:</p>
<script src="https://gist.github.com/3060058.js"> </script>
<p>Of note here are the commented out lines. This port iteration business sets up an empty virtual host at the start of the list which is responsible for handling all failed matches of the following entries - AKA the default virtual host. In my version of the file, this is around line 570, but you should see it about 60 lines before the end of the file.</p>
<p>Then restart apache. You’ll find in your compiled httpd.conf file (/Library/Application Support/appsolute/MAMP PRO/conf/httpd.conf), you no longer have the extra virtual host definition above the ones you’ve explicitly defined and the extra settings you’ve added into the definition for your first virtual host will be passed along correctly to all unmatched web requests.</p>
]]></content>
</entry>
<entry>
<title type="html"><![CDATA[Stop working on shit code]]></title>
<link href="http://www.eagleton.org/2011/07/stop-working-on-shit-code/"/>
<updated>2011-07-26T00:00:00+10:00</updated>
<id>http://www.eagleton.org/2011/07/stop-working-on-shit-code</id>
<content type="html"><![CDATA[<p>Do you work on old, shitty code? Does it stink? Each time you have to work on that same file that drives you nuts, does it make you question your sanity?</p>
<p>In my day job, if there’s something that’ll bring tears to a developer’s eyes, it’s being given a story to work on that involves touching a 6~7 year old file called <code>sales.php</code>. This file is a monstrous 7000+ lines long and is a gigantic state machine that is confusing and highly prone to malfunction. It also loosely forms the “C” and the “V” of a fairly broken MVC structure. To make matters worse, over the years, there have been ~10 different developers ‘work’ on it and it’s a delicate debacle of different coding styles, motivations and business desires.<!--more--></p>
<p>Every developer who has ever had the misfortune of working with this file (and the rest of the broken MVC) has always cried out that the whole system needs rewriting (and rightly so), but it’s hard to sell that to the business when it’ll a) take ages, b) probably take longer than that, c) in the meantime, they get no new features and d) will, once completed, probably be just as bad as the old one (and hey presto, it’s now outdated too). I was talking to a colleague about this the other week and came to a realisation about it.</p>
<p><strong>Stop working on shit code! We’re better than that.</strong> After working with this software for 3 years, I can’t say that I’m proud of the work I’ve done there (my colleague was 6 years - he couldn’t either) - I’ve just continued the legacy of bad code because the barrier to change was too high. If you can’t be proud of your work, then when you look back on it later, you’ll realise you’ve wasted your time (and your company’s). As of that day, my new work ethos is centred around pride.</p>
<ul>
<li>As I commit each changeset, I want to be able to say I’m proud of the code I’m committing.</li>
<li>I respect my colleagues as professionals and friends. When they peer review my work, I don’t want them to think “Wow, what a lame way to do that” or “wouldn’t it be great if he did ‘xyz’?”. If they do think I’ve done something poorly, I <strong>want</strong> them to call me out on it. If they know some smarter way to do it, teach me. If I’ve left a debugging line in or a dodgy comment, make me fix it.</li>
<li>Conversely, when I peer review my colleague’s work, I want to know that what I’m seeing is their best solution to the problem and that they are proud of the work they’re showing me. I will tell them if I think it stinks and explain why.</li>
</ul>
<p>I’m not saying each commit has to revolutionise the world or rewrite the whole system, but <strong>the state of the system should ‘smell’ better after each commit than before.</strong> Not smell the same, and definitely not smell worse. Working on some new calculation inside a 7000 line class? Refactor that calculation out in a sensible way. Suddenly that stinky old class is only 6900 lines of crap. I’d say that smells a little better.</p>
<p>Go home at the end of the day being able to say ”<strong>I’m proud of what I did here</strong>”.</p>
]]></content>
</entry>
<entry>
<title type="html"><![CDATA[OS X Lion + MAMP 2.0.1 + Memcache and PHP 5.2.17]]></title>
<link href="http://www.eagleton.org/2011/07/os-x-lion-mamp-2-0-1-memcache-and-php-5-2-17/"/>
<updated>2011-07-25T00:00:00+10:00</updated>
<id>http://www.eagleton.org/2011/07/os-x-lion-mamp-2-0-1-memcache-and-php-5-2-17</id>
<content type="html"><![CDATA[<p>After a fresh install of Lion, getting up to speed with my normal MAMP dev setup + memcached wasn’t as easy as on Snow Leopard. I ended up seeking inspiration from the following articles:</p>
<ul>
<li><a href="http://mxcl.github.com/homebrew/">Homebrew</a> - for installing memcached</li>
<li><a href="http://www.lullabot.com/articles/setup-memcached-mamp-sandbox-environment">Lullabot’s article about memcached with mamp</a></li>
<li><a href="http://forum.mamp.info/viewtopic.php?f=2&t=13815">MAMP Forum</a> - MAMP 2.0.1’s pear is broken</li>
</ul>
<p>In hindsight, it was quite easy:<!--more--></p>
<ul>
<li>Ensure Xcode is installed - XCode 4.1 is free now in the app store - make sure you install it after it downloads</li>
<li>Install homebrew as per the instructions <a href="http://mxcl.github.com/homebrew/">here</a></li>
<li>Install memcached by simply
<code>brew install memcached</code></li>
<li>pear in this version of MAMP is broken, to fix it, simply remove pear’s config file
<code>mv /Applications/MAMP/bin/php/php5.2.17/conf/pear.conf /Applications/MAMP/bin/php/php5.2.17/conf/pear.conf.old</code></li>
<li>As per the section ”<a href="http://www.lullabot.com/articles/setup-memcached-mamp-sandbox-environment">Install Memcache PHP Extension - Option 2</a>”
<ul>
<li><a href="http://www.php.net/downloads.php">Download the correct version of the php source code for your installed php</a></li>
<li>Create the path /Applications/MAMP/bin/php/php5.2.17/include/ and extract the contents of the source code download here.</li>
<li>Rename the folder that was created as just ‘php’ so you’ll end up with /Applications/MAMP/bin/php/php5.2.17/include/php</li>
<li><code>cd /Applications/MAMP/bin/php/php5.2.17/include/php
./configure
cd /Applications/MAMP/bin/php/php5.2.17/bin
./pecl i memcache</code>
This should dump memcached.so in the extension folder. If it’s made something other than /Applications/MAMP/bin/php/php5.2.17/lib/php/extensions/no-debug-non-zts-20060613, move it into there (it’d only be different in the last part of the path)</li>
</ul>
</li>
<li>Add this to the extensions part of your php.ini
<code>
extension=memcache.so
</code></li>
<li>Restart apache</li>
</ul>
<p>And hey presto, it’s done.</p>
<p>You could also cheat and just put my <a href="http://www.eagleton.org/wp-content/uploads/2011/07/memcache.so">pre-compiled version of memcache.so</a> in your extension folder and go to town.</p>
<p><span style="text-decoration: underline;">Update:</span>
I’ve also compiled the php 5.3.6 version of the <code>.so</code> file. <a href="http://www.eagleton.org/wp-content/uploads/2011/07/memcache-php5.3.6.so">Download it</a>, rename it back to <code>memcache.so</code>, put it in your extension folder and enjoy.</p>
]]></content>
</entry>
<entry>
<title type="html"><![CDATA[Wiki Class]]></title>
<link href="http://www.eagleton.org/2010/06/wiki-class/"/>
<updated>2010-06-08T21:44:00+10:00</updated>
<id>http://www.eagleton.org/2010/06/wiki-class</id>
<content type="html"><![CDATA[<p>Ages ago, I wrote a simple class to enable some scripts to update our wiki. A friend asked for a copy, so here it is:<!--more--></p>
<div><script src='https://gist.github.com/1598093.js?file='></script>
<noscript><pre><code></code></pre></noscript></div>
]]></content>
</entry>
</feed>