-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathatom.xml
2090 lines (1719 loc) · 152 KB
/
atom.xml
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
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
<title><![CDATA[Blind Squirrel]]></title>
<link href="http://bealetech.com/atom.xml" rel="self"/>
<link href="http://bealetech.com/"/>
<updated>2013-06-14T14:15:45-07:00</updated>
<id>http://bealetech.com/</id>
<author>
<name><![CDATA[Sean Laurent]]></name>
</author>
<generator uri="http://octopress.org/">Octopress</generator>
<entry>
<title type="html"><![CDATA[Custom SSL Certificates with Chef 11 Server]]></title>
<link href="http://bealetech.com/blog/2013/06/14/custom-ssl-certificates-with-chef-11-server/"/>
<updated>2013-06-14T14:02:00-07:00</updated>
<id>http://bealetech.com/blog/2013/06/14/custom-ssl-certificates-with-chef-11-server</id>
<content type="html"><![CDATA[<p>While setting up <a href="http://www.opscode.com/chef/">Chef</a> 11 Server on a <a href="http://www.centos.org/">CentOS</a> 6.4 box, I realized I wanted that it defaults to using self-signed SSL certificates. Since we have existing wildcard certificates through GoDaddy, I wanted to switch over to those. It look a little bit of digging and some help from IRC #chef to get things working.</p>
<!-- more -->
<p>First, you need to your certificate and key. For completeness, you want to combine your certificate with the certificate chain provided by your signing authority. In the case of GoDaddy, they gave me two files:</p>
<ul>
<li><code>example.com.crt</code></li>
<li><code>gd_bundle.crt</code></li>
</ul>
<p>To create a combined bundle:</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'>cat example.com.crt gd_bundle.crt > example.com.pem
</span></code></pre></td></tr></table></div></figure>
<p>In addition, you need to make sure that your keyfile does <em>not</em> have a passphrase associated with it, otherwise Nginx will refuse to start up. To remove the passphrase from an existing key file:</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'>openssl rsa -in example.com.key -out example.com.nopassphrase.key
</span></code></pre></td></tr></table></div></figure>
<p>You need to copy the combined bundle and your key file to your server and place them in a secure location. On a typical CentOS installation, you want to dump the files in <code>/etc/pki/tls/private</code>.</p>
<p>Next, you need to tell Chef to use the custom certificates. Create a file named <code>/etc/chef-server/chef-server.rb</code>, if doesn’t exist already. Add the following lines 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>
<span class='line-number'>2</span>
</pre></td><td class='code'><pre><code class='ruby'><span class='line'><span class="n">nginx</span><span class="o">[</span><span class="s1">'ssl_certificate'</span><span class="o">]</span> <span class="o">=</span> <span class="s2">"/etc/pki/tls/private/example.com.pem"</span>
</span><span class='line'><span class="n">nginx</span><span class="o">[</span><span class="s1">'ssl_certificate_key'</span><span class="o">]</span> <span class="o">=</span> <span class="s2">"/etc/pki/tls/private/example.com.nopassphrase.key"</span>
</span></code></pre></td></tr></table></div></figure>
<p>Now, reconfigure Chef 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>
</pre></td><td class='code'><pre><code class='bash'><span class='line'>chef-server-ctl reconfigure
</span></code></pre></td></tr></table></div></figure>
<p>That will reconfigure Nginx with the new settings (which are stored in <code>/var/opt/chef-server/nginx/etc</code>) and automatically restart Nginx. You can verify that it’s using the correct certificate by running:</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'>openssl s_client -connect localhost:443
</span></code></pre></td></tr></table></div></figure>
]]></content>
</entry>
<entry>
<title type="html"><![CDATA[Asgard and Mater Cookbooks]]></title>
<link href="http://bealetech.com/blog/2013/04/29/asgard-and-mater-cookbooks/"/>
<updated>2013-04-29T21:00:00-07:00</updated>
<id>http://bealetech.com/blog/2013/04/29/asgard-and-mater-cookbooks</id>
<content type="html"><![CDATA[<p>Over at <a href="http://www.studyblue.com">StudyBlue</a>, we leverage <a href="http://www.opscode.com/chef/">Chef</a> pretty heavily for automation. Today we just open sourced two Chef cookbooks as a way to give back to the community that has supported us.</p>
<!-- more -->
<h2>Asgard</h2>
<p><a href="https://github.com/StudyBlue/chef-asgard">https://github.com/StudyBlue/chef-asgard</a></p>
<ul>
<li>Chef cookbook for installing <a href="https://github.com/Netflix/asgard">Netflix Asgard</a>.</li>
<li>Installs and configures Netflix Asgard with Java 6 and Tomcat 7.</li>
<li>Can also proxy via Apache.</li>
</ul>
<h2>Mater</h2>
<p><a href="https://github.com/StudyBlue/chef-mater">https://github.com/StudyBlue/chef-mater</a></p>
<ul>
<li>Chef cookbook for installing <a href="https://github.com/obfuscurity/mater">Mater</a>, a bridge between <a href="http://panic.com/statusboard/">StatusBoard</a> and <a href="http://graphite.wikidot.com/">Graphite</a>.</li>
<li>Includes support for running Mater under <a href="http://unicorn.bogomips.org/">Unicorn</a> with Apache as a proxy.</li>
</ul>
]]></content>
</entry>
<entry>
<title type="html"><![CDATA[Pushing to Maven Central with Sonatype]]></title>
<link href="http://bealetech.com/blog/2013/04/10/pushing-to-maven-central-with-sonatype/"/>
<updated>2013-04-10T15:07:00-07:00</updated>
<id>http://bealetech.com/blog/2013/04/10/pushing-to-maven-central-with-sonatype</id>
<content type="html"><![CDATA[<p>Getting your opensource JAR published to Maven Central is free, but requires a little bit of up front work. I use <a href="https://sonatype.org">Sonatype</a> to help publish the jars for <a href="https://github.com/organicveggie/metrics-statsd">metrics-statsd</a>, which makes life much easier.
Most of the process is documented by Sonatype, which you can read about here:</p>
<p><a href="https://docs.sonatype.org/display/Repository/Sonatype+OSS+Maven+Repository+Usage+Guide">https://docs.sonatype.org/display/Repository/Sonatype+OSS+Maven+Repository+Usage+Guide</a></p>
<p>There were a few tricky parts that either weren’t documented well or I just found confusing. I have tried to document some of these parts below.</p>
<!-- more -->
<h1>Terminology</h1>
<p>In case you’re as easily confused as I was, Sonatype uses three different terms when talking about pushing jars:</p>
<ol>
<li><strong>Deploy</strong> refers to deploying <em>snapshots</em> to Sonatype.</li>
<li><strong>Staging</strong> refers to pushing potential release artifacts to Sonatype. Note that <em>staging</em> an artifact does not automatically push it to Maven Central.</li>
<li><strong>Release</strong> refers to marking the artifacts for release on Sonatype’s Nexus server so that they get pushed to Maven Central.</li>
</ol>
<h1>Required Changes</h1>
<h2>Artifacts</h2>
<p>Pushing jars to Maven Central requires that you produce three artifacts:</p>
<ol>
<li>Main jar with compiled classes</li>
<li>Sources jar</li>
<li>Javadocs jar</li>
</ol>
<p>To automatically generate the second and third artifacts, add the following to the build plugins section of your <code>pom.xml</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>
<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>
</pre></td><td class='code'><pre><code class='xml'><span class='line'><span class="nt"><plugin></span>
</span><span class='line'> <span class="nt"><groupId></span>org.apache.maven.plugins<span class="nt"></groupId></span>
</span><span class='line'> <span class="nt"><artifactId></span>maven-source-plugin<span class="nt"></artifactId></span>
</span><span class='line'> <span class="nt"><version></span>2.1.2<span class="nt"></version></span>
</span><span class='line'> <span class="nt"><executions></span>
</span><span class='line'> <span class="nt"><execution></span>
</span><span class='line'> <span class="nt"><id></span>attach-sources<span class="nt"></id></span>
</span><span class='line'> <span class="nt"><goals></span>
</span><span class='line'> <span class="nt"><goal></span>jar<span class="nt"></goal></span>
</span><span class='line'> <span class="nt"></goals></span>
</span><span class='line'> <span class="nt"></execution></span>
</span><span class='line'> <span class="nt"></executions></span>
</span><span class='line'><span class="nt"></plugin></span>
</span><span class='line'><span class="nt"><plugin></span>
</span><span class='line'> <span class="nt"><groupId></span>org.apache.maven.plugins<span class="nt"></groupId></span>
</span><span class='line'> <span class="nt"><artifactId></span>maven-javadoc-plugin<span class="nt"></artifactId></span>
</span><span class='line'> <span class="nt"><version></span>2.8.1<span class="nt"></version></span>
</span><span class='line'> <span class="nt"><executions></span>
</span><span class='line'> <span class="nt"><execution></span>
</span><span class='line'> <span class="nt"><id></span>attach-javadocs<span class="nt"></id></span>
</span><span class='line'> <span class="nt"><goals></span>
</span><span class='line'> <span class="nt"><goal></span>jar<span class="nt"></goal></span>
</span><span class='line'> <span class="nt"></goals></span>
</span><span class='line'> <span class="nt"></execution></span>
</span><span class='line'> <span class="nt"></executions></span>
</span><span class='line'><span class="nt"></plugin></span>
</span></code></pre></td></tr></table></div></figure>
<h2>Artifact Signing</h2>
<p>Maven Central requires that you sign your released artifacts with GPG. Note that <em>snapshots</em> do not need to be signed. Sonatype has a thorough article on signing your artifacts:</p>
<p><a href="https://docs.sonatype.org/display/Repository/How+To+Generate+PGP+Signatures+With+Maven">How to Generate PGP Signatures With Maven</a></p>
<p>The key steps are:</p>
<ol>
<li>Generate a key pair</li>
<li>Distribute your public key</li>
<li>Update your <code>pom.xml</code></li>
</ol>
<p>The first two steps are straightforward. The only trick with the third step is that you <em>only</em> want to sign artifacts during the release process. If you add the <code>maven-gpg-plugin</code> to your main, every single build will get signed and Maven will prompt you for your passphrase with every build. Instead, you can define a Maven profile with a specific name and include the <code>maven-gpg-plugin</code> 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>
<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>
</pre></td><td class='code'><pre><code class='xml'><span class='line'><span class="nt"><profiles></span>
</span><span class='line'> <span class="nt"><profile></span>
</span><span class='line'> <span class="nt"><id></span>release-sign-artifacts<span class="nt"></id></span>
</span><span class='line'> <span class="nt"><activation></span>
</span><span class='line'> <span class="nt"><property></span>
</span><span class='line'> <span class="nt"><name></span>performRelease<span class="nt"></name></span>
</span><span class='line'> <span class="nt"><value></span>true<span class="nt"></value></span>
</span><span class='line'> <span class="nt"></property></span>
</span><span class='line'> <span class="nt"></activation></span>
</span><span class='line'> <span class="nt"><build></span>
</span><span class='line'> <span class="nt"><plugins></span>
</span><span class='line'> <span class="nt"><plugin></span>
</span><span class='line'> <span class="nt"><groupId></span>org.apache.maven.plugins<span class="nt"></groupId></span>
</span><span class='line'> <span class="nt"><artifactId></span>maven-gpg-plugin<span class="nt"></artifactId></span>
</span><span class='line'> <span class="nt"><version></span>1.1<span class="nt"></version></span>
</span><span class='line'> <span class="nt"><executions></span>
</span><span class='line'> <span class="nt"><execution></span>
</span><span class='line'> <span class="nt"><id></span>sign-artifacts<span class="nt"></id></span>
</span><span class='line'> <span class="nt"><phase></span>verify<span class="nt"></phase></span>
</span><span class='line'> <span class="nt"><goals></span>
</span><span class='line'> <span class="nt"><goal></span>sign<span class="nt"></goal></span>
</span><span class='line'> <span class="nt"></goals></span>
</span><span class='line'> <span class="nt"></execution></span>
</span><span class='line'> <span class="nt"></executions></span>
</span><span class='line'> <span class="nt"></plugin></span>
</span><span class='line'> <span class="nt"></plugins></span>
</span><span class='line'> <span class="nt"></build></span>
</span><span class='line'> <span class="nt"></profile></span>
</span><span class='line'><span class="nt"></profiles></span>
</span></code></pre></td></tr></table></div></figure>
<h2>distributionManagement</h2>
<p>Following the recommendation from Sonatype, you will remove the <code><repositories></repositories></code> section of your <code>pom.xml</code>. Once you do that, Maven no longer knows what server to use when <em>deploying</em> or <em>staging</em>. To compensate, you need to add a <code>distributionManagement</code> section:</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>
</pre></td><td class='code'><pre><code class='xml'><span class='line'><span class="nt"><distributionManagement></span>
</span><span class='line'> <span class="nt"><snapshotRepository></span>
</span><span class='line'> <span class="nt"><id></span>sonatype-nexus-snapshots<span class="nt"></id></span>
</span><span class='line'> <span class="nt"><url></span>https://oss.sonatype.org/content/repositories/snapshots/<span class="nt"></url></span>
</span><span class='line'> <span class="nt"></snapshotRepository></span>
</span><span class='line'> <span class="nt"><repository></span>
</span><span class='line'> <span class="nt"><id></span>sonatype-nexus-staging<span class="nt"></id></span>
</span><span class='line'> <span class="nt"><url></span>https://oss.sonatype.org/service/local/staging/deploy/maven2/<span class="nt"></url></span>
</span><span class='line'> <span class="nt"></repository></span>
</span><span class='line'><span class="nt"></distributionManagement></span>
</span></code></pre></td></tr></table></div></figure>
<h2>Sonatype Parent POM</h2>
<p>You need to configure your <code>pom.xml</code> to inherit from the Sonatype Parent POM:</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='xml'><span class='line'><span class="nt"><parent></span>
</span><span class='line'> <span class="nt"><groupId></span>org.sonatype.oss<span class="nt"></groupId></span>
</span><span class='line'> <span class="nt"><artifactId></span>oss-parent<span class="nt"></artifactId></span>
</span><span class='line'> <span class="nt"><version></span>7<span class="nt"></version></span>
</span><span class='line'><span class="nt"></parent></span>
</span></code></pre></td></tr></table></div></figure>
<h1>Deploying</h1>
<p>Assuming you’ve followed the instructions from Sonatype and setup an account, you’re now ready to deploy snapshots. The process is simple:</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'>mvn clean deploy
</span></code></pre></td></tr></table></div></figure>
<p>That will automatically clean, build and push your snapshot to Sonatype.</p>
<h1>Releasing</h1>
<p>Pushing a release jar to Maven Central consists of two parts: staging and releasing.</p>
<h2>Staging</h2>
<p>In this part we clean everything up; prepare for the build by creating a tag for the release and updating the pom.xml; perform the build; deploy the artifacts to Sonatype.</p>
<p>The process consists of three commands:</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'>mvn release:clean
</span><span class='line'>mvn release:prepare
</span><span class='line'>mvn release:perform
</span></code></pre></td></tr></table></div></figure>
<p>The <code>release:prepare</code> step will prompt you for release information. Here is some sample output from the 2.3.0 release of <a href="https://github.com/organicveggie/metrics-statsd">metrics-statsd</a>:</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>
</pre></td><td class='code'><pre><code class='bash'><span class='line'><span class="nv">$ </span>mvn release:prepare
</span><span class='line'><span class="o">[</span>INFO<span class="o">]</span> Scanning <span class="k">for </span>projects...
</span><span class='line'><span class="o">[</span>INFO<span class="o">]</span>
</span><span class='line'><span class="o">[</span>INFO<span class="o">]</span> ------------------------------------------------------------------------
</span><span class='line'><span class="o">[</span>INFO<span class="o">]</span> Building Metrics Statsd Support 2.3.0-SNAPSHOT
</span><span class='line'><span class="o">[</span>INFO<span class="o">]</span> ------------------------------------------------------------------------
</span><span class='line'><span class="o">[</span>INFO<span class="o">]</span>
</span><span class='line'><span class="o">[</span>INFO<span class="o">]</span> --- maven-release-plugin:2.2.1:prepare <span class="o">(</span>default-cli<span class="o">)</span> @ metrics-statsd ---
</span><span class='line'><span class="o">[</span>INFO<span class="o">]</span> Verifying that there are no <span class="nb">local </span>modifications...
</span><span class='line'><span class="o">[</span>INFO<span class="o">]</span> ignoring changes on: pom.xml.next, release.properties, pom.xml.releaseBackup, pom.xml.backup, pom.xml.branch, pom.xml.tag
</span><span class='line'><span class="o">[</span>INFO<span class="o">]</span> Executing: /bin/sh -c <span class="nb">cd</span> /Users/sean/src/metrics-statsd <span class="o">&&</span> git status
</span><span class='line'><span class="o">[</span>INFO<span class="o">]</span> Working directory: /Users/sean/src/metrics-statsd
</span><span class='line'><span class="o">[</span>INFO<span class="o">]</span> Checking dependencies and plugins <span class="k">for </span>snapshots ...
</span><span class='line'>What is the release version <span class="k">for</span> <span class="s2">"Metrics Statsd Support"</span>? <span class="o">(</span>com.bealetech:metrics-statsd<span class="o">)</span> 2.3.0: :
</span><span class='line'>What is SCM release tag or label <span class="k">for</span> <span class="s2">"Metrics Statsd Support"</span>? <span class="o">(</span>com.bealetech:metrics-statsd<span class="o">)</span> v2.3.0: :
</span><span class='line'>What is the new development version <span class="k">for</span> <span class="s2">"Metrics Statsd Support"</span>? <span class="o">(</span>com.bealetech:metrics-statsd<span class="o">)</span> 2.3.1-SNAPSHOT: :
</span></code></pre></td></tr></table></div></figure>
<h2>Releasing</h2>
<p>Once the artifacts are staged on Sonatype’s Nexus, you need to go through a few annoying steps:</p>
<ul>
<li>Close out the staging release in Sonatype</li>
<li>Release the artifacts in Sonatype</li>
</ul>
<p>That process is well documented (with images) by Sonatype:</p>
<p><a href="https://docs.sonatype.org/display/Repository/Sonatype+OSS+Maven+Repository+Usage+Guide#SonatypeOSSMavenRepositoryUsageGuide-8a.ReleaseIt">https://docs.sonatype.org/display/Repository/Sonatype+OSS+Maven+Repository+Usage+Guide#SonatypeOSSMavenRepositoryUsageGuide-8a.ReleaseIt</a></p>
<p>Within two hours, Sonatype will push the artifacts to Maven Centrl.</p>
]]></content>
</entry>
<entry>
<title type="html"><![CDATA[Distributed Graphite on EC2]]></title>
<link href="http://bealetech.com/blog/2012/05/28/distributed-graphite-on-ec2/"/>
<updated>2012-05-28T14:20:00-07:00</updated>
<id>http://bealetech.com/blog/2012/05/28/distributed-graphite-on-ec2</id>
<content type="html"><![CDATA[<p>Some time ago, we switched from <a href="http://www.cacti.net/">Cacti</a> to <a href="http://graphite.wikidot.com/">Graphite</a> for tracking and graphing system metrics. In our <a href="http://aws.amazon.com/ec2/">Amazon EC2 environment</a>, we frequently startup new servers and shut down old servers. While Cacti did a decent job, the amount of manual effort required to setup new graphs made it a challenge to use. Since Graphite simply tracks anything you throw at it and easily handles applying aggregate functions across multiple metrics, we found Graphite to be a much better fit with EC2 and our usage patterns. With a solid web interface and a variety of alternate front-ends and awesome dashboard tools like <a href="http://jondot.github.com/graphene/">Graphene</a>, we quickly fell in love with Graphite.</p>
<!-- more -->
<p>In fact, the more we utilized Graphite, the more data we wanted to push into Graphite. Systems metrics? Check. IO stats? Check. Apache stats? Check. MongoDB stats on a per collection basis? Why not! We quickly found ourselves with over 50,000 metrics and 500GB of data, all of which was getting updated every 15-30 seconds. Unfortunately, we also rapidly hit the limit of how much data we could record on a single instance. Even with a RAID-0 array of 8x EBS volumes on an m2.2xlarge instance, we couldn’t write the data fast enough. The poor instance began spending more than 50% of it’s time in I/O wait and eventually became non-responsive. What we needed was a way to distribute the write load across multiple instances.</p>
<p>Fortunately, Graphite natively supports running in a distributed environment. A successful deployment consists of three key pieces:</p>
<ul>
<li>carbon-cache - This is what actually accepts and stores the metrics.</li>
<li>carbon-relay - Handles sharding the metrics and sending them to the appropriate carbon-cache instances.</li>
<li>webapp - Handles displaying the metrics. Must reside on every instance running a carbon-cache daemon. The webapp queries the other carbon-cache instances for data as necessary.</li>
</ul>
<p>Although there are many different ways you can setup your distributed Graphite environment, we chose to take a straight foward approach:</p>
<ul>
<li>One dedicated instance running carbon-relay that receives metrics from the various server instances, shards the metrics and forwards them on to the carbon-cache servers</li>
<li>Two dedicated instances running both carbon-cache and webapp.</li>
</ul>
<h2>Carbon Relay</h2>
<p>On the carbon-relay server, you need to configure two key files to indicate that this node should run as a relay: carbon.conf and relay.conf.</p>
<p><code>carbon.conf</code></p>
<div>
<pre><code class='properties'>[relay]
RELAY_METHOD = consistent-hashing
LINE_RECEIVER_INTERFACE = x.x.x.x
LINE_RECEIVER_PORT = 2003
PICKLE_RECEIVER_INTERFACE = 127.0.0.1
PICKLE_RECEIVER_PORT = 2004
DESTINATIONS = cache1:2004:a,cache2:2004:a
MAX_DATAPOINTS_PER_MESSAGE = 500
MAX_QUEUE_SIZE = 10000
USE_FLOW_CONTROL = True</code></pre>
</div>
<p>For simplicity, we’re using the consistent-hashing method of sharding. The advantage to consistent-hasing is that Graphite will automatically split the metrics evenly across all carbon-cache instances. If you add another carbon-cache node, Graphite will start sending data to it. The disadvantage is that you have absolutely no control over which metric goes to which server. If you start with two nodes and then add a third node, Graphite will not automatically rebalance the data.</p>
<p>A couple key things to note:</p>
<ul>
<li>The RELAY_METHOD value is set to consistent-hashing</li>
<li>The LINE_RECEIVER_INTERFACE must be set to the IP address of the relay node, not localhost</li>
<li>The DESTINATIONS value must contain all of the target carbon-cache nodes</li>
<li>Each server listed in the DESTINATIONS option must include the name or ip address of a carbon-cache instance, the pickle-receiver port for the remote instance and the carbon-cache identifier. If you run multiple carbon-cache daemons on the remote server, the first instance will be identified as “a”, the second instance as “b”, etc.</li>
</ul>
<p><code>relay.conf</code></p>
<div>
<pre><code class='properties'>[default]
default = true
destinations = cache1,cache2</code></pre>
</div>
<p>This sample relay.conf shows us splitting the data automatically across two servers: cache1 and cache2.</p>
<h2>Carbon Cache</h2>
<p>On the carbon-cache servers, we need to configure the carbon-cache daemon to appropriately accept incoming data from the carbon-relay servers.</p>
<p><code>carbon.conf</code></p>
<div>
<pre><code class='properties'>[cache]
LOCAL_DATA_DIR = /opt/graphite/storage/whisper/
MAX_CACHE_SIZE = inf
MAX_UPDATES_PER_SECOND = 800
MAX_CREATES_PER_MINUTE = 100
LINE_RECEIVER_INTERFACE = y.y.y.y
LINE_RECEIVER_PORT = 2003
PICKLE_RECEIVER_INTERFACE = y.y.y.y
PICKLE_RECEIVER_PORT = 2004
CACHE_QUERY_INTERFACE = 127.0.0.1
CACHE_QUERY_PORT = 7002
LOG_UPDATES = False</code></pre>
</div>
<p>There are several critical settings here. First, the pickle receiver must be configured correctly to allow incoming data from the carbon-relay server. Second, the line receiver must be configured correctly to allow the the webapp to communicate with the other carbon-cache instances.</p>
<ul>
<li>LINE_RECEIVER_INTERFACE must be set to the local ip address (not 127.0.0.1)</li>
<li>LINE_RECEIVER_PORT must be set to 2003</li>
<li>PICKLE_RECEIVER_INTERFACE must be set to the local ip address (not 127.0.0.1)</li>
<li>PICKLE_RECEIVER_PORT must match the port we listed in the DESTINATION line in carbon.conf on the carbon-relay server</li>
</ul>
<p>The other key is configuring the local_settings.py config file for the webapp correctly:</p>
<div>
<pre><code class='properties'>CLUSTER_SERVERS = [ 'cache1','cache2' ]
MEMCACHE_HOSTS = [ 'memcache1.graphite:11211' ]</code></pre>
</div>
<p>The only mandatory piece of information in local_settings.py is CLUSTER_SERVERS, which must be a Python array containing strings that are the names (or ip address) of every carbon-cache server. You can optionally include an array of memcached instances to improve web performance dramatically. If you choose to utilize memcached, you can either run it locally on each carbon-cache instance or you can run a cluster of one or more memcached servers remotely. In the example above, we’re using a single memcached instance running on a remote server.</p>
<p>IMPORTANT NOTE: The local_settings.py file MUST be readable by the web server user. If you’re running Apache, this is typically the apache user. If the local_settings.py file is NOT readable, you will get very very strange errors.</p>
<h2>Firewall Rules</h2>
<p>To get this all working, specific ports must be open on the various firewalls. If you’re using Amazon EC2, your security groups will need to contain rules explicitly allowing incoming traffic on these ports:</p>
<h3>carbon-relay</h3>
<ol>
<li>Incoming on port 2003</li>
</ol>
<h3>carbon-cache/webapp</h3>
<ol>
<li>Incoming on port 2004 (messages from carbon-relay)</li>
<li>Incoming on port 2003 (requests for data from other carbon-cache servers)</li>
<li>Incoming on port 80 (web requests)</li>
<li>Incoming on port 11211 (if you’re running memcached locally)</li>
</ol>
]]></content>
</entry>
<entry>
<title type="html"><![CDATA[Testing Logstash grok filters]]></title>
<link href="http://bealetech.com/blog/2012/05/15/testing-logstash-grok-filters/"/>
<updated>2012-05-15T13:25:00-07:00</updated>
<id>http://bealetech.com/blog/2012/05/15/testing-logstash-grok-filters</id>
<content type="html"><![CDATA[<p>Logstash is an outstanding tool for collecting and parsing logfiles. In particular, the grok filter is extremely useful to extract specific pieces of data from your logfiles. Once you pull data out of the logfiles into fields, you can easily search on those fields. Unfortunately, I find the format for patterns in grok filter challenging to write correctly. If you mess up your pattern, you will end up with the dreaded “_grokparsefailure” tag on your log entry. What you need is a way to test your patterns before adding them to Logstash.</p>
<!-- more -->
<p>As it turns out, you can test your patterns using the grok ruby library. @a1cy demonstrated the basics to me, but I wanted to describe the full process.</p>
<h2>Requirements</h2>
<ul>
<li>Ruby 1.9+</li>
<li>jls-grok gem</li>
</ul>
<p>On my machine, I chose to install Ruby 1.9.2 via RVM, but you can use whatever technique you want. If you try to use Ruby 1.8.7, you will get a syntax error when you load the grok gem.</p>
<h2>Load Grok</h2>
<p>You want to use the “grok-pure” library, which is 100% ruby, rather than “grok”, which depends on a C library.</p>
<div>
<pre><code class='ruby'>require 'rubygems'
require 'grok-pure'
grok = Grok.new</code></pre>
</div>
<h2>Loading Patterns</h2>
<p>Since the grok filter in Logstash depends heavily on pattern files, I recommend you download the standard patterns from Github. Either the standard set for Logstash:</p>
<p><a href="https://github.com/logstash/logstash/tree/master/patterns">https://github.com/logstash/logstash/tree/master/patterns</a></p>
<p>Or you can use the ones with grok:</p>
<p><a href="https://github.com/jordansissel/ruby-grok/blob/master/patterns/pure-ruby">https://github.com/jordansissel/ruby-grok/blob/master/patterns/pure-ruby</a></p>
<p>Dump these into a directory so that you can load them with grok.</p>
<div>
<pre><code class='ruby'>grok.add_patterns_from_file("/path/to/patterns/grok-patterns")</code></pre>
</div>
<p>You can use the same technique to load your own pattern files. Or you can manually add patterns by name:</p>
<div>
<pre><code class='ruby'>grok.add_pattern("foo", ".*foo.*")
grok.add_pattern("bar", ".*bar.*")</code></pre>
</div>
<h2>Testing Patterns</h2>
<p>So, you have successfully loaded a set of patterns. How do you test something? Let’s take a sample log line from a MongoDB logfile:</p>
<p><code>Tue May 15 11:21:42 [conn1047685] moveChunk deleted: 7157</code></p>
<p>Let’s say we want to grab the date/time as well as the number of the deleted chunk. Unfortunately, the date/time format doesn’t match any of the stock patterns. We can build up a new date pattern and test it each step of the way:</p>
<div>
<pre><code class='ruby'>text = "Tue May 15 11:21:42 [conn1047685] moveChunk deleted: 7157"
pattern = '%{DAY}'
grok.compile(pattern)
grok.match(text)</code></pre>
</div>
<p>The last line returns false if the pattern fails to match the input text. If the pattern matches the input text, Grok.match() returns a Grok::Match object that contains a lot of useful information about the match. You can ask Grok to output the text it capture by using the captures() method:</p>
<div>
<pre><code class='ruby'>grok.match(text).captures()
=> {"DAY"=>["Tue"]}</code></pre>
</div>
<p>You can also test named captures, the same way you would use them in the Logstash grok filter:</p>
<div>
<pre><code class='ruby'>pattern = '%{DAY:day_of_week}'
grok.compile(pattern)
grok.match(text).captures()
=> {"DAY:day_of_week"=>["Tue"]}</code></pre>
</div>
<p>The full date/time pattern for this example looks like the following:</p>
<div>
<pre><code class='ruby'>pattern = '%{DAY} %{MONTH} %{MONTHDAY} %{TIME}'
grok.compile(pattern)
grok.match(text).capture()
=> {"DAY"=>["Tue"], "MONTH"=>["May"], "MONTHDAY"=>["15"], "TIME"=>["11:21:42"], "HOUR"=>["11"], "MINUTE"=>["21"], "SECOND"=>["42"]}</code></pre>
</div>
<p>Now let’s say we want to re-use this date/time pattern and still extract the chunk id from the log line. We can add a named pattern to the grok object manually and then reuse it, the same way we used patterns from the files:</p>
<div>
<pre><code class='ruby'>grok.add_pattern("MONGO_TIMESTAMP", '%{DAY} %{MONTH} %{MONTHDAY} %{TIME}')
grok.compile("%{MONGO_TIMESTAMP}")
pattern = '%{MONGO_TIMESTAMP:timestamp}'
grok.compile(pattern)
grok.match(text).captures()
=> {"MONGO_TIMESTAMP:timestamp"=>["Tue May 15 11:21:42"], "DAY"=>["Tue"], "MONTH"=>["May"], "MONTHDAY"=>["15"], "TIME"=>["11:21:42"], "HOUR"=>["11"], "MINUTE"=>["21"], "SECOND"=>["42"]}</code></pre>
</div>
<p>We still want the chunk id, so we can use additional patterns:</p>
<div>
<pre><code class='ruby'>pattern = '%{MONGO_TIMESTAMP:timestamp}%{GREEDYDATA} moveChunk deleted: %{NUMBER:chunk_id}'
grok.compile(pattern)
grok.match(text).captures()
=> {"MONGO_TIMESTAMP:timestamp"=>["Tue May 15 11:21:42"], "DAY"=>["Tue"], "MONTH"=>["May"], "MONTHDAY"=>["15"], "TIME"=>["11:21:42"], "HOUR"=>["11"], "MINUTE"=>["21"], "SECOND"=>["42"], "GREEDYDATA"=>[" [conn1047685]"], "NUMBER:chunk_id"=>["7157"], "BASE10NUM"=>["7157"]}</code></pre>
</div>
<p>Let’s say we wanted to grab that connection number inside the square brackets:</p>
<div>
<pre><code class='ruby'>pattern = '%{MONGO_TIMESTAMP:timestamp} \\[conn%{NUMBER:connection}\\] moveChunk deleted: %{NUMBER:chunk_id}'
grok.compile(pattern)
grok.match(text).captures()
=> {"MONGO_TIMESTAMP:timestamp"=>["Tue May 15 11:21:42"], "DAY"=>["Tue"], "MONTH"=>["May"], "MONTHDAY"=>["15"], "TIME"=>["11:21:42"], "HOUR"=>["11"], "MINUTE"=>["21"], "SECOND"=>["42"], "NUMBER:connection"=>["1047685"], "BASE10NUM"=>["1047685", "7157"], "NUMBER:chunk_id"=>["7157"]}</code></pre>
</div>
<h2>Full Example</h2>
<div>
<pre><code class='ruby'>require 'rubygems'
require 'grok-pure'
grok = Grok.new
text = "Tue May 15 11:21:42 [conn1047685] moveChunk deleted: 7157"
pattern = '%{MONGO_TIMESTAMP:timestamp} \\[conn%{NUMBER:connection}\\] moveChunk deleted: %{NUMBER:chunk_id}'
grok.compile(pattern)
grok.match(text).captures()
=> {"MONGO_TIMESTAMP:timestamp"=>["Tue May 15 11:21:42"], "DAY"=>["Tue"], "MONTH"=>["May"], "MONTHDAY"=>["15"], "TIME"=>["11:21:42"], "HOUR"=>["11"], "MINUTE"=>["21"], "SECOND"=>["42"], "NUMBER:connection"=>["1047685"], "BASE10NUM"=>["1047685", "7157"], "NUMBER:chunk_id"=>["7157"]}</code></pre>
</div>
<p>You can also find an ultra simple example in the grok example folder on Github: <a href="https://github.com/jordansissel/ruby-grok/blob/master/examples/test.rb">https://github.com/jordansissel/ruby-grok/blob/master/examples/test.rb</a>.</p>
]]></content>
</entry>
<entry>
<title type="html"><![CDATA[Why PostgreSQL?]]></title>
<link href="http://bealetech.com/blog/2010/10/14/why-postgresql/"/>
<updated>2010-10-14T22:49:00-07:00</updated>
<id>http://bealetech.com/blog/2010/10/14/why-postgresql</id>
<content type="html"><![CDATA[<p>Quick overview of what PostgreSQL brings to the table that is not available in MySQL.</p>
<!-- more -->
<ul>
<li>Uses MVCC for all tables providing:
<ul>
<li>Fully transactional including ACID compliance for consistency</li>
<li>Nested transactions</li>
</ul>
</li>
<li>SQL 2008 compliant</li>
<li>Foreign keys for any table</li>
<li>Advanced table partitioning</li>
<li>Highly sophisticated query planner/optimizer
<ul>
<li>Can split up a query for execution across multiple CPUs simultaneously</li>
<li>Collects internal statistics for adaptive query planning</li>
<li>Special genetic query optimizer for queries with large numbers of joins</li>
<li>Supports multiple indexes per table per query</li>
</ul>
</li>
<li>Advanced support for query & results caching</li>
<li>Hot/online backup</li>
<li>Point-in-time-recovery</li>
<li>Write-ahead logs for fault-tolerance</li>
<li>Tablespaces for controlling physical disk layout</li>
<li>Native asynchronous replication guaranteeing identical results on all machines. Supports both:
<ul>
<li>Streaming replication</li>
<li>Hot standby</li>
</ul>
</li>
<li>Partial indexes</li>
<li>Index creation/removal does not lock table</li>
<li>Full support for constraints</li>
<li>Transactional DDL - changes like table modifications can placed inside a transaction and rolled back</li>
</ul>
<p>Specific disadvantages to MySQL:</p>
<ul>
<li>Confusion with table types - MyISAM vs InnoDB</li>
<li>Designed to scale out not up - does not utilize larger numbers of cores efficiently and cannot spread queries across cores</li>
<li>Hot backup of is difficult for databases containing both InnoDB and MyISAM</li>
<li>Replication is mediocre and error prone</li>
<li>InnoDB stores the data with the primary key, so any queries using secondary indices are slower</li>
<li>Subqueries not well optimized</li>
<li>Only uses a single index per table per query</li>
<li>Index creation/removal requires an exclusive write lock</li>
<li>MyISAM only offers table level locking which causes severe performance degradation under heavy concurrency</li>
<li>Limited support for constraints</li>
<li>No transactional DDL - changes like table modifications are automatically committed and cannot be rolled back</li>
</ul>
<p>MySQL offers the following advantages over PostgreSQL:</p>
<ul>
<li>MyISAM tables can offer better read performance, specifically for simple SELECT queries, but at the cost of no support for transactions, foreign keys or data guarantees</li>
<li>COUNT(*) on MyISAM is very fast and slow on PostgreSQL</li>
<li>INSERT IGNORE and INSERT…ON DUPLICATE UPDATE</li>
</ul>
]]></content>
</entry>
<entry>
<title type="html"><![CDATA[Different content in Rails based on UserAgent]]></title>
<link href="http://bealetech.com/blog/2010/08/11/different-content-in-rails-based-on-useragent/"/>
<updated>2010-08-11T10:57:00-07:00</updated>
<id>http://bealetech.com/blog/2010/08/11/different-content-in-rails-based-on-useragent</id>
<content type="html"><![CDATA[<p>I was recently working on a website built using Rails that needed to render different content for certain user agents. Specifically, we needed simpler versions of certain pages for BlackBerry devices. Here’s how I accomplished it.</p>
<!-- more -->
<p>First, I added a new mime-type for BlackBerry by adding the following line to <code>config/initializers/mime_types.rb</code>:</p>
<figure class='code'><figcaption><span>mime_types.rb </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='ruby'><span class='line'><span class="ss">Mime</span><span class="p">:</span><span class="ss">:Type</span><span class="o">.</span><span class="n">register_alias</span> <span class="s2">"text/html"</span><span class="p">,</span> <span class="ss">:blackberry</span>
</span></code></pre></td></tr></table></div></figure>
<p>Next, I added two utility methods to <code>app/controllers/application.rb</code>:</p>
<figure class='code'><figcaption><span>application.rb </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>
</pre></td><td class='code'><pre><code class='ruby'><span class='line'><span class="c1"># Checks UserAgent</span>
</span><span class='line'><span class="k">def</span> <span class="nf">is_blackberry?</span>
</span><span class='line'> <span class="n">ua</span> <span class="o">=</span> <span class="n">request</span><span class="o">.</span><span class="n">user_agent</span>
</span><span class='line'> <span class="k">return</span> <span class="kp">false</span> <span class="k">if</span> <span class="n">ua</span><span class="o">.</span><span class="n">nil?</span>
</span><span class='line'> <span class="k">return</span> <span class="kp">false</span> <span class="k">if</span> <span class="o">!</span> <span class="n">ua</span><span class="o">.</span><span class="n">downcase</span><span class="o">.</span><span class="n">index</span><span class="p">(</span><span class="s1">'blackberry'</span><span class="p">)</span>
</span><span class='line'>
</span><span class='line'> <span class="c1"># Don't call the BlackBerry 9800 a BlackBerry, since it has a modern browser</span>
</span><span class='line'> <span class="c1"># based on WebKit:</span>
</span><span class='line'> <span class="c1"># Mozilla/5.0 (BlackBerry; U; BlackBerry 9800; en) AppleWebKit/534.1+ (KHTML, Like Gecko) Version/6.0.0.141 Mobile Safari/534.1+</span>
</span><span class='line'> <span class="k">return</span> <span class="kp">false</span> <span class="k">if</span> <span class="n">ua</span><span class="o">.</span><span class="n">downcase</span><span class="o">.</span><span class="n">index</span><span class="p">(</span><span class="s1">'webkit'</span><span class="p">)</span>
</span><span class='line'>
</span><span class='line'> <span class="c1"># Must be a BlackBerry!</span>
</span><span class='line'> <span class="kp">true</span>
</span><span class='line'><span class="k">end</span>
</span><span class='line'>
</span><span class='line'><span class="c1"># Sets the respond_to format to blackberry if blackberry</span>
</span><span class='line'><span class="k">def</span> <span class="nf">set_blackberry_format</span>
</span><span class='line'> <span class="k">if</span> <span class="o">!</span><span class="n">request</span><span class="o">.</span><span class="n">xhr?</span> <span class="o">&</span><span class="n">amp</span><span class="p">;</span><span class="o">&</span><span class="n">amp</span><span class="p">;</span> <span class="n">is_blackberry?</span>
</span><span class='line'> <span class="n">request</span><span class="o">.</span><span class="n">format</span> <span class="o">=</span> <span class="ss">:blackberry</span>
</span><span class='line'> <span class="k">end</span>
</span><span class='line'><span class="k">end</span>
</span></code></pre></td></tr></table></div></figure>
<p>With that in hand, it’s easy to render BlackBerry specific content on specific pages:</p>
<figure class='code'> <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>
</pre></td><td class='code'><pre><code class='ruby'><span class='line'><span class="n">set_blackberry_format</span>
</span><span class='line'><span class="n">respond_to</span> <span class="k">do</span> <span class="o">|</span><span class="nb">format</span><span class="o">|</span>
</span><span class='line'> <span class="nb">format</span><span class="o">.</span><span class="n">blackberry</span>
</span><span class='line'> <span class="nb">format</span><span class="o">.</span><span class="n">html</span>
</span><span class='line'> <span class="nb">format</span><span class="o">.</span><span class="n">js</span> <span class="p">{</span> <span class="n">render</span> <span class="ss">:layout</span> <span class="o">=&</span><span class="n">gt</span><span class="p">;</span> <span class="kp">false</span> <span class="p">}</span>
</span><span class='line'><span class="k">end</span>
</span></code></pre></td></tr></table></div></figure>
]]></content>
</entry>
<entry>
<title type="html"><![CDATA[Tomcat init script for Ubuntu]]></title>
<link href="http://bealetech.com/blog/2010/07/25/tomcat-init-script-for-ubuntu/"/>
<updated>2010-07-25T13:06:00-07:00</updated>
<id>http://bealetech.com/blog/2010/07/25/tomcat-init-script-for-ubuntu</id>
<content type="html"><![CDATA[<p>Recently I spent some time working on improving my init scripts for Tomcat 6.x in a production environment running Ubuntu. One of the major problems we had encountered was that occasionally Tomcat refuses to shut down completely and requires a <code>kill -9</code> to stop it. The standard init scripts I had seen didn’t solve this problem at all.</p>
<!-- more -->
<p><a href="http://www.laliluna.de/">Laliluna</a> has a great <a href="http://www.laliluna.de/articles/tomcat-startup-script-linux.html">article</a> that focuses on RedHat, CentOS and Fedora. Unfortunately, their scripts didn’t work correctly under Ubuntu 8.04 LTS. As a result, I spent some time modifying their scripts to get them to work correctly under Unbuntu. Many thanks to Laliluna for doing the heavy work.</p>
<p>Without any further ado, here’s what I put together:</p>
<figure class='code'><figcaption><span>/etc/init.dtomcat </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>
<span class='line-number'>50</span>
<span class='line-number'>51</span>
<span class='line-number'>52</span>
<span class='line-number'>53</span>
<span class='line-number'>54</span>
<span class='line-number'>55</span>
<span class='line-number'>56</span>
<span class='line-number'>57</span>
<span class='line-number'>58</span>
<span class='line-number'>59</span>
<span class='line-number'>60</span>
<span class='line-number'>61</span>
<span class='line-number'>62</span>
<span class='line-number'>63</span>
<span class='line-number'>64</span>
<span class='line-number'>65</span>
<span class='line-number'>66</span>
<span class='line-number'>67</span>
<span class='line-number'>68</span>
<span class='line-number'>69</span>
<span class='line-number'>70</span>
<span class='line-number'>71</span>
<span class='line-number'>72</span>
<span class='line-number'>73</span>
<span class='line-number'>74</span>
<span class='line-number'>75</span>
<span class='line-number'>76</span>
<span class='line-number'>77</span>
<span class='line-number'>78</span>
<span class='line-number'>79</span>
<span class='line-number'>80</span>
<span class='line-number'>81</span>
<span class='line-number'>82</span>
<span class='line-number'>83</span>
<span class='line-number'>84</span>
<span class='line-number'>85</span>
<span class='line-number'>86</span>
<span class='line-number'>87</span>
<span class='line-number'>88</span>
<span class='line-number'>89</span>
<span class='line-number'>90</span>
<span class='line-number'>91</span>
<span class='line-number'>92</span>
<span class='line-number'>93</span>
<span class='line-number'>94</span>
<span class='line-number'>95</span>
<span class='line-number'>96</span>
<span class='line-number'>97</span>
<span class='line-number'>98</span>
<span class='line-number'>99</span>
<span class='line-number'>100</span>
<span class='line-number'>101</span>
<span class='line-number'>102</span>
<span class='line-number'>103</span>
<span class='line-number'>104</span>
<span class='line-number'>105</span>
<span class='line-number'>106</span>