<!DOCTYPE html>
<!--[if lt IE 7 ]><html dir="ltr" lang="en-US" class="no-js ie ie6 lte7 lte8 lte9"><![endif]-->
<!--[if IE 7 ]><html dir="ltr" lang="en-US" class="no-js ie ie7 lte7 lte8 lte9"><![endif]-->
<!--[if IE 8 ]><html dir="ltr" lang="en-US" class="no-js ie ie8 lte8 lte9"><![endif]-->
<!--[if IE 9 ]><html dir="ltr" lang="en-US" class="no-js ie ie9 lte9"><![endif]-->
<!--[if (gt IE 9)|!(IE)]><!--><html dir="ltr" lang="en-US" class="no-js"><!--<![endif]-->
	<head>
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no" />
		<meta charset="UTF-8" />
		<title>Daniil Kulchenko - dkume</title>
		<link rel="profile" href="http://gmpg.org/xfn/11" />
		<link rel="stylesheet" href="http://dkume.com/wp-content/themes/dkume/style.css" />
		<link rel="stylesheet" href="http://dkume.com/wp-content/themes/dkume/responsive.css" />
		<link rel="pingback" href="http://dkume.com/xmlrpc.php" />
<link rel="alternate" type="application/rss+xml" title="dkume &raquo; Feed" href="http://dkume.com/feed/" />
<link rel="alternate" type="application/rss+xml" title="dkume &raquo; Comments Feed" href="http://dkume.com/comments/feed/" />
<link rel="EditURI" type="application/rsd+xml" title="RSD" href="http://dkume.com/xmlrpc.php?rsd" />
<link rel="wlwmanifest" type="application/wlwmanifest+xml" href="http://dkume.com/wp-includes/wlwmanifest.xml" /> 

<script type="text/javascript">

  var _gaq = _gaq || [];
  _gaq.push(['_setAccount', 'UA-1381981-9']);
  _gaq.push(['_trackPageview']);

  (function() {
    var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
    ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
    var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
  })();

</script>
	</head>
	<body class="home blog">
	
	<div id="wrap">
		
		<header role="banner">
			<h1 class="lato lighter" style="font-size: 3em"><a href="http://dkume.com/" title="dkume" rel="home">dkume</a></h1>
			<p class="lato" style="margin-top: -1em">
The musings of a<br id="description-br" />
teenage hacker.
</p>
			
				
			<div id="mobile-blurb"><a href="http://daniilkulchenko.com">about me</a> &middot; <a target="_blank" href="http://twitter.com/dkulchenko">twitter</a> &middot; <a target="_blank" href="mailto:daniil@kulchenko.com">email</a></div>
		
			<div class="links">
				<p><a href="http://daniilkulchenko.com">about me</a></p>
				<p><a target="_blank" href="http://twitter.com/dkulchenko">@dkulchenko</a></p>
				<p><a target="_blank" href="http://github.com/dkulchenko">github</a></p>
				<p><a target="_blank" href="mailto:daniil@kulchenko.com">email</a>    </p>
			</div><!-- .links -->
		</header>
		
		<section id="content" role="main">
	





			<article id="post-70" class="post-70 post type-post status-publish format-standard hentry category-myself">
			<div class="entry-meta">
				<span class="entry-date">2012.03.31</span>			</div><!-- .entry-meta -->
			
			<h2 class="entry-title"><a class="is_link_"0" href="http://dkume.com/selling-phenona/" rel="bookmark" title="Selling a startup at the age of 15">Selling a startup at the age of 15</a></h2>



				<div class="entry-content">
				<p>It didn&#8217;t begin as one.</p>
<p>It was April 2009, my second trip to Mexico. Back in the day I would freelance, and at the time I had a client who wanted me to develop a data aggregator for Craigslist. Coincidentally, I was finishing up the project right around the same time I went on vacation. My thought process was that it&#8217;d be a simple <code>scp</code> over to the client&#8217;s box and I&#8217;d be on my way, but never before had I met IIS. A good third of my vacation was spent on getting that Perl app to run on a Windows box.</p>
<p><strong>There&#8217;s got to be a better way, right?</strong> This was before the <a href="http://en.wikipedia.org/wiki/Platform_as_a_service">PaaS</a> boom, Heroku was the only option out there and it didn&#8217;t support anything but Ruby. So, come summer 2010, I wrote my own, for Perl. I called it Phenona.</p>
<p>It took a few months of learning about network topologies, Redis, ØMQ, LXC, redundancy, distributed systems, et. al before I was ready to jump in. And only halfway through coding did I realize that this could be of some utility to others. So I scrapped and rewrote it with others in mind. No billing system even in sight (<em>a la 37signals</em>) but in December of that year, I was ready with what one could call a private beta. Given my $20/month budget (my allowance at the time), the idea was to let a tiny bit of people in to give feedback, then hopefully jump straight to a launch.</p>
<p>The response surprised me. I&#8217;d devised a registration form that would ask each prospective user a wide array of questions so that I could get a better perspective of the market. Yet even with the additional friction, 10 users registered within the first week. Then another 10. Then 50. Then 100. Each day I would log on to <a href="http://mailchimp.com/">MailChimp</a> (fantastic service) and read the comments of the day and would be surprised again and again about the various backgrounds people were coming from and the ideas they had for improving Phenona. In the meantime, I was navigating the innards of the <a href="http://www.cpan.org/">CPAN</a> build process, getting a client library out the door and iterating, iterating, iterating on the server-side. </p>
<p>One day, I got an email from <a href="http://activestate.com">ActiveState</a>. They were getting into the cloud business and wanted to talk about Phenona. Phenona was written in Perl, for Perl apps, and ActiveState is widely known for the excellent <a href="http://www.activestate.com/activeperl">ActivePerl</a>, so it was a natural fit. For obvious reasons, I can&#8217;t go into detail about the months that followed, but it was quite the rollercoaster ride. I learned the concepts of &#8220;due diligence&#8221;, &#8220;indemnity&#8221;, contracts, lawyers and more lawyers, and even family law in Washington state (I am an <a href="http://en.wikipedia.org/wiki/Emancipation_of_minors">emancipated minor</a>). ActiveState was fantastic to work with through it all; they&#8217;re seriously the nicest people in the business.</p>
<p>Come June 14th (2011), it was go time: announcement day. A regular school day, I might add. I got up at 5am to be able to push the blog post to the Phenona blog in time and send the tweets out, and headed off to school.</p>
<p>The Register <a href="http://www.theregister.co.uk/2011/06/14/activestate_buys_teen_programmer/">was the first</a>. Then <a href="http://www.geekwire.com/2011/seattle-area-15yearold-sells-startup-company-activestate/">Geekwire</a>. But aside from that, the 14th was quiet. So was the 15th. But on the third day, something happened, and suddenly my inbox was full. The few weeks that followed were insane. An interview for KOMO (local news station in Seattle), a video interview for national TV in Russia, the GeekWire podcast, Skype interviews for various bloggers, dozens of email interviews. A news outlet had emailed the principal of my school to get a quote, and the principal had forwarded the email to all my teachers. It started out as flattering but quickly progressed to exhausting, to the point where the red (1) on the Mail icon in the OS X dock would cause an involuntary sigh.</p>
<p>But it was worth it, <em>many times over</em>. </p>
<p>Over the past year, I&#8217;ve met more fantastic people than I can possibly count. The support and encouragement from the crowd has been much more than I could&#8217;ve possible asked for when I committed the first line of Phenona&#8217;s code years ago.</p>
<p>So where have I been since June? Working behind the scenes on <a href="http://stackato.com">Stackato</a>, which is in many ways a continuation of the Phenona idea: frictionless deployment to the cloud, as widely accessible as possible. </p>
<p>And of course, in my spare time, I&#8217;ve been thinking about the next big idea. An entrepreneur&#8217;s spirit is a crazy thing.</p>
<p>Hacker News discussion <a href="http://news.ycombinator.com/item?id=3789681">here</a>.</p>
							</div><!-- .entry-content -->
	

		</article><!-- #post-## -->

		
	

			<article id="post-55" class="post-55 post type-post status-publish format-standard hentry category-articles">
			<div class="entry-meta">
				<span class="entry-date">2011.10.17</span>			</div><!-- .entry-meta -->
			
			<h2 class="entry-title"><a class="is_link_"0" href="http://dkume.com/virtualization-using-lxc-linux-containers-in-amazon-ec2/" rel="bookmark" title="Virtualization using LXC on EC2">Virtualization using LXC on EC2</a></h2>



				<div class="entry-content">
				<p><em>(Note: this is mirrored from the Phenona blog; Phenona was acquired by ActiveState, so the original post is no longer accessible.</em><strong> Update 10/27</strong>: now also available at the <a href="http://www.activestate.com/blog/2011/10/virtualization-ec2-cloud-using-lxc" target="_blank">ActiveState blog</a>.<em>)</em></p>
<h3>Virtualization</h3>
<p>EC2 is already a <a href="http://en.wikipedia.org/wiki/Paravirtualization" target="_blank">(para)virtualized</a> environment, which means you can&#8217;t run your own virtualization (KVM/VirtualBox/qemu). As an alternative, Linux recently introduced a new system into the kernel, called <code>cgroups</code>, which provides a way to isolate process groups from each other in the kernel. A project was soon formed around this new technology, which allows for very thin, fast, and secure quasi-virtualization. It&#8217;s called LXC. And it works in EC2 perfectly.</p>
<p><strong>Here&#8217;s how.</strong></p>
<p>You&#8217;ll want a recent Linux AMI (preferrably kernel 2.6.35 or higher). I use Ubuntu 11.10, and the following instructions are meant for that OS. Can&#8217;t vouch for other distros, but the instructions should be easily portable. Ubuntu&#8217;s excellent for the LXC + EC2 combination because they already have <a href="http://uec-images.ubuntu.com/releases/11.10/release/" target="_blank">pre-made AMI images</a>, the kernel supports LXC out of the box, and they have software repositories hosted in the EC2 cloud, which makes for extremely fast system updates. Also, any instance type works, even a <code>t1.micro</code> will suffice (my weapon of choice for testing purposes).</p>
<p>Start by SSH-ing into your EC2 server. You&#8217;ll need to run almost all of the following instructions as root, so let&#8217;s do:</p>
<p><code>sudo -i</code></p>
<p>to become root. Otherwise, you can prepend &#8216;sudo&#8217; to the beginning of every command from now on (unless specified otherwise).</p>
<p>Now, we need to install a few packages:</p>
<p><code>apt-get update &amp;&amp; apt-get install lxc debootstrap bridge-utils dnsmasq</code></p>
<p>Now run <code>lxc-checkconfig</code> and make sure that the tests pass (all of them should if you&#8217;re using the AMI).</p>
<p>Keep in mind that the effects of most of the commands from here on out (specifically iptables, sysctl, mount, brctl and any edits to /etc/resolv.conf) <strong>will not persist over a reboot</strong>, even on a EBS-backed instance. These are in-memory changes which <strong>will go away</strong> as soon as you shut down the machine. If you bring the instance back up, you&#8217;ll need to run them again, otherwise things <strong>will be broken</strong>. There are several ways to get around this: iptables rules and /etc/resolv.conf can be set by an init script, sysctl can be set in sysctl.conf, mounts can be specified in /etc/fstab, and brctl can be set in /etc/network/interfaces (add the br0 interface); however, for the purposes of this guide (I don&#8217;t use EBS-backed instances, personally), we&#8217;ll assume instance storage (config is lost on reboot).</p>
<p>We&#8217;ll need to create a place on the system to hold cgroup information (required for LXC to work). I use /cgroup. Let&#8217;s mount a cgroup environment there.</p>
<p><code>mkdir /cgroup<br />
mount -t cgroup none /cgroup</code></p>
<p>Now, let&#8217;s create a network bridge for the containers to be able to connect to the network/Internet. Simply run:</p>
<p><code>brctl addbr br0<br />
brctl setfd br0 0<br />
ifconfig br0 192.168.3.1 up</code></p>
<p>Now we need to set up a few system rules for the containers to be able to reach the Internet:</p>
<p><code>iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE<br />
sysctl -w net.ipv4.ip_forward=1</code></p>
<p>Let&#8217;s set up DHCP/DNS on our new bridge. Open up <code>/etc/dnsmasq.conf</code> for editing (vim/nano/ed/cat, your choice). Uncomment the necessary lines so that the conf file looks like the following:</p>
<p><code>domain-needed<br />
bogus-priv<br />
interface = br0<br />
listen-address = 127.0.0.1<br />
listen-address = 192.168.3.1<br />
expand-hosts<br />
domain = containers<br />
dhcp-range = 192.168.3.50,192.168.3.200,1h</code></p>
<p>Now, you&#8217;ll need to edit <code>/etc/dhcp/dhclient.conf</code> for DNS to properly resolve locally. Add the following lines to the beginning:</p>
<p><code>prepend domain-name-servers 127.0.0.1;<br />
prepend domain-search "containers.";</code></p>
<p>(Don&#8217;t forget the dot after <code>containers</code>, that&#8217;s not a typo!)</p>
<p>Now we need to renew our DHCP lease so that dhclient will regenerate /etc/resolv.conf.</p>
<p><code>dhclient3 -e IF_METRIC=100 -pf /var/run/dhclient.eth0.pid -lf /var/lib/dhcp3/dhclient.eth0.leases eth0</code></p>
<p>Now, let&#8217;s restart dnsmasq so it&#8217;ll re-read the new configuration.</p>
<p><code>service dnsmasq restart</code></p>
<h2></h2>
<p>Next, we need to create the environment inside the container. There&#8217;s a script that comes with lxc called lxc-ubuntu, which will set up the container. However, it&#8217;ll require a bit of tweaking for the environment to work. I&#8217;ve done the tweaking for you, and put the new script up, so simply run: <strong>(updated 4/30/11 for Ubuntu Server 11.04)</strong></p>
<p><code>wget -O lxc-ubuntu http://bit.ly/ec2ubuntulxc<br />
chmod +x lxc-ubuntu</code></p>
<p>Now, let&#8217;s create a new container:</p>
<p><code>./lxc-ubuntu -p /mnt/vm0 -n vm0</code></p>
<p>Wait a while for the script to finish, and your container is set up in /mnt/vm0. Let&#8217;s try it out!</p>
<p><code>lxc-start -n vm0</code></p>
<p>Type in root for the username and root for the password. Try pinging Google:</p>
<p><code>ping www.google.com</code></p>
<p>If it works, your Internet is set up! Now let&#8217;s try another thing <strong>(make sure you run this from the VM, not from the host!!)</strong>:</p>
<p><code>poweroff</code> (this shuts down the VM, and puts you in the host again)<br />
<code>lxc-start -n vm0 -d </code>(this runs the VM in daemon mode)</p>
<p>To check if a VM is running, type:</p>
<p><code>lxc-info -n vm0</code></p>
<p>(it should say RUNNING). To test network, try pinging the VM (this might not work right away, you might have to wait up to a minute):</p>
<p><code>ping vm0<br />
ssh root@vm0</code></p>
<p>If those two work, the VM is now in your DNS and you can address it by its hostname. Cool, huh?</p>
<h3>Creating a new VM</h3>
<p>Creating another VM is as simple as:</p>
<p><code>./lxc-ubuntu -n vm1 -p /mnt/vm1</code></p>
<p>The packages won&#8217;t be redownloaded, and the command should complete quickly.</p>
<h3>Clone existing VM</h3>
<p>If you want to clone your existing VM, you&#8217;ll need to do a few things:</p>
<p><code>cp -r /mnt/vm0 /mnt/vm1</code></p>
<p>Now edit /mnt/vm1/config and replace all references of vm0 to vm1. Do the same with /mnt/vm1/fstab. Then go into /mnt/vm1/rootfs/etc/hostname and replace the hostname with vm1. Finally, run:</p>
<p><code>lxc-create -n vm1 -f /mnt/vm1/config</code></p>
<p>Upon starting the VM, you should be able to ping it/ssh to it:</p>
<p><code>ping vm1<br />
ssh root@vm1</code></p>
<p>If not, lxc-console into the VM and check your connection. Keep in mind you only need one <code>br0</code> for all your instances, but you can create many, if you so desire.</p>
<h3>Running services inside the container</h3>
<p>At <strong><a target="_blank" href="http://phenona.com">Phenona</a></strong>, we run Perl web servers and the like inside these containers. You may want them to be accessible from outside the VM (from the rest of EC2, or outside EC2). To do this, you&#8217;ll need to port forward from the host to the VM. Simply run:</p>
<p><code>iptables -t nat -A PREROUTING -p tcp --dport
<port on host> -j DNAT --to-destination <hostname of VM>:
<port on VM></code></p>
<h3>Hibernating a container</h3>
<p>To &#8216;hibernate&#8217; a container (save the current state (running processes) of the VM for instant restoring later) do:</p>
<p><code>lxc-freeze -n vm0</code></p>
<p>and later,</p>
<p><code>lxc-unfreeze -n vm0</code></p>
<p>to restore.</p>
<h3>Installing additional packages into the container</h3>
<p>Your container is just like any other Ubuntu system. Therefore,</p>
<p><code>apt-get update<br />
apt-get install <whatever></code></p>
<p>works great.</p>
<h3>Setting resource limits</h3>
<p>One of the benefits of LXC is that you can limit resource usage per-container. Let&#8217;s delve into the various resources you can limit:</p>
<p><strong>CPU</strong></p>
<p>There&#8217;s two ways of limiting CPU in LXC. On a multi-core system, you can assign different CPUs to different containers, as such (add this line to your container config file, /mnt/vm0/config or similar):</p>
<p><code>lxc.cgroup.cpuset.cpus = 0</code> (assigns the first CPU to the container)<br />
or<br />
<code>lxc.cgroup.cpuset.cpus = 0,2,3</code> (assigns the first, third, and fourth CPU to the container)</p>
<p>The alternative (this one makes more sense to me) is to use the scheduler. You can use values to say &#8216;I want this container to get 3 times the CPU of this container&#8217;. For example, add:</p>
<p><code>lxc.cgroup.cpu.shares = 2048</code></p>
<p>to the config to give a container double the default (1024).</p>
<p><strong>RAM</strong></p>
<p>To limit RAM, simply set:</p>
<p><code>lxc.cgroup.memory.limit<em>in</em>bytes = 256M</code></p>
<p>(replacing 256M with however much RAM you want to allow).</p>
<p>To limit swap, set:</p>
<p><code>lxc.cgroup.memory.memsw.limit<em>in</em>bytes = 1G</code></p>
<p><strong>Hard Disk</strong></p>
<p>There&#8217;s no official way to do this, it&#8217;s up to you. You can use LVM (in EC2? Good luck.), or you can create a filesystem in a file (something like <code>dd if=/dev/zero of=somefile.img bs=4GB count=1 &amp;&amp; mkfs.ext3 somefile.img &amp;&amp; mount -o loop somefile.img /mnt/vm0/rootfs</code>) and mount it to /mnt/vm0/rootfs to limit space.</p>
<h3>Network Bandwidth</h3>
<p>To limit network bandwidth per container, do some reading on the <code>tc</code> utility. Keep in mind you&#8217;ll need to use separate bridges (br0, br1) for each container if you go this route. Don&#8217;t forget to edit the config of each VM to match your new bridge if you do so.<span class="Apple-style-span" style="font-size: 20px; font-weight: bold;"> </span></p>
<h3>Closing Remarks</h3>
<p>Thanks to the <a href="http://blog.foaa.de/2010/05/lxc-on-debian-squeeze" target="_blank">Foaa</a> and <a href="http://blog.mudy.info/2010/07/linux-container-on-amazon-ec2-server/" target="_blank">Mudy</a> blogs for getting me started on my way towards a running LXC.</p>
<p>Some further reading: the <a href="http://lxc.sourceforge.net/" target="_blank">main LXC site</a>, <a href="http://lxc.teegra.net/" target="_blank">the LXC HOWTO</a>, and <a href="http://www.ibm.com/developerworks/linux/library/l-lxc-containers/" target="_blank">IBM&#8217;s tutorial</a>.</p>
<p><strong>NOTE: </strong>When following other guides on LXC, be very careful with messing with the network in the EC2 environment (restarting networking services or altering /etc/network/interfaces on the <strong>host</strong>) because one wrong command, and the connection will drop between you and your instance (you&#8217;ll lose SSH), and therefore lose your instance completely. I did that many, many times while exploring LXC. The instructions I&#8217;ve provided here have been tested and will not drop your EC2 connection, but I can&#8217;t vouch for other methods.</p>
							</div><!-- .entry-content -->
	

		</article><!-- #post-## -->

		
	

			<article id="post-12" class="post-12 post type-post status-publish format-standard hentry category-myself tag-blog tag-me">
			<div class="entry-meta">
				<span class="entry-date">2011.05.22</span>			</div><!-- .entry-meta -->
			
			<h2 class="entry-title"><a class="is_link_"0" href="http://dkume.com/hello/" rel="bookmark" title="Brief introductions">Brief introductions</a></h2>



				<div class="entry-content">
				<p>Hello, I don&#8217;t believe we&#8217;ve met.</p>
<p>I&#8217;m Daniil Kulchenko, a 15 year old software developer, designer, writer, biker, driver, boater, Facebook-er, fun-have-er, hanging-out-with-friends-er, and a lot of other words that don&#8217;t actually exist. I go by dku on IRC, so this blog&#8217;s name naturally followed.</p>
<p>I&#8217;m also the creator of <a href="http://phenona.com/" target="_blank">Phenona</a>, the first and only pure-Perl PaaS online today, which allows you to easily deploy and manage Perl web applications in the cloud.</p>
<p>Welcome aboard. There&#8217;s many tech rants, new ideas, (hopefully) helpful tutorials, and whatever else happens to pop into my mind, ahead. Stay tuned.</p>
							</div><!-- .entry-content -->
	

		</article><!-- #post-## -->

		
	

		</section><!-- #main -->


		</div><!-- #wrap -->
	</body>
</html>
<!-- Dynamic page generated in 0.234 seconds. -->
<!-- Cached page generated by WP-Super-Cache on 2012-07-15 15:38:18 -->
<!-- super cache -->