title: why systemd cannot start golang web app, no answer
body: <p>My golang web app cannot start when I use systemd, but it works fine when manually start. What are problems with my systemd configuration?</p>
  
  <p><strong>goweb.service</strong></p>
  
  <pre><code>$ cat goweb.service 
  [Unit]
  Description=Backend service
  After=network.target
  
  [Service]
  User=myapp
  Group=myapp
  Restart=on-failure
  ExecStart=/u01/backend
  
  [Install]
  WantedBy=multi-user.target
  </code></pre>
  
  <p><code>backend</code> is a binary file compiled with command: <code>env GOOS=linux GOARCH=amd64 go build -v bitbucket.org/myapp/backend</code></p>
  
  <p><strong>systemd service status</strong></p>
  
  <pre><code>$ sudo service goweb status
  Redirecting to /bin/systemctl status  goweb.service
  ● goweb.service - Backend service
     Loaded: loaded (/usr/lib/systemd/system/goweb.service; disabled; vendor preset: disabled)
     Active: inactive (dead)
  
  May 18 10:55:56 instance-1 systemd[1]: Started Backend service.
  May 18 10:55:56 instance-1 systemd[1]: Starting Backend service...
  </code></pre>
  
  <p><strong>P/S</strong>: It looks like my web app started, but then stoped immediately.</p>
  
  <p>I try config <code>Type=forking</code>, then service status show as below. Could someone explains why the log <code>Started Backend service.</code> and <code>Starting Backend service...</code> order is reversed.</p>
  
  <pre><code>$ sudo service goweb status
  Redirecting to /bin/systemctl status  goweb.service
  ● goweb.service - Backend service
     Loaded: loaded (/usr/lib/systemd/system/goweb.service; enabled; vendor preset: disabled)
     Active: inactive (dead) since Wed 2016-05-18 11:06:02 UTC; 2s ago
    Process: 25847 ExecStart=/u01/backend (code=exited, status=0/SUCCESS)
  
  May 18 11:06:02 instance-1 systemd[1]: Starting Backend service...
  May 18 11:06:02 instance-1 systemd[1]: Started Backend service.
  </code></pre>
  
  <p>Result when I run web app manually (from terminal):</p>
  
  <pre><code>$ /u01/backend
  [GIN-debug] [WARNING] Running in "debug" mode. Switch to "release" mode in production.
   - using env:   export GIN_MODE=release
   - using code:  gin.SetMode(gin.ReleaseMode)
  
  [GIN-debug] POST   /upload                   --&gt; main.uploadFileHandler (3 handlers)
  [GIN-debug] Environment variable PORT="9005"
  [GIN-debug] Listening and serving HTTP on :9005
  </code></pre>
  
  <hr>
  
  <p><strong>Update</strong>:</p>
  
  <ol>
  <li>I try <a href="http://supervisord.org/" rel="nofollow">supervisord</a> and it works fine (same binary file)</li>
  <li>With <code>systemd</code>, I changed service config to <code>Restart=always</code>,  <code>RestartSec=15</code>. And <code>systemd</code> keeps restarting my web app.</li>
  </ol>
  
  <p>Does anyone know why <code>supervisord</code> work fine but <code>systemd</code> not? I think that <code>systemd</code> would work fine with a basic task like that!</p>