Scheduling netbox-sync container
Hey, this is not as much a real issue, more a request to append documentation (to compensate for my lack of experience, probably).
I've been running netbox in docker for quote a while (running on a host with portainer as an easy management interface), and I now added the netbox-sync container and configured it. It works like a charm!
I appended the netbox-sync container to the netbox docker-compose file, which keeps everything running. But now netbox-sync keeps on running of course. It goes off and finishes in 45 seconds, then starts again, and again, and again, etc.
Now I know this is probably not how the sync container is meant to be run, but I would love the netbox-sync container to get an option to for example sleep 3600 seconds after every run, just to name an example? This way, I could have portainer/compose just keep the containers running and happy, and the sync would run regularly.
Or are there other ways to have a single docker compose file and to run this netbox-sync container on fixed intervals with a cron-like syntax or something?
Hi,
A quick and dirty solution would be adding a '&&', 'sleep', '3600' to the cmd line in docker-compose. have you tried that?
Well, I was not able to get any combination of entrypoint of cmd to work, python doesn't like that syntax:
netbox-sync | usage: netbox-sync.py [-h] [-c settings.ini [settings.ini ...]] [-g]
netbox-sync | [-l {DEBUG3,DEBUG2,DEBUG,INFO,WARNING,ERROR}] [-n] [-p]
netbox-sync | netbox-sync.py: error: unrecognized arguments: && sleep 3600
But I was able to create a script, mount that into the container and set it as entrypoint:
#puppet code
file { '/data/volumes/netbox-sync/start_with_sleep.sh':
ensure => present,
mode => '0700',
owner => 1000,
group => 1000,
content => '#!/bin/sh
python3 netbox-sync.py; sleep 3600',
require => File['/data/volumes/netbox-sync']
}
and in docker-compose:
[..]
netbox-sync:
container_name: netbox-sync
image: registry.company.local/dockerhub-proxy/bbricardo/netbox-sync
restart: always
entrypoint: ['/app/start_with_sleep.sh']
volumes:
- "/data/volumes/netbox-sync/start_with_sleep.sh:/app/start_with_sleep.sh:ro"
environment:
[..]
So I'm happy! But would still like a more native approach ;)
I'm doing it like this:
netbox-sync:
image: bbricardo/netbox-sync:latest
volumes:
- ./netbox-sync/settings.ini:/app/settings.ini
entrypoint: [ "sh", "-c" ]
command: >
"while true; do
echo '[INFO] Running netbox-sync at $(date)';
python3 netbox-sync.py -c settings.ini;
echo '[INFO] Sleeping...';
sleep 86400;
done"
I'm doing it like this:
netbox-sync: image: bbricardo/netbox-sync:latest volumes: - ./netbox-sync/settings.ini:/app/settings.ini entrypoint: [ "sh", "-c" ] command: > "while true; do echo '[INFO] Running netbox-sync at $(date)'; python3 netbox-sync.py -c settings.ini; echo '[INFO] Sleeping...'; sleep 86400; done"
This looks like a fairly good solution. @AxisNL : what do you think? does this solver your issue?
closing this issue due to no response.