diff options
author | Laurent Alfonsi <laurent.alfonsi@linaro.org> | 2022-03-31 16:54:52 +0000 |
---|---|---|
committer | Laurent Alfonsi <laurent.alfonsi@linaro.org> | 2022-04-15 11:03:16 +0200 |
commit | fc3367e7ff6a19e2af2bc1c671712bf96c1e307b (patch) | |
tree | 023a4d130a4fd0510a8126790b5ad6ee9302bf5c /prepare-board.sh | |
parent | 035f2a80bdadb7104520e920f575727cbc768072 (diff) |
prepare-board : Adapt for docker host containers
Change-Id: I649530dbdb72de57faa3db83aad250464c085b45
Diffstat (limited to 'prepare-board.sh')
-rwxr-xr-x | prepare-board.sh | 82 |
1 files changed, 52 insertions, 30 deletions
diff --git a/prepare-board.sh b/prepare-board.sh index 414c7bf..5d9236b 100755 --- a/prepare-board.sh +++ b/prepare-board.sh @@ -35,7 +35,6 @@ TOP=$(dirname "$(readlink -f "$0")") CONFS=$TOP/prepare-board RESTORE_LOC=/run/prepare-board # FIXME: put this in a board-specific conf file -SERVICE_LIST=("ntp") ############################################################ # usage/help @@ -89,6 +88,7 @@ hw_tag2board_type() sq*) echo "sq" ;; tk1*) echo "tk1" ;; tx1*) echo "tx1" ;; + fx*) echo "fx" ;; *) error "Unknown hw_tag $hw_tag" ;; esac } @@ -99,6 +99,7 @@ hw_tag2board_type() # configure access to linux tools: cpupower and perf configure_linux_tools() { + echo "# configure_linux_tools" local op=$1 case "$op" in @@ -132,6 +133,7 @@ set_var() local restore_file=$1 local file=$2 local value=$3 + local param local orig_value orig_value=$(cat "$file") @@ -139,7 +141,12 @@ set_var() if [ "$value" != "$orig_value" ]; then verbose "Setting $file to $value (was $orig_value)" echo "$file=$orig_value" >> "$restore_file" - echo "$value" > "$file" + if [[ "$file" =~ "/proc/sys/" ]]; then + param=$(echo "$file" | sed -e 's|/proc/sys/||' -e 's|/|.|g' ) + sysctl -w "$param"="$value" + else + echo "$value" > "$file" + fi if [ x"$(cat "$file")" != x"$value" ]; then error "cannot set $file to $value" fi @@ -162,7 +169,12 @@ restore_vars() file=$(echo "$entry" | cut -d= -f 1 ) value=$(echo "$entry" | cut -d= -f 2) verbose "Setting $file to $value" - (echo "$value" > "$file") || true + if [[ "$file" =~ "/proc/sys/" ]]; then + param=$(echo "$file" | sed -e 's|/proc/sys/||' -e 's|/|.|g' ) + (sysctl -w "$param"="$value") || true + else + (echo "$value" > "$file") || true + fi if [ x"$(cat "$file")" != x"$value" ]; then warning "cannot reset $file to $value" fi @@ -196,14 +208,15 @@ do_sysctl() configure_sysctls() { + echo "# configure_sysctls" local op=$1 - if [ "$op" = "start_board" ]; then + if [[ "$op" =~ start_* ]]; then local sysctl_file=$CONFS/sysctl-${BOARD_TYPE}.conf if [ ! -f "$sysctl_file" ]; then sysctl_file=$CONFS/sysctl.conf fi do_sysctl "$sysctl_file" "${RESTORE_LOC}/sysctls.conf" - elif [ "$op" = "stop_board" ]; then + elif [[ "$op" =~ stop_* ]]; then restore_vars "${RESTORE_LOC}/sysctls.conf" fi } @@ -212,16 +225,29 @@ configure_sysctls() ######################################## # configure_services and helpers # stops all services in ${SERVICE_LIST[*]} for benchmarking +SERVICE_LIST=( + # "ntp" : no NTP service on FX700 + "alsa-utils" "apport" "atd" "cron" + # "dbus" : keep + "irqbalance" "kmod" "multipath-tools" + # "networking" : keep for the moment + "procps" "rsyslog" + # "ssh" : keep + "udev" + # "ufw" : keep for the moment + "unattended-upgrades" + ) # do_service starts or stops a named service # assumes that the system is using systemd + do_service() { local op=$1 local restart_file=$2 local service=$3 - if [ "$op" = "start_board" ]; then + if [[ "$op" =~ start_* ]]; then # Stop services that are not already stopped. # Note that using "systemctl is-active" doesn't work here because we # can get here during "activating" stage just after board reboot. @@ -233,7 +259,7 @@ do_service() else verbose "Skipping system service $service, which is already stopped" fi - elif [ "$op" = "stop_board" ]; then + elif [[ "$op" =~ stop_* ]]; then if [ -f "$restart_file" ] && grep -q --line-regexp -e "$service" "$restart_file"; then verbose "Restarting system service $service" @@ -246,6 +272,7 @@ do_service() configure_services() { + echo "# configure_services" local op=$1 local i local restart_file=${RESTORE_LOC}/services @@ -262,6 +289,7 @@ configure_services() configure_perf_hack() { + echo "# configure_perfhack" local op=$1 local conf_file="$CONFS/perf_hack-$BOARD_TYPE" local pidfile="${RESTORE_LOC}/perf_hack.pid" @@ -368,14 +396,15 @@ do_tegra_start() configure_cpufreq() { + echo "# configure_cpufreq" local file=${RESTORE_LOC}/cpufreq - if [ "$op" = "start_board" ]; then + if [[ "$op" =~ start_* ]]; then # we have to disable cpuquiet before setting frequencies, but # do the restoration in the opposite order. So it's easiest # to share the same restore file. do_tegra_start "$file" do_cpufreq_start "$file" - elif [ "$op" = "stop_board" ]; then + elif [[ "$op" =~ stop_* ]]; then restore_vars "$file" fi } @@ -390,6 +419,7 @@ configure_cpufreq() # saves/restores board type configure_board_type_file() { + echo "# configure_board_type_file" local op=$1 local file="$RESTORE_LOC/board_type" @@ -412,22 +442,11 @@ configure_board_type_file() # update time on the board configure_ntp() { + echo "# configure_ntp" local op=$1 - if [ "$op" = "start_board" ]; then - local retry - # shellcheck disable=SC2034 # Intentionally unused - for retry in 5 4 3 2 1; do - if ntpd -gq; then - break - fi - - # Occasionally systemctl fails to properly kill ntp and - # we get stuck ntpd process that doesn't respond to SIGTERM. - # Kill it with SIGKILL. - pkill -9 ntpd || true - sleep 60 - done + if [[ "$op" =~ start_* ]]; then + timedatectl set-ntp false fi } @@ -447,12 +466,13 @@ test_docker() # Make sure docker is functional on the board configure_docker() { + echo "# configure_docker" local op=$1 local restore_file=${RESTORE_LOC}/docker local cnt local host_cnt - if [ "$op" = "start_board" ]; then + if [[ "$op" =~ start_* ]]; then # We have up-to-date docker-wrapper under /home/tcwg-benchmark/bin # thanks to tcwg-infra-update-home job, and now copy it to # /usr/local/bin/ so that it overrides /usr/bin/docker. @@ -488,23 +508,23 @@ configure_docker() fi fi - host_cnt=$(docker ps --filter name=host -q) + verbose "Stopping all docker containers except host container" + host_cnt=$(docker ps --filter name='host$' -q) for cnt in $(docker ps -q); do [ "$cnt" = "$host_cnt" ] && continue - docker stop $cnt - echo $cnt >> "$restore_file" + docker stop "$cnt" + echo "$cnt" >> "$restore_file" done - elif [ "$op" = "stop_board" ]; then + elif [[ "$op" =~ stop_* ]]; then for cnt in $(docker ps -q -f status=exited); do if grep -q "^$cnt\$" "$restore_file"; then - docker start $cnt + docker start "$cnt" fi done rm -f "$restore_file" fi } - ############################################################ # perform the configuration configure_common() @@ -529,6 +549,8 @@ configure_common() rmdir "${RESTORE_LOC}" ;; esac + + echo "# All configuration done" } DOCKER_IMAGE="" |