oglimmer/fulgens

View on GitHub
classes/plugins/NodePlugin.tmpl

Summary

Maintainability
Test Coverage

{{ header }}

if [ "$START_{{softwareComponentName|upper}}" = "YES" ]; then

{{ preparecomp }}

{{ getsource }}

f_build() {
  verbosePrint "npm i --save-prod"
  {{BeforeBuild}}
  {{Build}}
  {{AfterBuild}}
}
if [ "$SKIP_BUILD" != "YES" ]; then
  if [ -n "$CLEAN" ]; then
    verbosePrint "rm -rf node_modules/"
    rm -rf node_modules/
  fi
  f_build        
fi

{{ prestart }}

if [ "${{typeSourceVarName}}" == "docker" ]; then
  #if [ -f "{{pidFile}}" ] && [ "$(<{{pidFile}})" == "download" ]; then
  #  echo "node running but started from different source type"
  #  exit 1
  #fi
  if [ ! -f "{{pidFile}}" ]; then
    startDockerNetwork
    {{writeDockerConnectionLogic}}
    {{writeConfigFiles}}
    verbosePrint "docker run --rm -d -p {{ExposedPort}}:{{ExposedPort}} {% if DockerMemory %}-m {{DockerMemory}}{% endif %} --net={{systemName|lower}}net --name={{softwareComponentName}} $ADD_HOST_INTERNAL {{mountToDocker}} {{AllEnvVarsDocker}} -v $(pwd):/home/node/exec_env -w /home/node/exec_env {{DockerImage}}:${{typeSourceVarName}}_VERSION node {{NodeParam}} ./{{Start}}"
    dockerContainerID{{softwareComponentName}}=$(docker run --rm -d -p {{ExposedPort}}:{{ExposedPort}} \
        {% if DockerMemory %}-m {{DockerMemory}}{% endif %} \
        --net={{systemName|lower}}net --name={{softwareComponentName}} $ADD_HOST_INTERNAL \
        {{mountToDocker}} {{AllEnvVarsDocker}} \
        -v "$(pwd)":/home/node/exec_env -w /home/node/exec_env {{DockerImage}}:${{typeSourceVarName}}_VERSION node {{NodeParam}} ./{{Start}})
    echo "$dockerContainerID{{softwareComponentName}}">{{pidFile}}
  else
    dockerContainerID{{softwareComponentName}}=$(<{{pidFile}})
    echo "Reusing already running instance $dockerContainerID{{softwareComponentName}}"
  fi
  tailCmd="docker logs -f $dockerContainerID{{softwareComponentName}}"
fi

if [ "${{typeSourceVarName}}" == "local" ]; then
  #if [ -f "{{pidFile}}" ]; then
  #  echo "node running but started from different source type"
  #  exit 1
  #fi
  if [ ! -f "{{pidFile}}" ]; then
    cat <<-EOF > localrun/noint.js
      process.on( "SIGINT", function() {} );
      require('../{{Start}}');
EOF
    verbosePrint "{{AllEnvVarsNode}} node {{NodeParam}} localrun/noint.js >localrun/noint.out 2>&1 &"
    {{storeFileAndExportEnvVar}}
    {{AllEnvVarsNode}} node {{NodeParam}} localrun/noint.js >localrun/noint.out 2>&1 & 
    processId{{softwareComponentName}}=$!
    echo "$processId{{softwareComponentName}}">{{pidFile}}
  else
    processId{{softwareComponentName}}=$(<{{pidFile}})
    echo "Reusing already running instance $processId{{softwareComponentName}}"
  fi
  tailCmd="tail -f localrun/noint.out"
fi

{{ poststart }}

{{ leavecomp }}

fi