{"id":3164,"date":"2013-09-27T17:33:30","date_gmt":"2013-09-27T17:33:30","guid":{"rendered":"http:\/\/www.gubatron.com\/blog\/?p=3164"},"modified":"2019-04-25T13:18:58","modified_gmt":"2019-04-25T13:18:58","slug":"how-to-have-a-play-framework-app-autostart-during-boot-on-elastic-beanstalk-centos-ec2-instances","status":"publish","type":"post","link":"https:\/\/www.gubatron.com\/blog\/how-to-have-a-play-framework-app-autostart-during-boot-on-elastic-beanstalk-centos-ec2-instances\/","title":{"rendered":"How to have a Play framework app autostart during boot on Elastic Beanstalk CentOS ec2 instances"},"content":{"rendered":"<p>So you&#8217;ve created an Elastic Beanstalk environment, you have a play framework distribution which you&#8217;ve created using <strong>play dist<\/strong> (either on your local environment, or right there on the server, whatever you prefer)<\/p>\n<p><strong>play dist<\/strong> outputs a <strong>my-app-1.0.zip<\/strong> file which has a self-contained version of your app with all the necessary libraries and a <strong>start<\/strong> script.<\/p>\n<p>Afer you unzip it, you end up with a <strong>my-app-1.0\/lib\/<\/strong> folder and a start script.<\/p>\n<p>[pastacode lang=&#8221;bash&#8221; manual=&#8221;%5Bec2-user%40ip-10-235-8-106%20bullq-1.0%5D%24%20ls%20-l%0Atotal%2024%0Adrwxrwxr-x%202%20ec2-user%20ec2-user%204096%20Sep%2027%2015%3A35%20lib%0A-rwxrwxr-x%201%20ec2-user%20ec2-user%204328%20Sep%2027%2015%3A35%20start&#8221; message=&#8221;&#8221; highlight=&#8221;&#8221; provider=&#8221;manual&#8221;\/]<\/p>\n<p>Make sure it&#8217;s executable by using <strong>chmod +x start<\/strong> on the start script.<\/p>\n<p>So now, this is all in the first ec2 instance of your elastic beanstalk environment, if you&#8217;re like me and you&#8217;ve used ubuntu\/debian for your server management things can be slightly different here, since Amazon preferred CentOS for their default image, and here I&#8217;ll show you how to make your play app auto start when the server boots because you want every new machine that may be instanciated to have your app installed and to start the service as soon as the machine is up.<\/p>\n<p><strong>Create a \/etc\/init.d\/myappd script<\/strong><br \/>\n(I&#8217;m using &#8216;myapp&#8217; here as an example, your app can be named whatever is named, so replace accordingly)<\/p>\n<p>[pastacode lang=&#8221;bash&#8221; manual=&#8221;%23!%2Fusr%2Fbin%2Fenv%20bash%0A%23myappd%0A%23Script%20to%20start%7Cstop%7Crestart%20myappd%20from%20%2Fetc%2Finit.d%2F%0A%23By%20Gubatron%20%E2%80%93%20%40gubatron%20%E2%80%93%20gubatron%40gmail.com%0A%0A%23replace%20accordingly%20in%20these%20variables%20%E2%80%98myapp%E2%80%99%20for%20the%20name%20of%20your%20app%0APID_FILE%3D%2Fhome%2Fec2-user%2Fmyapp%2Fdist%2Fmyapp-1.0%2FRUNNING_PID%0ADAEMON_NAME%3Dmyappd%0ADAEMON_PATH%3D%2Fhome%2Fec2-user%2Fmyapp%0ADAEMON%3D%24DAEMON_PATH%2Fdist%2Fmyapp-1.0%2Fstart%0A%0Atest%20-x%20%24DAEMON%20%7C%7C%20exit%200%0A%0Aset%20-e%0A%0Afunction%20killDAEMON()%20%7B%0Aecho%20%E2%80%9Cstart%20kill%20daemon%E2%80%9D%0Akill%20-9%20cat%20%2Fhome%2Fec2-user%2Fbullq%2Fdist%2Fbullq-1.0%2FRUNNING_PID%0Aecho%20%E2%80%9Cend%20kill%20daemon%E2%80%9D%0A%7D%0A%0Afunction%20removePIDFile()%20%7B%0Aif%20%5B%20-e%20%24PID_FILE%20%5D%0Athen%0Arm%20-f%20%24PID_FILE%0Afi%0A%7D%0A%0Acase%20%241%20in%0Astart)%0AremovePIDFile%0Aecho%20%E2%80%9CStarting%20%24DAEMON_NAME%E2%80%A6%20%24DAEMON%E2%80%9D%0Anohup%20%24DAEMON%20%26%0A%3B%3B%0Arestart)%0Aecho%20%E2%80%9CHot%20restart%20of%20%24DAEMON_NAME%E2%80%9D%0AkillDAEMON%0AremovePIDFile%0ACOMMAND%3D%E2%80%9Dnohup%20%24DAEMON%20%26%E2%80%9D%3B%0Aecho%20%24COMMAND%0A%24COMMAND%0Arm%20-f%20%24PID_FILE%0A%3B%3B%0Astop)%0Aecho%20%E2%80%9CStopping%20%24DAEMON_NAME%E2%80%9D%0AkillDAEMON%0AremovePIDFile%0A%3B%3B%0A*)%0Aecho%20%E2%80%9CUsage%3A%20%24DAEMON_NAME%20%7Bstart%7Crestart%7Cstop%7D%E2%80%9D%20%3E%262%0Aexit%201%0A%3B%3B%0Aesac%0A%0Aexit%200&#8243; message=&#8221;&#8221; highlight=&#8221;&#8221; provider=&#8221;manual&#8221;\/]<\/p>\n<p>&nbsp;<\/p>\n<p><strong>Wire it to autostart<\/strong><\/p>\n<p>The simplest way I found to have this script start when the server would boot was to add it at the end of the<br \/>\n<strong>\/etc\/rc.local<\/strong> file. (In ubuntu you&#8217;d register the new script with the upate-rc.d command)<\/p>\n<p>[pastacode lang=&#8221;bash&#8221; manual=&#8221;%23!%2Fbin%2Fsh%0A%23%0AThis%20script%20will%20be%20executed%20after%20all%20the%20other%20init%20scripts.%0AYou%20can%20put%20your%20own%20initialization%20stuff%20in%20here%20if%20you%20don%E2%80%99t%0Awant%20to%20do%20the%20full%20Sys%20V%20style%20init%20stuff.%0A%0Atouch%20%2Fvar%2Flock%2Fsubsys%2Flocal%0A%0A%2Fetc%2Finit.d%2Fmyappd%20start&#8221; message=&#8221;&#8221; highlight=&#8221;&#8221; provider=&#8221;manual&#8221;\/]<\/p>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>So you&#8217;ve created an Elastic Beanstalk environment, you have a play framework distribution which you&#8217;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 necessary libraries and a start [&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":[1346,1301,1344,1156,1347,276,296,1157,1343,1345,1449,1315,1341,1342,1027],"class_list":["post-3164","post","type-post","status-publish","format-standard","hentry","category-code","category-linux","tag-etcrc-local","tag-amazon-web-services","tag-autostart","tag-aws","tag-centos","tag-cloud","tag-configuration","tag-ec2","tag-elastic-beans","tag-init-d","tag-linux","tag-management","tag-play","tag-play-framework","tag-ubuntu"],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"jetpack_shortlink":"https:\/\/wp.me\/p5Unzf-P2","jetpack-related-posts":[{"id":3543,"url":"https:\/\/www.gubatron.com\/blog\/tutorial-how-to-pause-an-aws-elastic-beanstalk-environment-using-the-dashboard\/","url_meta":{"origin":3164,"position":0},"title":"[TUTORIAL] HOW TO PAUSE AN AWS ELASTIC BEANSTALK ENVIRONMENT USING THE DASHBOARD","author":"gubatron","date":"June 23, 2016","format":false,"excerpt":"So you have set up a test elastic beanstalk environment because you don't want to put at risk your production elastic bean. You don't want to pay for the time you're not using it, and there's no freaking \"Pause Environment\" option. all you can do is \"Terminate Environment\"? but then\u2026","rel":"","context":"In &quot;Code&quot;","block_context":{"text":"Code","link":"https:\/\/www.gubatron.com\/blog\/category\/code\/"},"img":{"alt_text":"aws-elasticbean-no-pause-option","src":"https:\/\/i0.wp.com\/www.gubatron.com\/blog\/wp-content\/uploads\/2016\/06\/Screen-Shot-2016-06-23-at-1.54.48-PM-219x300.png?resize=350%2C200","width":350,"height":200},"classes":[]},{"id":3213,"url":"https:\/\/www.gubatron.com\/blog\/aws-troubleshooting-how-to-fix-a-broken-ebs-volume-bad-superblock-on-xfs\/","url_meta":{"origin":3164,"position":1},"title":"AWS troubleshooting: how to fix a broken EBS volume (bad superblock on xfs)","author":"gubatron","date":"January 19, 2014","format":false,"excerpt":"As great as EBS volumes are on Amazon Web Services, they can break and not ever mount again, even though your data could still be there intact, a simple corruption on the filesystem structure can cause a lot of damage. On this post I teach you how to move all\u2026","rel":"","context":"In &quot;Geeklife&quot;","block_context":{"text":"Geeklife","link":"https:\/\/www.gubatron.com\/blog\/category\/geeklife\/"},"img":{"alt_text":"","src":"https:\/\/i0.wp.com\/www.gubatron.com\/blog\/wp-content\/uploads\/2014\/01\/car-longshot2.jpg?fit=720%2C482&ssl=1&resize=350%2C200","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/www.gubatron.com\/blog\/wp-content\/uploads\/2014\/01\/car-longshot2.jpg?fit=720%2C482&ssl=1&resize=350%2C200 1x, https:\/\/i0.wp.com\/www.gubatron.com\/blog\/wp-content\/uploads\/2014\/01\/car-longshot2.jpg?fit=720%2C482&ssl=1&resize=525%2C300 1.5x, https:\/\/i0.wp.com\/www.gubatron.com\/blog\/wp-content\/uploads\/2014\/01\/car-longshot2.jpg?fit=720%2C482&ssl=1&resize=700%2C400 2x"},"classes":[]},{"id":2767,"url":"https:\/\/www.gubatron.com\/blog\/ubuntu-packages-for-a-kick-ass-web-server\/","url_meta":{"origin":3164,"position":2},"title":"ubuntu packages for a kick ass web server","author":"gubatron","date":"September 7, 2012","format":false,"excerpt":"Copy and paste the following list on a file, say \"packages.txt\". To install all just do: sudo apt-get install $(cat packages.txt) accountsservice acpid adduser ant ant-optional apache2-utils apparmor apport apport-symptoms apt apt-transport-https apt-utils apt-xapian-index aptitude at base-files base-passwd bash bash-completion bc bind9-host bsdmainutils bsdutils busybox-initramfs busybox-static byobu bzip2 ca-certificates ca-certificates-java\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":4073,"url":"https:\/\/www.gubatron.com\/blog\/remotely-code-signing-windows-apps-using-aws-virtual-servers-and-a-physical-usb-key\/","url_meta":{"origin":3164,"position":3},"title":"Remotely Code Signing Windows Apps Using AWS Virtual Servers and a Physical USB Key","author":"gubatron","date":"April 25, 2024","format":false,"excerpt":"As a developer, you may find yourself in a situation where you need to code sign your Windows applications using a physical USB signing key, but you don't have direct access to a Windows machine. Fortunately, with the power of cloud computing and remote desktop technology, you can set up\u2026","rel":"","context":"Similar post","block_context":{"text":"Similar post","link":""},"img":{"alt_text":"","src":"https:\/\/i0.wp.com\/www.gubatron.com\/blog\/wp-content\/uploads\/2024\/04\/GMBy5ZwWIAAnizc.jpeg?fit=1024%2C1024&ssl=1&resize=350%2C200","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/www.gubatron.com\/blog\/wp-content\/uploads\/2024\/04\/GMBy5ZwWIAAnizc.jpeg?fit=1024%2C1024&ssl=1&resize=350%2C200 1x, https:\/\/i0.wp.com\/www.gubatron.com\/blog\/wp-content\/uploads\/2024\/04\/GMBy5ZwWIAAnizc.jpeg?fit=1024%2C1024&ssl=1&resize=525%2C300 1.5x, https:\/\/i0.wp.com\/www.gubatron.com\/blog\/wp-content\/uploads\/2024\/04\/GMBy5ZwWIAAnizc.jpeg?fit=1024%2C1024&ssl=1&resize=700%2C400 2x"},"classes":[]},{"id":3977,"url":"https:\/\/www.gubatron.com\/blog\/how-to-resize-aws-ec2-ebs-root-partition-without-rebooting-in-3-steps\/","url_meta":{"origin":3164,"position":4},"title":"How to resize AWS ec2 ebs root partition without rebooting in 3 steps","author":"gubatron","date":"September 14, 2022","format":false,"excerpt":"Go to the AWS EBS dashboard and modify the volume size. Might be good to create a snapshot of it for safety but haven't really failed ever doing this. # 1. Check the device of your partition $ sudo lsblk NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINTS loop0 7:0 0\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\/2022\/09\/xai-tmp-imgen-db8aab31-34e5-4be7-b882-a7e87a2836f9.jpg?fit=1091%2C655&ssl=1&resize=350%2C200","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/www.gubatron.com\/blog\/wp-content\/uploads\/2022\/09\/xai-tmp-imgen-db8aab31-34e5-4be7-b882-a7e87a2836f9.jpg?fit=1091%2C655&ssl=1&resize=350%2C200 1x, https:\/\/i0.wp.com\/www.gubatron.com\/blog\/wp-content\/uploads\/2022\/09\/xai-tmp-imgen-db8aab31-34e5-4be7-b882-a7e87a2836f9.jpg?fit=1091%2C655&ssl=1&resize=525%2C300 1.5x, https:\/\/i0.wp.com\/www.gubatron.com\/blog\/wp-content\/uploads\/2022\/09\/xai-tmp-imgen-db8aab31-34e5-4be7-b882-a7e87a2836f9.jpg?fit=1091%2C655&ssl=1&resize=700%2C400 2x, https:\/\/i0.wp.com\/www.gubatron.com\/blog\/wp-content\/uploads\/2022\/09\/xai-tmp-imgen-db8aab31-34e5-4be7-b882-a7e87a2836f9.jpg?fit=1091%2C655&ssl=1&resize=1050%2C600 3x"},"classes":[]},{"id":3127,"url":"https:\/\/www.gubatron.com\/blog\/cant-ssh-to-ec2-ubuntu-instance-etcfstab-breaks-bootup-due-to-missing-ebs-volume-solved\/","url_meta":{"origin":3164,"position":5},"title":"can&#8217;t ssh to ec2 ubuntu instance, \/etc\/fstab breaks bootup due to missing ebs volume [SOLVED]","author":"gubatron","date":"August 21, 2013","format":false,"excerpt":"So the \/etc\/fstab file on your root volume looked like this LABEL=cloudimg-rootfs \/ ext4 defaults 0 0 \/dev\/xvdf \/mnt\/backups auto defaults,comment=cloudconfig 0 2 by mistake you deleted the ebs volume that you had mounted on \/mnt\/backups (or whatever folder) and you restarted your ubuntu instance not knowing that if 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":[]}],"_links":{"self":[{"href":"https:\/\/www.gubatron.com\/blog\/wp-json\/wp\/v2\/posts\/3164","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=3164"}],"version-history":[{"count":6,"href":"https:\/\/www.gubatron.com\/blog\/wp-json\/wp\/v2\/posts\/3164\/revisions"}],"predecessor-version":[{"id":3792,"href":"https:\/\/www.gubatron.com\/blog\/wp-json\/wp\/v2\/posts\/3164\/revisions\/3792"}],"wp:attachment":[{"href":"https:\/\/www.gubatron.com\/blog\/wp-json\/wp\/v2\/media?parent=3164"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.gubatron.com\/blog\/wp-json\/wp\/v2\/categories?post=3164"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.gubatron.com\/blog\/wp-json\/wp\/v2\/tags?post=3164"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}