<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
  <channel>
    <title>Pm2 on Janik von Rotz</title>
    <link>https://janikvonrotz.ch/tags/pm2/</link>
    <description>Recent content in Pm2 on Janik von Rotz</description>
    <generator>Hugo</generator>
    <language>en</language>
    <lastBuildDate>Tue, 14 Mar 2017 14:12:42 +0000</lastBuildDate>
    <atom:link href="https://janikvonrotz.ch/tags/pm2/index.xml" rel="self" type="application/rss+xml" />
    <item>
      <title>Deploy your Meteor app with PM2</title>
      <link>https://janikvonrotz.ch/2017/03/14/deploy-your-meteor-app-with-pm2/</link>
      <pubDate>Tue, 14 Mar 2017 14:12:42 +0000</pubDate>
      <guid>https://janikvonrotz.ch/2017/03/14/deploy-your-meteor-app-with-pm2/</guid>
      <description>&lt;p&gt;PM2 is a well-known node process manager. Not so well-known is its deployment feature. With pm2 you can reasonable easy deploy any node application. As Meteor is always a node app at its heart I&amp;rsquo;ve decided to deploy my current Meteor project with PM2.&lt;/p&gt;&#xA;&lt;p&gt;I assume you already have PM2 installed on your client and server, otherwise checkout &lt;a href=&#34;http://pm2.keymetrics.io/&#34;&gt;http://pm2.keymetrics.io/&lt;/a&gt;.&lt;/p&gt;&#xA;&lt;p&gt;To create a deployment configuration file run &lt;code&gt;pm2 ecosystem&lt;/code&gt; in your project folder. This will create the &lt;code&gt;ecosystem.config.js&lt;/code&gt; file. You can now configure this file according to your projects environment.&lt;/p&gt;&#xA;&lt;p&gt;Here&amp;rsquo;s mine:&lt;/p&gt;&#xA;&lt;p&gt;&lt;strong&gt;ecosystem.config.js&lt;/strong&gt;&lt;/p&gt;&#xA;&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;module.exports = {&#xA;  /**&#xA;   * Application configuration section&#xA;   * http://pm2.keymetrics.io/docs/usage/application-declaration/&#xA;   */&#xA;  apps: [&#xA;    {&#xA;      name: &amp;#39;Project&amp;#39;,&#xA;      script: &amp;#39;./bundle/main.js&amp;#39;,&#xA;      env: {&#xA;        NODE_ENV: &amp;#39;dev&amp;#39;,&#xA;        MONGO_URL: &amp;#39;mongodb://user:password@id.mlab.com:port/database&amp;#39;,&#xA;        ROOT_URL: &amp;#39;https://hostname.example.com&amp;#39;,&#xA;        PORT: 3000,&#xA;        METEOR_SETTINGS: {&#xA;          &amp;#39;private&amp;#39;: { ... },&#xA;          &amp;#39;public&amp;#39;: { ... }&#xA;        }&#xA;      },&#xA;      env_prod: {&#xA;      },&#xA;    },&#xA;  ],&#xA;&#xA;  /**&#xA;   * Deployment section&#xA;   * http://pm2.keymetrics.io/docs/usage/deployment/&#xA;   */&#xA;  deploy: {&#xA;    dev: {&#xA;      user: &amp;#39;login&amp;#39;,&#xA;      host: &amp;#39;hostname.example.com&amp;#39;,&#xA;      key: &amp;#39;/path/to/your/ssh/id_rsa&amp;#39;,&#xA;      ref: &amp;#39;origin/develop&amp;#39;,&#xA;      repo: &amp;#39;git@gitlab.com:username/repo.git&amp;#39;,&#xA;      path: &amp;#39;/path/to/your/project/folder&amp;#39;,&#xA;      &amp;#39;post-deploy&amp;#39;: &amp;#39;rm -rf ./bundle &amp;amp;&amp;amp; npm install --production &amp;amp;&amp;amp; meteor build . --directory &amp;amp;&amp;amp; cd ./bundle/programs/server &amp;amp;&amp;amp; npm install --production &amp;amp;&amp;amp; cd ../../.. &amp;amp;&amp;amp; pm2 startOrRestart ecosystem.config.js&amp;#39;,&#xA;    }&#xA;  }&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;&lt;strong&gt;Hint&lt;/strong&gt;: If your git repo is private, make sure your store a ssh key with access rights to the repo on your server.&lt;/p&gt;&#xA;&lt;p&gt;The &lt;code&gt;post-deploy&lt;/code&gt; command will build the node app from your Meteor project. This command once executed takes some time to finish.&lt;/p&gt;&#xA;&lt;p&gt;When you&amp;rsquo;re finished updating the config file, you have to set up the project folder on your server.&#xA;Run &lt;code&gt;pm2 deploy ecosystem.config.js dev setup&lt;/code&gt; to do so. Your repo will be cloned and launched on your server.&lt;/p&gt;&#xA;&lt;p&gt;From now on, whenever you&amp;rsquo;ve pushed new changes to your repo, you can deploy your app with &lt;code&gt;pm2 deploy ecosystem.config.js&lt;/code&gt;.&lt;/p&gt;&#xA;&lt;p&gt;&lt;img src=&#34;https://janikvonrotz.ch/wp-content/uploads/2017/03/Screen-Shot-2017-03-14-at-13.44.04.png&#34; alt=&#34;Untitled&#34;&gt;&amp;hellip;&#xA;&lt;figure&gt;&lt;img src=&#34;https://janikvonrotz.ch/wp-content/uploads/2017/03/Screen-Shot-2017-03-14-at-13.44.30.png&#34;&gt;&lt;figcaption&gt;&#xA;      &lt;h4&gt;Meteor app deployed successfully.&lt;/h4&gt;&#xA;    &lt;/figcaption&gt;&#xA;&lt;/figure&gt;&#xA;&lt;/p&gt;&#xA;&lt;p&gt;Make sure to have a look on the &lt;a href=&#34;http://pm2.keymetrics.io/docs/usage/deployment/&#34;&gt;PM2 deployment documentation&lt;/a&gt;.&lt;/p&gt;</description>
    </item>
  </channel>
</rss>
