TeamCity Agent Clean custom directories on Linux hosts
Hello,
We have a bunch of Linux Agents(#3 agents per host).
As part of house keeping activities we would like to clean up some cache folders (~/.ivy2/cache; ~/.gradle/caches; and
/apps/sw/teamcity/stack/*) regularly.
Presently we have Command line executions doing rm -rf </pathToDir/>; however this creates issues when this agent is not idle and there are running or about-to-start builds.
We may write a custom script; however I am looking for some out of box functionality which would stop the agent/s do the cleanup and restart the agents again.
Some suggestions please?
Please sign in to leave a comment.
Hi,
It should be easy to perform a REST API call via curl to enable/disable agents: https://confluence.jetbrains.com/display/TCD10/REST+API#RESTAPI-Agents Disable right before the cleanup, re-enable right after.
Could you check whether this would work for you?
Thanks,
Couple of pointers here:-
> Would disabling the agents before cleanup be sufficient or should I need to stop the agents
(Disabling would still leave a chance where developers can run builds on disabled agents)
> Since the `cache` and `stack`are common for all the agents its desirable to stop/disable all the three agents and then do a cleanup; this should be a TC build for ease of use;
However suppose we have a TC build which does; Agent disable->clean-up->Enable Agents,
once the agent is disabled the cleanup wont happen on this agent since it falls of the TC radar
Any thoughts on this
Hi Shirshendu,
disabling the agents should be enough. Disabled agents shouldn't be allowed to run new builds, so it should be fine.
If you have a shared cache and stack, and also are going to clean them, then yes, I'd strongly suggest to disable all of them, otherwise an agent might be using the cache or stack and lead to unexpected behavior.
Regarding your last scenario, I was thinking more of a separate script that you run with a tool such as cron. If you are running all steps within the same script, then the agent should have all the information it needs even if it falls of the radar of the server. This said, disabling/stopping agents usually waits until they finish their current build, but I haven't really tested what happens when an agent tries to disable itself from within a build.
Thanks Denis,
I was thinking on similar lines, however we have cron disabled, and any scheduling needs to happen via scheduling tool, autosys.
I am trying to avoid this since configuring and scheduling on autosys will involve other teams which i do not want, i need to have full control.
We have developed a korn shell script which does the following:
Stop Agents (1,2,&3) --> Check if any builds are running (by REST API) --> If no builds running on either of the agents then Do cleanUp, else wait and check again till no builds are running--> Start Agents(1,2&3).
When running from the command prompt of the server it executes ok and does the intended tasks.
I am now trying to run the script as a Command Line build step; nohup ~/script.sh &; however due to some reason this does not work although the TC job ends green.
Will keep updating on how it goes