Sign inSign up

hugomcfonseca/rundeck-executions-cleanup

By hugomcfonseca

•Updated over 8 years ago

Docker container to clean old data from Rundeck once or scheduled at a specific time.

Image
0

1.7K

hugomcfonseca/rundeck-executions-cleanup repository overview

⁠rundeck-executions-management

Python tool to remove executions data from Rundeck using Rundeck API.

Rundeck API will clean up executions data from both database and filesystem. However, it does not remove all related executions' data from database - it only cleans up data from base_report and execution tables. This will maintain unnecessary data in database, specifically, in the following database tables: workflow, workflow_step and workflow_workflow_step. To overcome this issue, it was implemented on the script to connect to database and also cleaning up this data.

It is provided two different ways to run old data maintenance in Rundeck:

  • Standalone: download latest code from master branch and execute it from where you may want, or
  • Docker: launch container to run Rundeck maintenance and exit after finish it or periodically execute it in a cron job (check it in master-docker branch for stable version).

⁠Getting Started

⁠Standalone

By default, this script needs at least one parameter: a valid token. Others parameters are assumed by default and can be overriden. Next, it is showed all available parameters:

  -h, --help                      Show this help message and exit
  -a, --auth <token>              Rundeck token
  -t, --host <domain>             Rundeck host or domain (default: localhost)
  -p, --port <port>               Rundeck port (default: 4440)
  -m, --execution-mode <mode>     Select operation to run this project (default: cleanup)
  --db-host <host>                Rundeck database host (default: mysql-host)
  --db-port <port>                Rundeck database port (default: 3306)
  --db-name <database>            Rundeck database name (default: rundeck)
  --db-user <user>                Rundeck database user (default: rundeck)
  --db-pass <password>            Rundeck database password
  --filtered-project <project>    Filter by a given project
  --filtered-job <job>            Filter by a given job UUID
  --api-version <version>         Rundeck API version (default: 20)
  --search-timeout <seconds>      Timeout to expire HTTP GET requests (default: 60)
  --delete-timeout <seconds>      Timeout to expire HTTP POST requests (default: 300)
  --keep-time <time>              Period of time to keep executions records (default: 30d)
  --chunk-size <size>             Size of each delete iteration (default: 200)
  --retries <number>              Number of retries when some error occur (default: 5)
  --retry-delay <seconds>         Delay to start next retry (default: 5)
  --ssl-enabled                   Rundeck is served over SSL (default: false)
  --executions-by-project         Filter executions by project (default: true)
  --unoptimized                   Run all queries in workflows tables (default: false)
  --running                       Filter by only running executions (default: false)
  --debug                         Print all operations (default: false)
⁠Docker
Env variableDefaultRequiredDescription
RD_TOKENYesRundeck token to access its API
RD_HOSTlocalhostYesRundeck host or domain address
RD_PORT4440YesRundeck port
RD_SSLfalseYesFlag to assign Rundeck is over SSL
RD_DB_HOSTmysql-hostYesHost of Rundeck database
RD_DB_PORT3306YesPort of Rundeck database
RD_DB_NAMErundeckYesName of Rundeck database
RD_DB_USERrundeckYesUser name of Rundeck database
RD_DB_PASSYesUser's password of Rundeck password
KEEP_TIME30dYesPeriod of time to keep executions records
CHUNK_SIZE200YesSize of each delete iteration
RD_API_VERSION20YesRundeck API version
RD_PROJECTNoRun cleanup to a given project
SEARCH_TIMEOUT60NoTimeout to expire HTTP GET requests (in seconds)
DELETE_TIMEOUT300NoTimeout to expire HTTP POST requests (in seconds)
RETRY_TIMES5NoNumber of retries when some error occur
RETRY_BACKOFF5NoDelay to start next retry (in seconds)
DEBUGfalseNoUsed to print all operations during clean up
RD_DB_UNOPTIMIZEDfalseNoAssign to true when database queries below were not run
ONETIME_RUNNINGfalseNoRunning mode of script (run & exit or by a cron)
SCHEDULE* 0 * * *NoTime schema which script may run (in cron mode)

⁠Tuning Rundeck database to speed up its cleaning

If you are experiencing some slowness in Rundeck cleanup, probably you are missing some changes you should do in Rundeck database.

-- Change columns type from base_report table
ALTER TABLE `base_report` MODIFY COLUMN `jc_exec_id` int(11) unsigned;
ALTER TABLE `base_report` MODIFY COLUMN `jc_job_id` int(11) unsigned;
 
-- Add indexes to `base_report` and `execution` tables
ALTER TABLE `base_report` ADD INDEX `BASE_REPORT_IDX_3` (`jc_exec_id`);
ALTER TABLE `base_report` ADD INDEX `BASE_REPORT_IDX_4` (`class`);
ALTER TABLE `base_report` ADD INDEX `BASE_REPORT_IDX_5` (`version`);
ALTER TABLE `execution` ADD INDEX `EXEC_IDX_0` (`version`);
ALTER TABLE `execution` ADD INDEX `EXEC_IDX_5` ( `retry_execution_id` );
 
-- Update existing foreign keys to have DELETE ON CASCADE
ALTER TABLE `workflow_step` DROP FOREIGN KEY `FK_8bbf05v4f6vo5o3cgp69awcue`;
ALTER TABLE `workflow_step` ADD CONSTRAINT `FK_8bbf05v4f6vo5o3cgp69awcue` FOREIGN KEY(`error_handler_id`) REFERENCES workflow_step(`id`) ON DELETE CASCADE;
ALTER TABLE `workflow_workflow_step` DROP FOREIGN KEY `FK_9pkey6k5fdo6worgquakkh7d1`;
ALTER TABLE `workflow_workflow_step` ADD CONSTRAINT `FK_9pkey6k5fdo6worgquakkh7d1` FOREIGN KEY(`workflow_step_id`) REFERENCES workflow_step(`id`) ON DELETE CASCADE;

⁠Usage

⁠Standalone
⁠1. Cleanup old records with default arguments' values (local Rundeck server)
$ python executions_management.py --auth YOUR_TOKEN
⁠2. Cleanup old records in a remote Rundeck server (available over SSL)
$ python executions_management.py --auth-token YOUR_TOKEN --host rundeck.domain.com --port 443 --ssl-enabled
⁠Docker
⁠1. Launch a container to run maintenance periodically
$ docker run -it -d --name rundeck-maintenance --link rundeck_db:mysql-host \
    -e RD_TOKEN="SECRET_TOKEN" \
    -e RD_DB_PASS="SECRET_DB_PASS" \
    hugomcfonseca/rundeck-executions-cleanup:latest
⁠2. Launch a container to run maintenance once
$ docker run -it -d --name rundeck-maintenance --link rundeck_db:mysql-host \
    -e RD_TOKEN="SECRET_TOKEN" \
    -e RD_DB_PASS="SECRET_DB_PASS" \
    -e ONETIME_RUNNING="true" \
    hugomcfonseca/rundeck-executions-cleanup:latest

Please notice, if you don't want to create a linked connection to Rundeck database, you are able to specify it using environment variables.

Tag summary

Content type

Image

Digest

Size

19.4 MB

Last updated

over 8 years ago

docker pull hugomcfonseca/rundeck-executions-cleanup