title: PM2 to restart automarically after crash
body: <p>I have some DigitalOcean droplet with small amount of RAM, but there I should to host a lot of pm2 processes (to be more accurate, 9 - 8 in cluster mode (with provided <code>-i 0</code>) and 1 in fork mode). These processes are NodeJS Express servers that do server-side rendering for React.js projects.</p>
  <p>So, as expected, sometimes pm2 is crashing because there is not enough RAM, and after it crashing it obviously does not restore all processes despite of  there is startup daemon enabled.</p>
  <p>I know, that startup daemon works only on system starts, so now every time when pm2 crashes, I should manually go to the droplet and reboot the system on it.</p>
  <p>Is there any workarounds to automate this process? Or, maybe there exist some pm2 daemon that works when pm2 starts?</p>
  <p>Appreciate any help!<br />
  Thanks in advance!</p>
  <hr />
  <h1>Update</h1>
  <p>Here is the last crash log (the part, that is related to crash manually):</p>
  <pre><code>&lt;--- Last few GCs ---&gt;
  
  [11194:0x3184710] 38854201 ms: Scavenge 24.7 (28.2) -&gt; 23.8 (28.2) MB, 0.5 / 0.0 ms  allocation failure
  [11194:0x3184710] 38888980 ms: Scavenge 24.8 (28.2) -&gt; 23.9 (28.7) MB, 0.7 / 0.0 ms  allocation failure
  [11194:0x3184710] 39006864 ms: Scavenge 24.8 (28.7) -&gt; 23.9 (28.7) MB, 0.7 / 0.0 ms  allocation failure
  [11194:0x3184710] 39131478 ms: Scavenge 24.8 (28.7) -&gt; 23.9 (28.7) MB, 0.4 / 0.0 ms  allocation failure
  
  
  &lt;--- JS stacktrace ---&gt;
  
  ==== JS stack trace =========================================
  
  Security context: 0xa90e93a5879 &lt;JSObject&gt;
      0: builtin exit frame: parse(this=0xa90e93890a9 &lt;Object map = 0x188eb7f82ba1&gt;,0x33a45597fe41 &lt;String[338]: {&quot;type&quot;:&quot;axm:monitor&quot;,&quot;data&quot;:{&quot;Loop delay&quot;:{&quot;value&quot;:&quot;0.81ms&quot;,&quot;ag$
  
  FATAL ERROR: Committing semi space failed. Allocation failed - process out of memory
  1: node::Abort() [node /home/&lt;private path&gt;/frontend/dist-server/server.bundle.js]
  2: 0x8c20ec [node /home/&lt;private path&gt;/frontend/dist-server/server.bundle.js]
  3: v8::Utils::ReportOOMFailure(char const*, bool) [node /home/&lt;private path&gt;/frontend/dist-server/server.bundle.js]
  4: v8::internal::V8::FatalProcessOutOfMemory(char const*, bool) [node /home/&lt;private path&gt;/frontend/dist-server/server.bundle.js]
  5: v8::internal::Heap::PerformGarbageCollection(v8::internal::GarbageCollector, v8::GCCallbackFlags) [node /home/&lt;private path&gt;/frontend/dist-server/server.bundle$
  6: v8::internal::Heap::CollectGarbage(v8::internal::AllocationSpace, v8::internal::GarbageCollectionReason, v8::GCCallbackFlags) [node /home/&lt;private path&gt;/fronte$
  7: v8::internal::Factory::NewJSObject(v8::internal::Handle&lt;v8::internal::JSFunction&gt;, v8::internal::PretenureFlag) [node /home/&lt;private path&gt;/frontend/dist-server$
  8: v8::internal::JsonParser&lt;true&gt;::ParseJsonObject() [node /home/&lt;private path&gt;/frontend/dist-server/server.bundle.js]
  9: v8::internal::JsonParser&lt;true&gt;::ParseJsonValue() [node /home/&lt;private path&gt;/frontend/dist-server/server.bundle.js]
  10: v8::internal::JsonParser&lt;true&gt;::ParseJson() [node /home/&lt;private path&gt;/frontend/dist-server/server.bundle.js]
  11: v8::internal::Builtin_JsonParse(int, v8::internal::Object**, v8::internal::Isolate*) [node /home/&lt;private path&gt;/frontend/dist-server/server.bundle.js]
  12: 0x1d7ee3e8697d
  </code></pre>