mirror of
https://github.com/cwinfo/powerdns-admin.git
synced 2024-12-30 15:05:39 +00:00
Update update_zones.py bg script
This commit is contained in:
parent
8de6df4d3b
commit
0234f21e1d
@ -1,8 +1,8 @@
|
|||||||
#!/usr/bin/env python3
|
#!/usr/bin/env python3
|
||||||
|
|
||||||
####################################################################################################################################
|
####################################################################################################################################
|
||||||
# A CLI Script to update list of domains instead from the UI. Can be useful for people who want to execute updates from a cronjob
|
# A CLI Script to update list of domains instead from the UI. Can be useful for people who want to execute updates from a cronjob
|
||||||
#
|
#
|
||||||
# Tip:
|
# Tip:
|
||||||
# When running from a cron, use flock (you might need to install it) to be sure only one process is running a time. eg:
|
# When running from a cron, use flock (you might need to install it) to be sure only one process is running a time. eg:
|
||||||
# */5 * * * * flock -xn "/tmp/pdns-update-zones.lock" python /var/www/html/apps/poweradmin/update_zones.py >/dev/null 2>&1
|
# */5 * * * * flock -xn "/tmp/pdns-update-zones.lock" python /var/www/html/apps/poweradmin/update_zones.py >/dev/null 2>&1
|
||||||
@ -10,21 +10,26 @@
|
|||||||
##############################################################
|
##############################################################
|
||||||
|
|
||||||
### Imports
|
### Imports
|
||||||
from powerdnsadmin.models.domain import Domain
|
|
||||||
from config import BG_DOMAIN_UPDATES
|
|
||||||
|
|
||||||
import sys
|
import sys
|
||||||
import logging as logger
|
import logging
|
||||||
|
|
||||||
### Define logging
|
from flask import current_app
|
||||||
logging = logger.getLogger(__name__)
|
from powerdnsadmin import create_app
|
||||||
|
from powerdnsadmin.models.domain import Domain
|
||||||
|
from powerdnsadmin.models.setting import Setting
|
||||||
|
|
||||||
### Check if BG_DOMAIN_UPDATES is set to true
|
app = create_app()
|
||||||
if not BG_DOMAIN_UPDATES:
|
app.logger.setLevel(logging.INFO)
|
||||||
logging.error('Set BG_DOMAIN_UPDATES to True in config.py')
|
|
||||||
sys.exit(1)
|
|
||||||
|
|
||||||
### Start the update process
|
with app.app_context():
|
||||||
logging.info('Update zones from nameserver API')
|
status = Setting().get('bg_domain_updates')
|
||||||
|
|
||||||
d = Domain().update()
|
### Check if bg_domain_updates is set to true
|
||||||
|
if not status:
|
||||||
|
app.logger.error('Please turn on "bg_domain_updates" setting to run this job.')
|
||||||
|
sys.exit(1)
|
||||||
|
|
||||||
|
### Start the update process
|
||||||
|
app.logger.info('Update zones from nameserver API')
|
||||||
|
|
||||||
|
d = Domain().update()
|
||||||
|
Loading…
Reference in New Issue
Block a user