Verified Commit 772939b0 authored by Karel Koci's avatar Karel Koci 🤘
Browse files

Added option --no-network-fail

This option should be used for example from cron to not spam pkgupdate
when we know it is going to fail. It also prevents from spamming users
because of failed update executions.
parent a5e0e6ca
......@@ -4,6 +4,13 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
## [Unreleased]
### Added
- Option `--no-network-fail` to skip updater run when network connection is
unavailable
- Possibility to disable network test by setting zero
- System shutdown is now retained till there is process holding opkg lock
## [1.3.2] - 2020-08-17
### Changed
- pkgupdate is now not run with `--task-log`
......
......@@ -5,7 +5,7 @@ from svupdater.prerun import random_sleep, wait_for_network
from svupdater._supervisor import run
from svupdater.const import PKGUPDATE_TIMEOUT, PKGUPDATE_TIMEOUT_KILL
from svupdater.const import PING_TIMEOUT
from svupdater.utils import daemonize
from svupdater.utils import daemonize, report
HELP_DESCRIPTION = """
Updater-ng supervisor used for system updating.
......@@ -21,39 +21,38 @@ def parse_arguments():
""")
prs.add_argument('--rand-sleep', const=7200, nargs='?', type=int,
help="""
Sleep random amount of the time with maximum of given
number of seconds. In default two hours are used.
Sleep random amount of the time with maximum of given number of seconds. In default two hours are
used.
""")
prs.add_argument('--wait-for-network', const=PING_TIMEOUT, type=int,
nargs='?', help="""
Check if Turris repository is accessible (even before
going to background). You can specify timeout in seconds
as an argument. 10 seconds is used if no argument is
specified.
Check if Turris repository is accessible (even before going to background). You can specify timeout
in seconds as an argument. 10 seconds is used if no argument is specified. Specify zero to disable
network check.
""")
prs.add_argument('--no-network-fail', action='store_true',
help="""
Do not run pkgupdate when network connection is not detected.
""")
prs.add_argument('--ensure-run', action='store_true',
help="""
Make sure that updater runs at least once after current
time. This can be used to ensure that latest changes are
applied as soon as possible even if another instance of
updater is already running.
Make sure that updater runs at least once after current time. This can be used to ensure that
latest changes are applied as soon as possible even if another instance of updater is already
running.
""")
prs.add_argument('--quiet', '-q', action='store_true',
help="""
Don't print pkgupdate's output to console. But still print
supervisor output.
Don't print pkgupdate's output to console. But still print supervisor output.
""")
prs.add_argument('--timeout', default=PKGUPDATE_TIMEOUT,
help="""
Set time limit in seconds for updater execution. pkgupdate
is gracefully exited when this timeout runs out. This is
protection for pkgupdate stall. In defaut one hour is set
as timeout.
Set time limit in seconds for updater execution. pkgupdate is gracefully exited when this timeout
runs out. This is protection for pkgupdate stall. In defaut one hour is set as timeout.
""")
prs.add_argument('--timeout-kill', default=PKGUPDATE_TIMEOUT_KILL,
help="""
Set time in seconds after which pkgupdate is killed. This
is time from timeout. In default one minute is used.
Set time in seconds after which pkgupdate is killed. This is time from timeout. In default one
minute is used.
""")
return prs.parse_args()
......@@ -69,8 +68,11 @@ def main():
if args.daemon and daemonize():
return
random_sleep(args.rand_sleep)
wait_for_network(args.wait_for_network)
if args.rand_sleep > 0:
random_sleep(args.rand_sleep)
if not wait_for_network(args.wait_for_network) and not args.no_network_fail:
report("There seems to be no network connection to Turris servers. Please try again later.")
sys.exit(1)
sys.exit(run(
ensure_run=args.ensure_run,
......
......@@ -20,21 +20,24 @@ def random_sleep(max_seconds):
report("Suspending updater start for " + str(suspend) + " seconds")
time.sleep(suspend)
def ping(address=PING_ADDRESS, count=1, deadline=1):
"""Ping address with given amount of pings and deadline.
Returns True on success and False if ping fails.
"""
with open(os.devnull, 'w') as devnull:
return subprocess.call(
['ping', '-c', str(count), '-w', str(deadline), address],
stdin=devnull,
stdout=devnull,
stderr=devnull
)
def wait_for_network(max_stall):
"""This tries to connect to repo.turris.cz to check if we can access it and
otherwise it stalls execution for given maximum number of seconds.
Returns True if connection is successful and False otherwise.
"""
def ping():
"""Just run one second timeout single ping to check if we have
connection """
with open(os.devnull, 'w') as devnull:
return subprocess.call(
['ping', '-c', '1', '-w', '1', PING_ADDRESS],
stdin=devnull,
stdout=devnull,
stderr=devnull
)
def network_test():
"Run network test (expected to be run as subprocess)"
......@@ -50,3 +53,5 @@ def wait_for_network(max_stall):
process.join(max_stall)
if process.is_alive():
process.terminate()
return False
return True
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment