{"id":2202,"date":"2011-04-06T11:12:43","date_gmt":"2011-04-06T15:12:43","guid":{"rendered":"http:\/\/www.gubatron.com\/blog\/?p=2202"},"modified":"2011-04-06T11:12:43","modified_gmt":"2011-04-06T15:12:43","slug":"have-the-latest-haproxy-as-a-ubuntu-service","status":"publish","type":"post","link":"https:\/\/www.gubatron.com\/blog\/have-the-latest-haproxy-as-a-ubuntu-service\/","title":{"rendered":"Have the latest HAProxy as a Ubuntu Service"},"content":{"rendered":"<p>So you need to use HAProxy and you love the convenience of binary packages on repos, but when you install the version HAProxy available in the repos you realize that it is way too old for what you need.<\/p>\n<p>Then you download the latest HAProxy, compile it, configure it, but it&#8217;s a bit of a pain in the ass to not have the convenience of having haproxy be automatically restarted as a service like those available on \/etc\/init.d<\/p>\n<p><strong>This post teaches you how to have haproxy as a Ubuntu\/Debian service.<\/strong><\/p>\n<p>First copy or symlink this script to your \/etc\/init.d\/ folder (you&#8217;ll need root permissions to do this)<\/p>\n<p>[bash]<br \/>\n#!\/usr\/bin\/env bash<br \/>\n# haproxyd<br \/>\n# Script to start|stop|restart haproxy from \/etc\/init.d\/<br \/>\n# By Gubatron.<\/p>\n<p>HAPROXY_PATH=\/path\/to\/haproxy-X.Y.Z<br \/>\nHAPROXY_DAEMON=$HAPROXY_PATH\/haproxy<\/p>\n<p>test -x $HAPROXY_DAEMON || exit 0<\/p>\n<p>set -e<\/p>\n<p>function getHaproxyPID() {<br \/>\n  PID=`ps aux | grep &#8216;haproxy -f&#8217; | grep -v &quot;grep&quot; | awk &#8216;{ print $2 }&#8217;`<br \/>\n}<\/p>\n<p>case $1 in<br \/>\n  start)<br \/>\n        echo &quot;Starting haproxy&#8230;&quot;<br \/>\n        $HAPROXY_DAEMON -f $HAPROXY_PATH\/haproxy.cfg<br \/>\n        ;;<br \/>\n  restart)<br \/>\n        echo &quot;Hot restart of haproxy&quot;<br \/>\n        getHaproxyPID<br \/>\n        COMMAND=&quot;$HAPROXY_DAEMON -f $HAPROXY_PATH\/haproxy.cfg -sf $PID&quot;<br \/>\n        echo $COMMAND<br \/>\n        `$COMMAND`<br \/>\n        ;;<br \/>\n  stop)<br \/>\n        echo &quot;Stopping haproxy&quot;<br \/>\n        getHaproxyPID<br \/>\n        COMMAND=&quot;kill -9 $PID&quot;<br \/>\n        echo $COMMAND<br \/>\n        `$COMMAND`<br \/>\n        ;;<br \/>\n  *)<br \/>\n        echo &quot;Usage: haproxyd {start|restart|stop}&quot; &gt;&amp;2<br \/>\n        exit 1<br \/>\n        ;;<br \/>\nesac<\/p>\n<p>exit 0<br \/>\n[\/bash]<\/p>\n<p>This script, on it&#8217;s own can be used as<br \/>\n[bash]<br \/>\n.\/haproxyd start<br \/>\n.\/haproxyd restart<br \/>\n.\/haproxyd stop<br \/>\n[\/bash]<\/p>\n<p>But you want this script registered on all the right runlevels of the operating system.<\/p>\n<p>With Ubuntu\/Debian there&#8217;s a utility called <a href=\"http:\/\/manpages.ubuntu.com\/manpages\/hardy\/man8\/update-rc.d.8.html\" target=\"_blank\">update-rc.d<\/a> to register \/etc\/init.d\/ scripts very easily.<\/p>\n<p>Once the script above is available on \/etc\/init.d do the following<\/p>\n<p>[bash]<br \/>\ncd \/etc\/init.d<br \/>\nsudo update-rc.d haproxyd defaults<br \/>\n[\/bash]<\/p>\n<p>The script should now be registered on all the right runlevels and you should be able to invoke it as a service like<\/p>\n<p>[bash]<br \/>\nsudo service haproxyd &lt;command&gt;<br \/>\n[\/bash] <\/p>\n","protected":false},"excerpt":{"rendered":"<p>So you need to use HAProxy and you love the convenience of binary packages on repos, but when you install the version HAProxy available in the repos you realize that it is way too old for what you need. Then you download the latest HAProxy, compile it, configure it, but it&#8217;s a bit of a [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":false,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2}},"categories":[15,43],"tags":[],"class_list":["post-2202","post","type-post","status-publish","format-standard","hentry","category-code","category-linux"],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"jetpack_shortlink":"https:\/\/wp.me\/p5Unzf-zw","jetpack-related-posts":[{"id":2745,"url":"https:\/\/www.gubatron.com\/blog\/ubuntu-mongodb-wont-start-fixed\/","url_meta":{"origin":2202,"position":0},"title":"Ubuntu: mongodb won&#8217;t start [FIXED]","author":"gubatron","date":"May 23, 2012","format":false,"excerpt":"So you decided to change the default location of your mongodb data path on mongodb.conf but mongo won't start and you get an error similar to this [bash] Wed May 23 04:17:35 [initandlisten] MongoDB starting : pid=1214 port=27017 dbpath=\/media\/ebs\/data 64-bit host=domU-12-31-38-00-78-DB Wed May 23 04:17:35 [initandlisten] db version v2.0.4, pdfile\u2026","rel":"","context":"In \"mongo\"","block_context":{"text":"mongo","link":"https:\/\/www.gubatron.com\/blog\/tag\/mongo\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":3164,"url":"https:\/\/www.gubatron.com\/blog\/how-to-have-a-play-framework-app-autostart-during-boot-on-elastic-beanstalk-centos-ec2-instances\/","url_meta":{"origin":2202,"position":1},"title":"How to have a Play framework app autostart during boot on Elastic Beanstalk CentOS ec2 instances","author":"gubatron","date":"September 27, 2013","format":false,"excerpt":"So you've created an Elastic Beanstalk environment, you have a play framework distribution which you've created using play dist (either on your local environment, or right there on the server, whatever you prefer) play dist outputs a my-app-1.0.zip file which has a self-contained version of your app with all the\u2026","rel":"","context":"In &quot;Code&quot;","block_context":{"text":"Code","link":"https:\/\/www.gubatron.com\/blog\/category\/code\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":2081,"url":"https:\/\/www.gubatron.com\/blog\/ubuntu-wicd-network-manager-connection-failed-bad-password-issue-solved\/","url_meta":{"origin":2202,"position":2},"title":"Ubuntu: WiCD Network Manager &#8220;Connection Failed: Bad Password&#8221; [SOLVED]","author":"gubatron","date":"October 29, 2010","format":false,"excerpt":"If you're familiar with correctly entering your WPA2 password after an Ubuntu update and now your Netbook won't connect using WiCD, I got the solution that worked for me. Uninstall network-manager and restart WiCD Open a terminal and type: [shell] $ sudo apt-get remove network-manager ... $ sudo \/etc\/init.d\/wicd restart\u2026","rel":"","context":"In &quot;Linux&quot;","block_context":{"text":"Linux","link":"https:\/\/www.gubatron.com\/blog\/category\/linux\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":1939,"url":"https:\/\/www.gubatron.com\/blog\/solved-eclipse-cant-see-my-android-device-on-ubuntu\/","url_meta":{"origin":2202,"position":3},"title":"[SOLVED] Eclipse can&#8217;t see my Android Device on Ubuntu","author":"gubatron","date":"May 28, 2010","format":false,"excerpt":"Are you seeing this on eclipse when you plug your Android device to your Ubuntu box? Serial Number: ?????????? AVD Name: N\/A Target: unknown State: ?? Here's the solution: 1. Create a script to fix this next time it happens, let's call it \"android_device_reset\" and save it on a folder\u2026","rel":"","context":"In &quot;Android&quot;","block_context":{"text":"Android","link":"https:\/\/www.gubatron.com\/blog\/category\/android\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":3899,"url":"https:\/\/www.gubatron.com\/blog\/how-to-suppress-useless-mod_openssl-lighttpd-error-messages-from-var-log-syslog-in-ubuntu\/","url_meta":{"origin":2202,"position":4},"title":"[linux\/ubuntu] How to suppress useless mod_openssl\/lighttpd error messages from appearing in \/var\/log\/syslog","author":"gubatron","date":"August 7, 2020","format":false,"excerpt":"Sometimes you have a bunch of useless errors creating unnecessary disk I\/O on your server, disk I\/O that should be used towards serving your user's requests efficiently. In this case a site running on lighttpd keeps logging several times per second the following message, creating too much noise and making\u2026","rel":"","context":"In &quot;Linux&quot;","block_context":{"text":"Linux","link":"https:\/\/www.gubatron.com\/blog\/category\/linux\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":3453,"url":"https:\/\/www.gubatron.com\/blog\/command-line-speed-test-see-how-fast-is-your-servers-connection\/","url_meta":{"origin":2202,"position":5},"title":"command line speed test, see how fast is your server&#8217;s connection","author":"gubatron","date":"January 6, 2016","format":false,"excerpt":"Save the following script in a file called speed_test #!\/bin\/bash # Requirements # sudo apt-get install lftp iperf lftp -e 'pget http:\/\/releases.ubuntu.com\/14.04.3\/ubuntu-14.04.3-desktop-amd64.iso; exit; ' make sure the file is executable: sudo chmod +x speed_test Once you have installed lftp and iperf make sure you have the script somewhere in your\u2026","rel":"","context":"In &quot;Code&quot;","block_context":{"text":"Code","link":"https:\/\/www.gubatron.com\/blog\/category\/code\/"},"img":{"alt_text":"","src":"https:\/\/i0.wp.com\/www.gubatron.com\/blog\/wp-content\/uploads\/2016\/01\/Fiber-optics.jpg?fit=892%2C538&ssl=1&resize=350%2C200","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/www.gubatron.com\/blog\/wp-content\/uploads\/2016\/01\/Fiber-optics.jpg?fit=892%2C538&ssl=1&resize=350%2C200 1x, https:\/\/i0.wp.com\/www.gubatron.com\/blog\/wp-content\/uploads\/2016\/01\/Fiber-optics.jpg?fit=892%2C538&ssl=1&resize=525%2C300 1.5x, https:\/\/i0.wp.com\/www.gubatron.com\/blog\/wp-content\/uploads\/2016\/01\/Fiber-optics.jpg?fit=892%2C538&ssl=1&resize=700%2C400 2x"},"classes":[]}],"_links":{"self":[{"href":"https:\/\/www.gubatron.com\/blog\/wp-json\/wp\/v2\/posts\/2202","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.gubatron.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.gubatron.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.gubatron.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.gubatron.com\/blog\/wp-json\/wp\/v2\/comments?post=2202"}],"version-history":[{"count":0,"href":"https:\/\/www.gubatron.com\/blog\/wp-json\/wp\/v2\/posts\/2202\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.gubatron.com\/blog\/wp-json\/wp\/v2\/media?parent=2202"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.gubatron.com\/blog\/wp-json\/wp\/v2\/categories?post=2202"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.gubatron.com\/blog\/wp-json\/wp\/v2\/tags?post=2202"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}