       # env += "export #{key}='#{val}'\n" for key,val of KONFIG.ENV
       return env
 
+    workerList = (separator=" ")->
+      (key for key,val of KONFIG.workers).join separator
+
     workersRunList = ->
       workers = ""
       for key,val of KONFIG.workers
-        workers +="#------------- worker: #{key} -------------#\n"
-        workers +="#{val.command} &>#{projectRoot}/.logs/#{key}.log & \n"
-        workers +="#{key}pid=$! \n"
-        workers +="echo [#{key}] started with pid: $#{key}pid \n\n"
+
+        workers += """
+
+        function worker_daemon_#{key} {
+
+          #------------- worker: #{key} -------------#
+          #{val.command} &>#{projectRoot}/.logs/#{key}.log &
+          #{key}pid=$!
+          echo [#{key}] started with pid: $#{key}pid
+
+
+        }
+
+        function worker_#{key} {
+
+          #------------- worker: #{key} -------------#
+          #{val.command}
+
+        }
+
+        """
       return workers
 
     installScript = """

      }

      function run () {
        #{projectRoot}/go/build.sh
        cd #{projectRoot}/go/src/socialapi
        make configure
        cd #{projectRoot}
        #{workersRunList()}
        tail -fq ./.logs/*.log

      }

      function check (){


      elif [ "$1" == "services" ]; then
        check_service_dependencies
        services

      elif [ "$1" == "worker" ]; then

        if [ "$2" == "" ]; then
          echo Available workers:
          echo "-------------------"
          echo '#{workerList "\n"}'
        else
          eval "worker_$2"
        fi

      else
        check
        run
      fi
      # ------ THIS FILE IS AUTO-GENERATED BY ./configure ----- #\n
      """
    # KONFIG.workers_        = workersRunList         KONFIG
    return run

  KONFIG.ENV            = generateEnvVariables   KONFIG
  KONFIG.supervisorConf = generateSupervisorConf KONFIG
  KONFIG.runFile        = generateRunFile        KONFIG
  return KONFIG

module.exports = Configuration
