title: init.d scripts works perfectly in console, bad poorly in systemd's service call
body: <p>i have following init.d script.</p>
  
  <pre><code>#!/bin/sh
  ### BEGIN INIT INFO
  # Provides:          teamcity
  # Short-Description: Start daemon at boot time
  # Description:       Enable service provided by daemon.
  ### END INIT INFO
  
  start_cmd="start-stop-daemon --start  -c root --chdir /srv/teamcity/TeamCity-9.1/bin --exec  /srv/teamcity/TeamCity-9.1/bin/runAll.sh start"
  stop_cmd="start-stop-daemon --start  -c root --chdir /srv/teamcity/TeamCity-9.1/bin --exec  /srv/teamcity/TeamCity-9.1/bin/runAll.sh stop"
  user="root"
  
  export TEAMCITY_DATA_PATH="/srv/teamcity/TeamCity-9.1/.BuildServer"
  export TEAMCITY_PID_FILE_PATH="/var/run/teamcity.pid"
  export TEAMCITY_SERVER_OPTS=-Djava.awt.headless=true
  export TEAMCITY_SERVER_MEM_OPTS="-Xmx750m -XX:MaxPermSize=270m"
  /etc/profile.d/java.sh
  
  name="teamcity"
  pid_file="/var/run/$name.pid"
  stdout_log="/var/log/$name.log"
  stderr_log="/var/log/$name.err"
  
  get_pid() {
      cat "$pid_file"
  }
  
  is_running() {
      [ -f "$pid_file" ] &amp;&amp; ps `get_pid` &gt; /dev/null 2&gt;&amp;1
  }
  
  case "$1" in
      start)
      if is_running; then
          echo "Already started"
      else
          echo "Starting $name"
          $start_cmd &gt;&gt; "$stdout_log" 2&gt;&gt; "$stderr_log" &amp;
          sleep 1
          if ! is_running; then
              echo "Unable to start, see $stdout_log and $stderr_log"
              exit 1
          fi
      fi
      ;;
      stop)
      if is_running; then
          echo -n "Stopping $name.."
          $stop_cmd &gt;&gt; "$stdout_log" 2&gt;&gt; "$stderr_log" &amp;
          for i in {1..20}
          do
              if ! is_running; then
                  break
              fi
  
              echo -n "."
              sleep 1
          done
  
          if is_running; then
              echo "Not stopped; may still be shutting down or shutdown may have failed"
              exit 1
          else
              echo "Stopped"
              if [ -f "$pid_file" ]; then
                  rm "$pid_file"
              fi
          fi
      else
          echo "Not running"
      fi
      ;;
      restart)
      $0 stop
      if is_running; then
          echo "Unable to stop, will not attempt to start"
          exit 1
      fi
      $0 start
      ;;
      status)
      if is_running; then
          echo "Running"
      else
          echo "Stopped"
          exit 1
      fi
      ;;
      *)
      echo "Usage: $0 {start|stop|restart|status}"
          exit 1
      ;;
  esac
  
  exit 0
  </code></pre>
  
  <p>If you using it directly from console like this</p>
  
  <pre><code>/etc/init.d/teamcity start
  </code></pre>
  
  <p>,it works very well. But with system'd "service" command not works.
  Systemd is not be able to start Teamcity properly.</p>
  
  <p>Systemd writes only one line on service teamcity start:</p>
  
  <pre><code>Started LSB: Start daemon at boot time.
  </code></pre>
  
  <p>Stopping service fails with:</p>
  
  <pre><code>teamcity.service: control process exited, code=exited status=1
  Stopped LSB: Start daemon at boot time.
  Unit teamcity.service entered failed state.
  </code></pre>
  
  <p>I spend three days googling and changing init file, but no suitable solution.
  Any suggestions to fix that? </p>
  
  <p>Leave SYSV init.d scripts and start using new systemd services notation is my last solution.</p>
  
  <p>Thanks a lot</p>