fun start()

in agent/src/main/kotlin/org/jetbrains/teamcity/sccache/SCCacheServer.kt [62:92]


    fun start(logger: BuildProgressLogger, runningBuild: AgentRunningBuild) {
        // invoke 'sccache --start-server' with all necessary env variables

        val env = HashMap<String, String>()
        // server should never stop itself
        env["SCCACHE_IDLE_TIMEOUT"] = "0"
        env["SCCACHE_SERVER_PORT"] = settings.port.toString()
        settings.backendConfig?.let { env.putAll(it.getEnv()) }

        val loggingLevel = runningBuild.sharedConfigParameters[SCCacheConstants.SCCACHE_SERVER_LOGGING_LEVEL]
                ?: runningBuild.agentConfiguration.configurationParameters[SCCacheConstants.SCCACHE_SERVER_LOGGING_LEVEL]
        if (!loggingLevel.isNullOrBlank()) {
            env["SCCACHE_LOG"] = loggingLevel
            // buildTempDirectory is not existing yet
            // neither is agentTempDirectory
            logFile = File(runningBuild.agentTempDirectory.absoluteFile.parent, "globalTmp/sccache-server-${runningBuild.buildId}.log")
            env["SCCACHE_ERROR_LOG"] = logFile!!.absolutePath
        }


        logger.message("Using env variables: ${env.toSortedMap()}")

        val result = run(env, "--start-server")
        if (reportFailures(result, logger)) return

        val stdout = result.stdout.trim()
        if (stdout.isNotEmpty() && stdout != "Starting sccache server...") {
            logger.message("sccache stdout:\n$stdout")
        }
        if (result.stderr.isNotEmpty()) logger.warning("sccache stderr:\n" + result.stderr)
    }