six demon bag
Wind, fire, all that kind of thing!
2020-04-30
Shell Patterns (4) - Limiting Execution Time
This is a short series describing some Bash constructs that I frequently use in my scripts.
Sometimes you want a script to give up on what it's trying to do after some period of time. The simplest way for limiting the time a given statement may take for execution is the timeout
command.
$ timout 2 ping 127.0.0.1 PING 127.0.0.1 (127.0.0.1) 56(84) bytes of data. 64 bytes from 127.0.0.1: icmp_seq=1 ttl=64 time=0.031 ms 64 bytes from 127.0.0.1: icmp_seq=2 ttl=64 time=0.012 ms $ echo $? 124
However, timeout
is only useful for limiting the execution time of a single (blocking) command. Consider for instance a situation where you deployed a VM or an LXD container, and need to wait for cloud-init to complete on that system. Or a situation where you sent an asynchronous request to a REST API. timeout
won't help you there. You need to poll the system or API repeatedly until the respective "operation completed" indicator appears.
Posted 22:35 [permalink]
2017-09-29
LXD upgrade fails on Ubuntu 16.04 without Systemd
Recently I tried to install LXD (Canonical's container manager) from backports on a Ubuntu 16.04 system (running without Systemd). The version shipping with the system (2.0) doesn't suffice, because I need the new storage API that was introduced with LXD 2.15. However, upgrading to the backports package failed post-install:
invoke-rc.d: initscript lxd, action "start" failed.
dpkg: error processing package lxd (--configure):
subprocess installed post-installation script returned error exit status 1
Processing triggers for ureadahead (0.100.0-19) ...
Errors were encountered while processing:
lxd
E: Sub-process /usr/bin/dpkg returned an error code (1)
Which was weird, since the upgrade had worked for me before.
Posted 13:57 [permalink]