mirror of
https://github.com/YunoHost/yunohost.git
synced 2024-09-03 20:06:10 +02:00
Handle the dyndns cron from the regenconf
This commit is contained in:
parent
675c4d0eea
commit
7efc6dcd07
2 changed files with 30 additions and 7 deletions
|
@ -86,6 +86,17 @@ SHELL=/bin/bash
|
||||||
0 7,19 * * * root : YunoHost Automatic Diagnosis; sleep \$((RANDOM\\%1200)); yunohost diagnosis run --email > /dev/null 2>/dev/null || echo "Running the automatic diagnosis failed miserably"
|
0 7,19 * * * root : YunoHost Automatic Diagnosis; sleep \$((RANDOM\\%1200)); yunohost diagnosis run --email > /dev/null 2>/dev/null || echo "Running the automatic diagnosis failed miserably"
|
||||||
EOF
|
EOF
|
||||||
|
|
||||||
|
# If we subscribed to a dyndns domain, add the corresponding cron
|
||||||
|
# - delay between 0 and 60 secs to spread the check over a 1 min window
|
||||||
|
# - do not run the command if some process already has the lock, to avoid queuing hundreds of commands...
|
||||||
|
if ls -l /etc/yunohost/dyndns/K*.private 2>/dev/null
|
||||||
|
then
|
||||||
|
cat > $pending_dir/etc/cron.d/yunohost-dyndns << EOF
|
||||||
|
SHELL=/bin/bash
|
||||||
|
*/10 * * * * root : YunoHost DynDNS update; sleep \$((RANDOM\\%60)); test -e /var/run/moulinette_yunohost.lock || yunohost dyndns update >> /dev/null
|
||||||
|
EOF
|
||||||
|
fi
|
||||||
|
|
||||||
# legacy stuff to avoid yunohost reporting etckeeper as manually modified
|
# legacy stuff to avoid yunohost reporting etckeeper as manually modified
|
||||||
# (this make sure that the hash is null / file is flagged as to-delete)
|
# (this make sure that the hash is null / file is flagged as to-delete)
|
||||||
mkdir -p $pending_dir/etc/etckeeper
|
mkdir -p $pending_dir/etc/etckeeper
|
||||||
|
|
|
@ -40,6 +40,7 @@ from yunohost.utils.error import YunohostError
|
||||||
from yunohost.domain import _get_maindomain, _build_dns_conf
|
from yunohost.domain import _get_maindomain, _build_dns_conf
|
||||||
from yunohost.utils.network import get_public_ip, dig
|
from yunohost.utils.network import get_public_ip, dig
|
||||||
from yunohost.log import is_unit_operation
|
from yunohost.log import is_unit_operation
|
||||||
|
from yunohost.regenconf import regen_conf
|
||||||
|
|
||||||
logger = getActionLogger("yunohost.dyndns")
|
logger = getActionLogger("yunohost.dyndns")
|
||||||
|
|
||||||
|
@ -121,10 +122,9 @@ def dyndns_subscribe(
|
||||||
subscribe_host -- Dynette HTTP API to subscribe to
|
subscribe_host -- Dynette HTTP API to subscribe to
|
||||||
|
|
||||||
"""
|
"""
|
||||||
if len(glob.glob("/etc/yunohost/dyndns/*.key")) != 0 or os.path.exists(
|
|
||||||
"/etc/cron.d/yunohost-dyndns"
|
if _guess_current_dyndns_domain(dyn_host) != (None, None):
|
||||||
):
|
raise YunohostError('domain_dyndns_already_subscribed')
|
||||||
raise YunohostError("domain_dyndns_already_subscribed")
|
|
||||||
|
|
||||||
if domain is None:
|
if domain is None:
|
||||||
domain = _get_maindomain()
|
domain = _get_maindomain()
|
||||||
|
@ -186,9 +186,17 @@ def dyndns_subscribe(
|
||||||
error = 'Server error, code: %s. (Message: "%s")' % (r.status_code, r.text)
|
error = 'Server error, code: %s. (Message: "%s")' % (r.status_code, r.text)
|
||||||
raise YunohostError("dyndns_registration_failed", error=error)
|
raise YunohostError("dyndns_registration_failed", error=error)
|
||||||
|
|
||||||
logger.success(m18n.n("dyndns_registered"))
|
# Yunohost regen conf will add the dyndns cron job if a private key exists
|
||||||
|
# in /etc/yunohost/dyndns
|
||||||
|
regen_conf("yunohost")
|
||||||
|
|
||||||
dyndns_installcron()
|
# Add some dyndns update in 2 and 4 minutes from now such that user should
|
||||||
|
# not have to wait 10ish minutes for the conf to propagate
|
||||||
|
cmd = "at -M now + {t} >/dev/null 2>&1 <<< \"/bin/bash -c 'yunohost dyndns update'\""
|
||||||
|
subprocess.check_call(cmd.format(t="2 min"), shell=True)
|
||||||
|
subprocess.check_call(cmd.format(t="4 min"), shell=True)
|
||||||
|
|
||||||
|
logger.success(m18n.n('dyndns_registered'))
|
||||||
|
|
||||||
|
|
||||||
@is_unit_operation()
|
@is_unit_operation()
|
||||||
|
@ -220,6 +228,10 @@ def dyndns_update(
|
||||||
# If domain is not given, try to guess it from keys available...
|
# If domain is not given, try to guess it from keys available...
|
||||||
if domain is None:
|
if domain is None:
|
||||||
(domain, key) = _guess_current_dyndns_domain(dyn_host)
|
(domain, key) = _guess_current_dyndns_domain(dyn_host)
|
||||||
|
|
||||||
|
if domain is None:
|
||||||
|
raise YunohostError('dyndns_no_domain_registered')
|
||||||
|
|
||||||
# If key is not given, pick the first file we find with the domain given
|
# If key is not given, pick the first file we find with the domain given
|
||||||
else:
|
else:
|
||||||
if key is None:
|
if key is None:
|
||||||
|
@ -414,4 +426,4 @@ def _guess_current_dyndns_domain(dyn_host):
|
||||||
else:
|
else:
|
||||||
return (_domain, path)
|
return (_domain, path)
|
||||||
|
|
||||||
raise YunohostError("dyndns_no_domain_registered")
|
return (None, None)
|
||||||
|
|
Loading…
Add table
Reference in a new issue