mirror of
https://github.com/YunoHost/yunohost.git
synced 2024-09-03 20:06:10 +02:00
[enh] Add a dry-run option for service_regen_conf
This commit is contained in:
parent
26adf05042
commit
cdf3c13bf5
20 changed files with 82 additions and 45 deletions
|
@ -980,6 +980,10 @@ service:
|
||||||
Override all manual modifications in configuration
|
Override all manual modifications in configuration
|
||||||
files
|
files
|
||||||
action: store_true
|
action: store_true
|
||||||
|
-n:
|
||||||
|
full: --dry-run
|
||||||
|
help: Show what would have been regenerated
|
||||||
|
action: store_true
|
||||||
-p:
|
-p:
|
||||||
full: --list-pending
|
full: --list-pending
|
||||||
help: List pending configuration files and exit
|
help: List pending configuration files and exit
|
||||||
|
|
|
@ -91,10 +91,11 @@ EOF
|
||||||
}
|
}
|
||||||
|
|
||||||
FORCE=$2
|
FORCE=$2
|
||||||
|
DRY_RUN=$3
|
||||||
|
|
||||||
case "$1" in
|
case "$1" in
|
||||||
pre)
|
pre)
|
||||||
do_pre_regen $3
|
do_pre_regen $4
|
||||||
;;
|
;;
|
||||||
post)
|
post)
|
||||||
;;
|
;;
|
||||||
|
|
|
@ -72,13 +72,14 @@ do_post_regen() {
|
||||||
}
|
}
|
||||||
|
|
||||||
FORCE=$2
|
FORCE=$2
|
||||||
|
DRY_RUN=$3
|
||||||
|
|
||||||
case "$1" in
|
case "$1" in
|
||||||
pre)
|
pre)
|
||||||
do_pre_regen $3
|
do_pre_regen $4
|
||||||
;;
|
;;
|
||||||
post)
|
post)
|
||||||
do_post_regen $3
|
do_post_regen $4
|
||||||
;;
|
;;
|
||||||
init)
|
init)
|
||||||
do_init_regen
|
do_init_regen
|
||||||
|
|
|
@ -27,13 +27,14 @@ do_post_regen() {
|
||||||
}
|
}
|
||||||
|
|
||||||
FORCE=$2
|
FORCE=$2
|
||||||
|
DRY_RUN=$3
|
||||||
|
|
||||||
case "$1" in
|
case "$1" in
|
||||||
pre)
|
pre)
|
||||||
do_pre_regen $3
|
do_pre_regen $4
|
||||||
;;
|
;;
|
||||||
post)
|
post)
|
||||||
do_post_regen $3
|
do_post_regen $4
|
||||||
;;
|
;;
|
||||||
*)
|
*)
|
||||||
echo "hook called with unknown argument \`$1'" >&2
|
echo "hook called with unknown argument \`$1'" >&2
|
||||||
|
|
|
@ -72,13 +72,14 @@ do_post_regen() {
|
||||||
}
|
}
|
||||||
|
|
||||||
FORCE=$2
|
FORCE=$2
|
||||||
|
DRY_RUN=$3
|
||||||
|
|
||||||
case "$1" in
|
case "$1" in
|
||||||
pre)
|
pre)
|
||||||
do_pre_regen $3
|
do_pre_regen $4
|
||||||
;;
|
;;
|
||||||
post)
|
post)
|
||||||
do_post_regen $3
|
do_post_regen $4
|
||||||
;;
|
;;
|
||||||
*)
|
*)
|
||||||
echo "hook called with unknown argument \`$1'" >&2
|
echo "hook called with unknown argument \`$1'" >&2
|
||||||
|
|
|
@ -18,13 +18,14 @@ do_post_regen() {
|
||||||
}
|
}
|
||||||
|
|
||||||
FORCE=$2
|
FORCE=$2
|
||||||
|
DRY_RUN=$3
|
||||||
|
|
||||||
case "$1" in
|
case "$1" in
|
||||||
pre)
|
pre)
|
||||||
do_pre_regen $3
|
do_pre_regen $4
|
||||||
;;
|
;;
|
||||||
post)
|
post)
|
||||||
do_post_regen $3
|
do_post_regen $4
|
||||||
;;
|
;;
|
||||||
*)
|
*)
|
||||||
echo "hook called with unknown argument \`$1'" >&2
|
echo "hook called with unknown argument \`$1'" >&2
|
||||||
|
|
|
@ -58,13 +58,14 @@ do_post_regen() {
|
||||||
}
|
}
|
||||||
|
|
||||||
FORCE=$2
|
FORCE=$2
|
||||||
|
DRY_RUN=$3
|
||||||
|
|
||||||
case "$1" in
|
case "$1" in
|
||||||
pre)
|
pre)
|
||||||
do_pre_regen $3
|
do_pre_regen $4
|
||||||
;;
|
;;
|
||||||
post)
|
post)
|
||||||
do_post_regen $3
|
do_post_regen $4
|
||||||
;;
|
;;
|
||||||
*)
|
*)
|
||||||
echo "hook called with unknown argument \`$1'" >&2
|
echo "hook called with unknown argument \`$1'" >&2
|
||||||
|
|
|
@ -80,13 +80,14 @@ do_post_regen() {
|
||||||
}
|
}
|
||||||
|
|
||||||
FORCE=$2
|
FORCE=$2
|
||||||
|
DRY_RUN=$3
|
||||||
|
|
||||||
case "$1" in
|
case "$1" in
|
||||||
pre)
|
pre)
|
||||||
do_pre_regen $3
|
do_pre_regen $4
|
||||||
;;
|
;;
|
||||||
post)
|
post)
|
||||||
do_post_regen $3
|
do_post_regen $4
|
||||||
;;
|
;;
|
||||||
init)
|
init)
|
||||||
do_init_regen
|
do_init_regen
|
||||||
|
|
|
@ -38,13 +38,14 @@ do_post_regen() {
|
||||||
}
|
}
|
||||||
|
|
||||||
FORCE=$2
|
FORCE=$2
|
||||||
|
DRY_RUN=$3
|
||||||
|
|
||||||
case "$1" in
|
case "$1" in
|
||||||
pre)
|
pre)
|
||||||
do_pre_regen $3
|
do_pre_regen $4
|
||||||
;;
|
;;
|
||||||
post)
|
post)
|
||||||
do_post_regen $3
|
do_post_regen $4
|
||||||
;;
|
;;
|
||||||
*)
|
*)
|
||||||
echo "hook called with unknown argument \`$1'" >&2
|
echo "hook called with unknown argument \`$1'" >&2
|
||||||
|
|
|
@ -51,13 +51,14 @@ do_post_regen() {
|
||||||
}
|
}
|
||||||
|
|
||||||
FORCE=$2
|
FORCE=$2
|
||||||
|
DRY_RUN=$3
|
||||||
|
|
||||||
case "$1" in
|
case "$1" in
|
||||||
pre)
|
pre)
|
||||||
do_pre_regen $3
|
do_pre_regen $4
|
||||||
;;
|
;;
|
||||||
post)
|
post)
|
||||||
do_post_regen $3
|
do_post_regen $4
|
||||||
;;
|
;;
|
||||||
*)
|
*)
|
||||||
echo "hook called with unknown argument \`$1'" >&2
|
echo "hook called with unknown argument \`$1'" >&2
|
||||||
|
|
|
@ -46,13 +46,14 @@ do_post_regen() {
|
||||||
}
|
}
|
||||||
|
|
||||||
FORCE=$2
|
FORCE=$2
|
||||||
|
DRY_RUN=$3
|
||||||
|
|
||||||
case "$1" in
|
case "$1" in
|
||||||
pre)
|
pre)
|
||||||
do_pre_regen $3
|
do_pre_regen $4
|
||||||
;;
|
;;
|
||||||
post)
|
post)
|
||||||
do_post_regen $3
|
do_post_regen $4
|
||||||
;;
|
;;
|
||||||
*)
|
*)
|
||||||
echo "hook called with unknown argument \`$1'" >&2
|
echo "hook called with unknown argument \`$1'" >&2
|
||||||
|
|
|
@ -32,13 +32,14 @@ do_post_regen() {
|
||||||
}
|
}
|
||||||
|
|
||||||
FORCE=$2
|
FORCE=$2
|
||||||
|
DRY_RUN=$3
|
||||||
|
|
||||||
case "$1" in
|
case "$1" in
|
||||||
pre)
|
pre)
|
||||||
do_pre_regen $3
|
do_pre_regen $4
|
||||||
;;
|
;;
|
||||||
post)
|
post)
|
||||||
do_post_regen $3
|
do_post_regen $4
|
||||||
;;
|
;;
|
||||||
*)
|
*)
|
||||||
echo "hook called with unknown argument \`$1'" >&2
|
echo "hook called with unknown argument \`$1'" >&2
|
||||||
|
|
|
@ -33,13 +33,14 @@ do_post_regen() {
|
||||||
}
|
}
|
||||||
|
|
||||||
FORCE=$2
|
FORCE=$2
|
||||||
|
DRY_RUN=$3
|
||||||
|
|
||||||
case "$1" in
|
case "$1" in
|
||||||
pre)
|
pre)
|
||||||
do_pre_regen $3
|
do_pre_regen $4
|
||||||
;;
|
;;
|
||||||
post)
|
post)
|
||||||
do_post_regen $3
|
do_post_regen $4
|
||||||
;;
|
;;
|
||||||
*)
|
*)
|
||||||
echo "hook called with unknown argument \`$1'" >&2
|
echo "hook called with unknown argument \`$1'" >&2
|
||||||
|
|
|
@ -18,13 +18,14 @@ do_post_regen() {
|
||||||
}
|
}
|
||||||
|
|
||||||
FORCE=$2
|
FORCE=$2
|
||||||
|
DRY_RUN=$3
|
||||||
|
|
||||||
case "$1" in
|
case "$1" in
|
||||||
pre)
|
pre)
|
||||||
do_pre_regen $3
|
do_pre_regen $4
|
||||||
;;
|
;;
|
||||||
post)
|
post)
|
||||||
do_post_regen $3
|
do_post_regen $4
|
||||||
;;
|
;;
|
||||||
*)
|
*)
|
||||||
echo "hook called with unknown argument \`$1'" >&2
|
echo "hook called with unknown argument \`$1'" >&2
|
||||||
|
|
|
@ -18,13 +18,14 @@ do_post_regen() {
|
||||||
}
|
}
|
||||||
|
|
||||||
FORCE=$2
|
FORCE=$2
|
||||||
|
DRY_RUN=$3
|
||||||
|
|
||||||
case "$1" in
|
case "$1" in
|
||||||
pre)
|
pre)
|
||||||
do_pre_regen $3
|
do_pre_regen $4
|
||||||
;;
|
;;
|
||||||
post)
|
post)
|
||||||
do_post_regen $3
|
do_post_regen $4
|
||||||
;;
|
;;
|
||||||
*)
|
*)
|
||||||
echo "hook called with unknown argument \`$1'" >&2
|
echo "hook called with unknown argument \`$1'" >&2
|
||||||
|
|
|
@ -48,13 +48,14 @@ do_post_regen() {
|
||||||
}
|
}
|
||||||
|
|
||||||
FORCE=$2
|
FORCE=$2
|
||||||
|
DRY_RUN=$3
|
||||||
|
|
||||||
case "$1" in
|
case "$1" in
|
||||||
pre)
|
pre)
|
||||||
do_pre_regen $3
|
do_pre_regen $4
|
||||||
;;
|
;;
|
||||||
post)
|
post)
|
||||||
do_post_regen $3
|
do_post_regen $4
|
||||||
;;
|
;;
|
||||||
*)
|
*)
|
||||||
echo "hook called with unknown argument \`$1'" >&2
|
echo "hook called with unknown argument \`$1'" >&2
|
||||||
|
|
|
@ -18,13 +18,14 @@ do_post_regen() {
|
||||||
}
|
}
|
||||||
|
|
||||||
FORCE=$2
|
FORCE=$2
|
||||||
|
DRY_RUN=$3
|
||||||
|
|
||||||
case "$1" in
|
case "$1" in
|
||||||
pre)
|
pre)
|
||||||
do_pre_regen $3
|
do_pre_regen $4
|
||||||
;;
|
;;
|
||||||
post)
|
post)
|
||||||
do_post_regen $3
|
do_post_regen $4
|
||||||
;;
|
;;
|
||||||
*)
|
*)
|
||||||
echo "hook called with unknown argument \`$1'" >&2
|
echo "hook called with unknown argument \`$1'" >&2
|
||||||
|
|
|
@ -22,13 +22,14 @@ do_post_regen() {
|
||||||
}
|
}
|
||||||
|
|
||||||
FORCE=$2
|
FORCE=$2
|
||||||
|
DRY_RUN=$3
|
||||||
|
|
||||||
case "$1" in
|
case "$1" in
|
||||||
pre)
|
pre)
|
||||||
do_pre_regen $3
|
do_pre_regen $4
|
||||||
;;
|
;;
|
||||||
post)
|
post)
|
||||||
do_post_regen $3
|
do_post_regen $4
|
||||||
;;
|
;;
|
||||||
*)
|
*)
|
||||||
echo "hook called with unknown argument \`$1'" >&2
|
echo "hook called with unknown argument \`$1'" >&2
|
||||||
|
|
|
@ -130,6 +130,7 @@
|
||||||
"service_cmd_exec_failed" : "Unable to execute command '{command:s}'",
|
"service_cmd_exec_failed" : "Unable to execute command '{command:s}'",
|
||||||
"service_regenconf_failed" : "Unable to regenerate the configuration for service(s): {services}",
|
"service_regenconf_failed" : "Unable to regenerate the configuration for service(s): {services}",
|
||||||
"service_regenconf_pending_applying" : "Applying pending configuration for service '{service}'...",
|
"service_regenconf_pending_applying" : "Applying pending configuration for service '{service}'...",
|
||||||
|
"service_regenconf_dry_pending_applying" : "Checking pending configuration which would have been applied for service '{service}'...",
|
||||||
"service_conf_file_manually_removed" : "The configuration file '{conf}' has been manually removed and will not be created",
|
"service_conf_file_manually_removed" : "The configuration file '{conf}' has been manually removed and will not be created",
|
||||||
"service_conf_file_manually_modified" : "The configuration file '{conf}' has been manually modified and will not be updated",
|
"service_conf_file_manually_modified" : "The configuration file '{conf}' has been manually modified and will not be updated",
|
||||||
"service_conf_file_not_managed" : "The configuration file '{conf}' is not managed yet and will not be updated",
|
"service_conf_file_not_managed" : "The configuration file '{conf}' is not managed yet and will not be updated",
|
||||||
|
@ -140,6 +141,7 @@
|
||||||
"service_conf_file_copy_failed" : "Unable to copy the new configuration file '{new}' to '{conf}'",
|
"service_conf_file_copy_failed" : "Unable to copy the new configuration file '{new}' to '{conf}'",
|
||||||
"service_conf_up_to_date" : "The configuration is already up-to-date for service '{service}'",
|
"service_conf_up_to_date" : "The configuration is already up-to-date for service '{service}'",
|
||||||
"service_conf_updated" : "The configuration has been updated for service '{service}'",
|
"service_conf_updated" : "The configuration has been updated for service '{service}'",
|
||||||
|
"service_conf_would_be_updated" : "The configuration would have been updated for service '{service}'",
|
||||||
|
|
||||||
"network_check_smtp_ok" : "Outbound mail (SMTP port 25) is not blocked",
|
"network_check_smtp_ok" : "Outbound mail (SMTP port 25) is not blocked",
|
||||||
"network_check_smtp_ko" : "Outbound mail (SMTP port 25) seems to be blocked by your network",
|
"network_check_smtp_ko" : "Outbound mail (SMTP port 25) seems to be blocked by your network",
|
||||||
|
|
|
@ -271,7 +271,7 @@ def service_log(name, number=50):
|
||||||
return result
|
return result
|
||||||
|
|
||||||
|
|
||||||
def service_regen_conf(names=[], with_diff=False, force=False,
|
def service_regen_conf(names=[], with_diff=False, force=False, dry_run=False,
|
||||||
list_pending=False):
|
list_pending=False):
|
||||||
"""
|
"""
|
||||||
Regenerate the configuration file(s) for a service
|
Regenerate the configuration file(s) for a service
|
||||||
|
@ -280,6 +280,7 @@ def service_regen_conf(names=[], with_diff=False, force=False,
|
||||||
names -- Services name to regenerate configuration of
|
names -- Services name to regenerate configuration of
|
||||||
with_diff -- Show differences in case of configuration changes
|
with_diff -- Show differences in case of configuration changes
|
||||||
force -- Override all manual modifications in configuration files
|
force -- Override all manual modifications in configuration files
|
||||||
|
dry_run -- Show what would have been regenerated
|
||||||
list_pending -- List pending configuration files and exit
|
list_pending -- List pending configuration files and exit
|
||||||
|
|
||||||
"""
|
"""
|
||||||
|
@ -303,7 +304,7 @@ def service_regen_conf(names=[], with_diff=False, force=False,
|
||||||
filesystem.mkdir(pending_conf_dir, 0755, True)
|
filesystem.mkdir(pending_conf_dir, 0755, True)
|
||||||
|
|
||||||
# Format common hooks arguments
|
# Format common hooks arguments
|
||||||
common_args = [1 if force else 0,]
|
common_args = [1 if force else 0, 1 if dry_run else 0]
|
||||||
|
|
||||||
# Execute hooks for pre-regen
|
# Execute hooks for pre-regen
|
||||||
pre_args = ['pre',] + common_args
|
pre_args = ['pre',] + common_args
|
||||||
|
@ -322,10 +323,16 @@ def service_regen_conf(names=[], with_diff=False, force=False,
|
||||||
m18n.n('service_regenconf_failed',
|
m18n.n('service_regenconf_failed',
|
||||||
services=', '.join(pre_result['failed'])))
|
services=', '.join(pre_result['failed'])))
|
||||||
|
|
||||||
|
# Set the processing method
|
||||||
|
_regen = _process_regen_conf if not dry_run else lambda *a, **k: True
|
||||||
|
|
||||||
# Iterate over services and process pending conf
|
# Iterate over services and process pending conf
|
||||||
for service, conf_files in _get_pending_conf(names).items():
|
for service, conf_files in _get_pending_conf(names).items():
|
||||||
logger.info(m18n.n('service_regenconf_pending_applying',
|
logger.info(m18n.n(
|
||||||
service=service))
|
'service_regenconf_pending_applying' if not dry_run else \
|
||||||
|
'service_regenconf_dry_pending_applying',
|
||||||
|
service=service))
|
||||||
|
|
||||||
conf_hashes = _get_conf_hashes(service)
|
conf_hashes = _get_conf_hashes(service)
|
||||||
succeed_regen = {}
|
succeed_regen = {}
|
||||||
failed_regen = {}
|
failed_regen = {}
|
||||||
|
@ -361,7 +368,7 @@ def service_regen_conf(names=[], with_diff=False, force=False,
|
||||||
else:
|
else:
|
||||||
logger.debug("> system conf does not exist yet")
|
logger.debug("> system conf does not exist yet")
|
||||||
conf_status = 'created'
|
conf_status = 'created'
|
||||||
regenerated = _process_regen_conf(
|
regenerated = _regen(
|
||||||
system_path, pending_path, save=False)
|
system_path, pending_path, save=False)
|
||||||
else:
|
else:
|
||||||
logger.warning(m18n.n(
|
logger.warning(m18n.n(
|
||||||
|
@ -376,10 +383,10 @@ def service_regen_conf(names=[], with_diff=False, force=False,
|
||||||
conf_status = 'managed'
|
conf_status = 'managed'
|
||||||
regenerated = True
|
regenerated = True
|
||||||
elif force and to_remove:
|
elif force and to_remove:
|
||||||
regenerated = _process_regen_conf(system_path)
|
regenerated = _regen(system_path)
|
||||||
conf_status = 'force-removed'
|
conf_status = 'force-removed'
|
||||||
elif force:
|
elif force:
|
||||||
regenerated = _process_regen_conf(system_path, pending_path)
|
regenerated = _regen(system_path, pending_path)
|
||||||
conf_status = 'force-updated'
|
conf_status = 'force-updated'
|
||||||
else:
|
else:
|
||||||
logger.warning(m18n.n('service_conf_file_not_managed',
|
logger.warning(m18n.n('service_conf_file_not_managed',
|
||||||
|
@ -388,10 +395,10 @@ def service_regen_conf(names=[], with_diff=False, force=False,
|
||||||
# -> system conf has not been manually modified
|
# -> system conf has not been manually modified
|
||||||
elif system_hash == current_hash:
|
elif system_hash == current_hash:
|
||||||
if to_remove:
|
if to_remove:
|
||||||
regenerated = _process_regen_conf(system_path)
|
regenerated = _regen(system_path)
|
||||||
conf_status = 'removed'
|
conf_status = 'removed'
|
||||||
elif system_hash != new_hash:
|
elif system_hash != new_hash:
|
||||||
regenerated = _process_regen_conf(system_path, pending_path)
|
regenerated = _regen(system_path, pending_path)
|
||||||
conf_status = 'updated'
|
conf_status = 'updated'
|
||||||
else:
|
else:
|
||||||
logger.debug("> system conf is already up-to-date")
|
logger.debug("> system conf is already up-to-date")
|
||||||
|
@ -400,7 +407,7 @@ def service_regen_conf(names=[], with_diff=False, force=False,
|
||||||
else:
|
else:
|
||||||
logger.debug("> system conf has been manually modified")
|
logger.debug("> system conf has been manually modified")
|
||||||
if force:
|
if force:
|
||||||
regenerated = _process_regen_conf(system_path, pending_path)
|
regenerated = _regen(system_path, pending_path)
|
||||||
conf_status = 'force-updated'
|
conf_status = 'force-updated'
|
||||||
else:
|
else:
|
||||||
logger.warning(m18n.n(
|
logger.warning(m18n.n(
|
||||||
|
@ -425,8 +432,11 @@ def service_regen_conf(names=[], with_diff=False, force=False,
|
||||||
logger.info(m18n.n('service_conf_up_to_date', service=service))
|
logger.info(m18n.n('service_conf_up_to_date', service=service))
|
||||||
continue
|
continue
|
||||||
elif not failed_regen:
|
elif not failed_regen:
|
||||||
logger.success(m18n.n('service_conf_updated', service=service))
|
logger.success(m18n.n(
|
||||||
if succeed_regen:
|
'service_conf_updated' if not dry_run else \
|
||||||
|
'service_conf_would_be_updated',
|
||||||
|
service=service))
|
||||||
|
if succeed_regen and not dry_run:
|
||||||
_update_conf_hashes(service, conf_hashes)
|
_update_conf_hashes(service, conf_hashes)
|
||||||
|
|
||||||
# Append the service results
|
# Append the service results
|
||||||
|
@ -435,6 +445,10 @@ def service_regen_conf(names=[], with_diff=False, force=False,
|
||||||
'pending': failed_regen
|
'pending': failed_regen
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# Return in case of dry run
|
||||||
|
if dry_run:
|
||||||
|
return result
|
||||||
|
|
||||||
# Execute hooks for post-regen
|
# Execute hooks for post-regen
|
||||||
post_args = ['post',] + common_args
|
post_args = ['post',] + common_args
|
||||||
def _pre_call(name, priority, path, args):
|
def _pre_call(name, priority, path, args):
|
||||||
|
|
Loading…
Add table
Reference in a new issue