{"id":24780458,"url":"https://github.com/webgriffe/swarm-cron","last_synced_at":"2026-04-16T15:34:27.235Z","repository":{"id":67627027,"uuid":"553624893","full_name":"webgriffe/swarm-cron","owner":"webgriffe","description":"Docker Swarm cron scheduler","archived":false,"fork":false,"pushed_at":"2023-05-29T06:26:01.000Z","size":29,"stargazers_count":3,"open_issues_count":0,"forks_count":0,"subscribers_count":5,"default_branch":"main","last_synced_at":"2025-10-25T19:43:18.088Z","etag":null,"topics":["cron","docker","swarm"],"latest_commit_sha":null,"homepage":"","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/webgriffe.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2022-10-18T13:59:52.000Z","updated_at":"2025-08-25T16:31:33.000Z","dependencies_parsed_at":"2025-01-29T10:31:28.481Z","dependency_job_id":"be48c8ea-6616-4322-bfb4-8da50fb06fda","html_url":"https://github.com/webgriffe/swarm-cron","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/webgriffe/swarm-cron","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/webgriffe%2Fswarm-cron","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/webgriffe%2Fswarm-cron/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/webgriffe%2Fswarm-cron/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/webgriffe%2Fswarm-cron/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/webgriffe","download_url":"https://codeload.github.com/webgriffe/swarm-cron/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/webgriffe%2Fswarm-cron/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":31892572,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-04-16T11:36:10.202Z","status":"ssl_error","status_checked_at":"2026-04-16T11:36:09.652Z","response_time":69,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.5:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["cron","docker","swarm"],"created_at":"2025-01-29T10:30:59.799Z","updated_at":"2026-04-16T15:34:27.218Z","avatar_url":"https://github.com/webgriffe.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Swarm Cron\n\nThis tool allows to schedule cron jobs using existing services running on Docker Swarm and making sure that a `docker stack deploy` does not interrupt a running cron job.\n\n## Usage\n\nGiven you have the following `docker-compose.yml` file deployed with `docker stack deploy -c docker-compose.yml my-app-stack`:\n\n```yaml\n\nversion: \"3.4\"\n\nservices:\n    my_app:\n        image: my-app-image:latest\n        volumes:\n            # All required volumes\n        environment:\n            # All required env vars\n        # ... all other service config\n    \n    # ... all other services\n```\n\nYou should have the service `my-app-stack_my_app` running on your Swarm (you can check it with `docker service ls`).\nTo activate swarm cron, add the `swarm_cron` service to your `docker-compose.yml` file as follows:\n\n```yaml\n\nversion: \"3.4\"\n\nservices:\n    my_app:\n        image: my-app-image:latest\n        volumes:\n            # All required volumes\n        environment:\n            # All required env vars\n        # ... all other service config\n    \n    # ... all other services\n    swarm_cron:\n        image: webgriffe/swarm-cron:main\n        volumes:\n            - \"/var/run/docker.sock:/var/run/docker.sock\"\n        deploy:\n            placement:\n                constraints:\n                    - node.role == manager        \n        environment:\n            SWARM_CRON_CRONTAB: |\n                # Cron expr          Full service name      Command to run\n                * *     * * *        my-app-stack_my_app    bin/cron1\n                0 2     * * *        my-app-stack_my_app    bin/cron2\n                # You can have comments too            \n                0 [3-6] * * *        my-app-stack_my_app    bin/cron3\n```\n\nYou're done! As you see the `swarm_cron` service is deployed on the manager node only and needs access to the Docker socket with the volume mount. The `SWARM_CRON_CRONTAB` environment variable is the actual crontab to configure your cron jobs. It's like a normal unix crontab with the only difference that after the cron expression and before the command you have to specify the full service name that have to be used to run that command. As explained above this name is usually the the format `\u003cSTACK_NAME\u003e_\u003cSERVICE_NAME\u003e` (where `\u003cSTACK_NAME\u003e` is the name of your stack used in the `docker stack deploy` command and `\u003cSERVICE_NAME\u003e` is the name of the service in the `docker-compose.yml` file).\n\n## Internals\n\nSwarm cron is written in [PHP](https://www.php.net/) 🐘 and it's based on the [Docker PHP Alpine image](https://hub.docker.com/_/php).\n\nWhen started the `SWARM_CRON_CRONTAB ` is converted into a normal unix crontab where each line runs the `/srv/app/swarm-cron run [service_name] [command]` command. Then the Alpine's `crond` process is started and run.\n\nWhen a cron expression is due to run the `/srv/app/swarm-cron run [service_name] [command]` is executed. This command uses the [Docker Engine API](https://docs.docker.com/engine/api/) to \"clone\" the service whose name is `[service_name]` and to start as a [replicated job](https://docs.docker.com/engine/reference/commandline/service_create/#running-as-a-job) in the Swarm, setting the command of that replicated job service to `[command]`. Swarm cron also ensure that an already running cron job is not restarted again if not completed.\n\n## Contributing\n\nTo be able to test changes on a local machine you have to do the following:\n\n1. Enter in swarm mode:\n\n\t```bash\n\tdocker swarm init\n\t```\n2. Create an example service to use to run cron jobs:\n\n\t```bash\n\tdocker service create --name swarm_cron_test -l com.docker.stack.namespace=test_stack alpine ping -c 80 google.com\n\t```\n3. Create an example swarm-cron crontab somewhere on your machine, for example in `/tmp/crontab`:\n\n\t```\n\t# A long running cron-job\n\t* * * * *           swarm_cron_test    ping -c 80 google.com\n\t# A short running cron-job\n\t* * * * *           swarm_cron_test    date\n\n\t# The content may vary depending on your needs\n\t```\n4. Run swarm-cron:\n\n\t```bash\n\tdocker build -t webgriffe/swarm-cron-scheduler:latest . \u0026\u0026 docker run --name swarm-cron --rm -v /var/run/docker.sock:/var/run/docker.sock -e \"SWARM_CRON_CRONTAB=$(cat /tmp/crontab)\" webgriffe/swarm-cron-scheduler:latest\n\t```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwebgriffe%2Fswarm-cron","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fwebgriffe%2Fswarm-cron","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwebgriffe%2Fswarm-cron/lists"}