edith_codecs
Clone
https://git.tahinli.com/Tahinli/edith_codecs.git
0 watching0 forksRust370.3 MiB6f8f2a3Tahinli6 days ago3950 commits
| 1 | #!/usr/bin/env bash |
| 2 | # remote-run.sh: run heavy cargo commands on the lane servers instead of this machine. |
| 3 | # |
| 4 | # Usage: |
| 5 | # scripts/remote-run.sh <lane> [--host auto|a|b|c] [--with-edith] [--clean] -- <command...> |
| 6 | # scripts/remote-run.sh <lane> --clean |
| 7 | # |
| 8 | # --host auto|a|b|c auto (default) probes a, b and c each round (one ssh each: busy slots and |
| 9 | # MemAvailable) and tries the least loaded first: fewest busy slots, then most |
| 10 | # MemAvailable. Unreachable hosts are skipped. It retries for up to 10 minutes |
| 11 | # (20 s between rounds), then builds locally. |
| 12 | # --with-edith also sync the edith tree ($EDITH_TREE, default |
| 13 | # $HOME/Documents/Code/Rust/edith) to ~/lanes/<lane>/edith and run |
| 14 | # the command inside it. Its path deps ../../../edith_codecs resolve to |
| 15 | # ~/lanes/<lane>/edith_codecs. |
| 16 | # --clean remove ~/lanes/<lane>, ~/.cache/tgt-<lane> and ~/tmp/<lane> on every host, |
| 17 | # and ~/.cache/tgt-<lane>, ~/.cache/tmp-<lane> locally. |
| 18 | # |
| 19 | # The source tree is the git toplevel of the current directory (worktrees work). It is rsynced |
| 20 | # to ~/lanes/<lane>/edith_codecs on the host, without target/, fixtures/ and .git. The host gets |
| 21 | # fixtures -> ~/fixtures as a symlink. The command runs under the host's slot lock (~/.remote-slot), |
| 22 | # so one heavy job at a time per server. |
| 23 | # |
| 24 | # Three job slots per host (~/.remote-slot.0, .1 and .2), each with CARGO_BUILD_JOBS=2. |
| 25 | # Remote env: CARGO_TARGET_DIR=~/.cache/tgt-<lane>, TMPDIR=~/tmp/<lane>, CARGO_BUILD_JOBS=2, |
| 26 | # EC_MEMGUARD_MAX=3500M (the memory cap read by scripts/memguard-runner.sh). Every EC_* variable |
| 27 | # from the local environment is forwarded and wins over the defaults. |
| 28 | # |
| 29 | # Exit codes: the remote command's code. 75 means the slot stayed busy (with --host a or b, after |
| 30 | # 10 minutes). A command that itself exits 75 looks the same and is retried on the next host. |
| 31 | # 255 means the chosen host was unreachable. stderr shows "remote-run: host=a|b|c|local" when a run starts. |
| 32 | |
| 33 | |
| 34 | |
| 35 | [ && |
| 36 | HOST_A= |
| 37 | HOST_B= |
| 38 | HOST_C= |
| 39 | EDITH_TREE= |
| 40 | EDITH_ASSETS= |
| 41 | SSH=(ssh -o BatchMode=yes -o ConnectTimeout=20) |
| 42 | RSYNC_RSH="ssh -o BatchMode=yes -o ConnectTimeout=20" |
| 43 | BUSY=75 |
| 44 | UNREACH=254 |
| 45 | RETRY_SECS=20 |
| 46 | RETRY_TOTAL=600 |
| 47 | |
| 48 | |
| 49 | |
| 50 | [ || { ; ; } |
| 51 | case in |
| 52 | -h|--help) ; ;; |
| 53 | esac |
| 54 | lane= |
| 55 | |
| 56 | |
| 57 | host=auto |
| 58 | with_edith=0 |
| 59 | clean=0 |
| 60 | cmd=() |
| 61 | while [; do |
| 62 | case in |
| 63 | --host) [ || ; host=; ;; |
| 64 | --host=*) host=; ;; |
| 65 | --with-edith) with_edith=1; ;; |
| 66 | --clean) clean=1; ;; |
| 67 | --) ; cmd=(""); break ;; |
| 68 | *) ;; |
| 69 | esac |
| 70 | done |
| 71 | |
| 72 | || |
| 73 | case in |
| 74 | auto|a|b|c) ;; |
| 75 | *) ;; |
| 76 | esac |
| 77 | |
| 78 | |
| 79 | |
| 80 | # rsh <ssh-target> <script>: run a bash script on the host. The script goes through stdin, so no |
| 81 | # quoting reaches fish, the remote login shell. |
| 82 | |
| 83 | |
| 84 | # Literal "$HOME/lanes/<lane>/<rel>" text, meant to be expanded by the remote bash. |
| 85 | |
| 86 | |
| 87 | |
| 88 | |
| 89 | |
| 90 | |
| 91 | |
| 92 | |
| 93 | |
| 94 | |
| 95 | |
| 96 | # sync_tree <addr> <local-dir> <remote-rel> [rsync filters...] |
| 97 | |
| 98 | |
| 99 | |
| 100 | |
| 101 | |
| 102 | |
| 103 | |
| 104 | |
| 105 | |
| 106 | |
| 107 | |
| 108 | |
| 109 | |
| 110 | |
| 111 | |
| 112 | |
| 113 | |
| 114 | |
| 115 | |
| 116 | # run_payload <host-letter>: the remote script that runs under the slot lock. |
| 117 | |
| 118 | |
| 119 | |
| 120 | |
| 121 | |
| 122 | |
| 123 | |
| 124 | |
| 125 | |
| 126 | |
| 127 | |
| 128 | |
| 129 | |
| 130 | |
| 131 | |
| 132 | |
| 133 | |
| 134 | |
| 135 | |
| 136 | |
| 137 | |
| 138 | |
| 139 | |
| 140 | |
| 141 | |
| 142 | |
| 143 | |
| 144 | |
| 145 | |
| 146 | |
| 147 | |
| 148 | |
| 149 | |
| 150 | |
| 151 | |
| 152 | |
| 153 | |
| 154 | if ; then |
| 155 | for; do |
| 156 | |
| 157 | |
| 158 | || |
| 159 | done |
| 160 | |
| 161 | |
| 162 | |
| 163 | fi |
| 164 | |
| 165 | || |
| 166 | ROOT= || |
| 167 | if && [; then |
| 168 | |
| 169 | fi |
| 170 | |
| 171 | # try_host <letter>: sync, then run. Returns the remote exit code, $BUSY, or $UNREACH. |
| 172 | |
| 173 | |
| 174 | |
| 175 | |
| 176 | |
| 177 | |
| 178 | |
| 179 | |
| 180 | |
| 181 | |
| 182 | |
| 183 | |
| 184 | |
| 185 | |
| 186 | |
| 187 | |
| 188 | |
| 189 | |
| 190 | |
| 191 | |
| 192 | |
| 193 | |
| 194 | |
| 195 | |
| 196 | |
| 197 | |
| 198 | |
| 199 | |
| 200 | |
| 201 | |
| 202 | |
| 203 | |
| 204 | |
| 205 | |
| 206 | |
| 207 | # probe_host <ssh-target>: print "<busy slots> <MemAvailable kB>" for one host. Each slot lock is |
| 208 | # taken with flock -n and dropped at once, so a running job is never disturbed. |
| 209 | |
| 210 | |
| 211 | |
| 212 | |
| 213 | |
| 214 | |
| 215 | |
| 216 | |
| 217 | |
| 218 | |
| 219 | |
| 220 | |
| 221 | |
| 222 | |
| 223 | |
| 224 | # auto_order: print the host letters, least loaded first. Unreachable hosts are left out. If none |
| 225 | # answers, print the old order c a b so try_host reports each host as unreachable as before. |
| 226 | |
| 227 | |
| 228 | |
| 229 | |
| 230 | |
| 231 | |
| 232 | |
| 233 | |
| 234 | |
| 235 | |
| 236 | |
| 237 | |
| 238 | |
| 239 | |
| 240 | |
| 241 | |
| 242 | |
| 243 | |
| 244 | candidates=("") |
| 245 | deadline= |
| 246 | busy=0 |
| 247 | while ; do |
| 248 | busy=0 |
| 249 | if [; then |
| 250 | |
| 251 | |
| 252 | fi |
| 253 | for; do |
| 254 | |
| 255 | rc= |
| 256 | case in |
| 257 | "") ;; |
| 258 | "") busy=1; ;; |
| 259 | *) ;; |
| 260 | esac |
| 261 | done |
| 262 | || break |
| 263 | || break |
| 264 | |
| 265 | done |
| 266 | |
| 267 | if [; then |
| 268 | if ; then |
| 269 | |
| 270 | |
| 271 | fi |
| 272 | |
| 273 | |
| 274 | fi |
| 275 | |
| 276 |