[{"data":1,"prerenderedAt":1020,"buildId":1021},["ShallowReactive",2],{"docs:\u002Fguide\u002Fhosts":3},{"page":4,"section":16,"document":17,"credits":10,"prev":1012,"next":1016},{"id":5,"path":6,"file":7,"title":8,"sourceTitle":8,"description":9,"tagline":9,"eyebrow":10,"credits":10,"keywords":11,"icon":12,"layout":13,"sidebar":14,"toc":14,"kind":10,"group":10,"navigation":14,"order":15},"hosts","\u002Fguide\u002Fhosts","guide\u002Fhosts.md","Hosts","Check fleet entries, expand Tailscale tags into machines, run one command on each over ssh, and record the fleet.",null,[],"i-lucide-server","article",true,4,"guide",{"nodes":18,"toc":1001},[19,28,198,206,209,285,295,364,379,385,395,419,422,482,485,499,514,528,534,562,575,581,682,787,793,800,807,818,872,878,904,914,920,934,966,974,980],[20,21,22,23,27],"p",{},"The ",[24,25,26],"code",{},"fleethosts"," entry takes a list of fleet entries and runs a command on the machines they name.",[29,30,33],"pre",{"language":31,"class":32,"wrap":14},"ts","shiki shiki-themes github-light-default github-dark-default dark:github-dark-default",[24,34,36,59,60,59,62,59,87,59,120,59,122,59,139,59,144,59,173,59,194],{"class":35},"language-ts",[37,38,41,45,49,52,56],"span",{"class":39,"style":40},"line","display: inline",[37,42,44],{"style":43},"color:#CF222E;--shiki-dark:#FF7B72","import",[37,46,48],{"style":47},"color:#1F2328;--shiki-dark:#E6EDF3"," { recordedHosts, resolveHosts, runOnHosts, standardPlaces } ",[37,50,51],{"style":43},"from",[37,53,55],{"style":54},"color:#0A3069;--shiki-dark:#A5D6FF"," \"fleethosts\"",[37,57,58],{"style":47},";","\n",[37,61],{"class":39,"style":40},[37,63,64,67,71,74,78,81,84],{"class":39,"style":40},[37,65,66],{"style":43},"const",[37,68,70],{"style":69},"color:#0550AE;--shiki-dark:#79C0FF"," places",[37,72,73],{"style":43}," =",[37,75,77],{"style":76},"color:#8250DF;--shiki-dark:#D2A8FF"," standardPlaces",[37,79,80],{"style":47},"(",[37,82,83],{"style":54},"\"mytool\"",[37,85,86],{"style":47},");",[37,88,89,91,94,96,99,102,105,108,111,114,117],{"class":39,"style":40},[37,90,66],{"style":43},[37,92,93],{"style":69}," entries",[37,95,73],{"style":43},[37,97,98],{"style":76}," recordedHosts",[37,100,101],{"style":47},"(places) ",[37,103,104],{"style":43},"??",[37,106,107],{"style":47}," [",[37,109,110],{"style":54},"\"vps\"",[37,112,113],{"style":47},", ",[37,115,116],{"style":54},"\"tag:servers\"",[37,118,119],{"style":47},"];",[37,121],{"class":39,"style":40},[37,123,124,126,129,131,134,137],{"class":39,"style":40},[37,125,66],{"style":43},[37,127,128],{"style":69}," runs",[37,130,73],{"style":43},[37,132,133],{"style":43}," await",[37,135,136],{"style":76}," runOnHosts",[37,138,80],{"style":47},[37,140,141],{"class":39,"style":40},[37,142,143],{"style":47},"  places,",[37,145,146,149,152,156,159,162,164,167,170],{"class":39,"style":40},[37,147,148],{"style":43},"  async",[37,150,151],{"style":47}," (",[37,153,155],{"style":154},"color:#953800;--shiki-dark:#FFA657","remoteCommand",[37,157,158],{"style":47},") ",[37,160,161],{"style":43},"=>",[37,163,151],{"style":47},[37,165,166],{"style":43},"await",[37,168,169],{"style":76}," resolveHosts",[37,171,172],{"style":47},"(places, entries, { remoteCommand })).targets,",[37,174,175,178,181,183,186,188,191],{"class":39,"style":40},[37,176,177],{"style":47},"  [",[37,179,180],{"style":54},"\"df\"",[37,182,113],{"style":47},[37,184,185],{"style":54},"\"-h\"",[37,187,113],{"style":47},[37,189,190],{"style":54},"\"\u002F\"",[37,192,193],{"style":47},"],",[37,195,196],{"class":39,"style":40},[37,197,86],{"style":47},[199,200,205],"h2",{"id":201,"anchor":202},"fleet-entries",{"label":203,"icon":204},"Section titled \"Fleet entries\"","#","Fleet entries",[20,207,208],{},"A fleet entry is one of:",[210,211,212,225],"table",{},[213,214,215],"thead",{},[216,217,218,222],"tr",{},[219,220,221],"th",{},"Entry",[219,223,224],{},"Example",[226,227,228,239,249,262,275],"tbody",{},[216,229,230,234],{},[231,232,233],"td",{},"A host name or ssh_config alias",[231,235,236],{},[24,237,238],{},"vps",[216,240,241,244],{},[231,242,243],{},"A user and host",[231,245,246],{},[24,247,248],{},"me@build.example.com",[216,250,251,254],{},[231,252,253],{},"An IP address",[231,255,256,113,259],{},[24,257,258],{},"100.64.0.7",[24,260,261],{},"fd7a:115c::7",[216,263,264,267],{},[231,265,266],{},"An ssh URL, with a port",[231,268,269,113,272],{},[24,270,271],{},"ssh:\u002F\u002Fdeploy@build.example.com:2222",[24,273,274],{},"ssh:\u002F\u002F[fd7a::7]:22",[216,276,277,280],{},[231,278,279],{},"A Tailscale tag",[231,281,282],{},[24,283,284],{},"tag:servers",[20,286,287,290,291,294],{},[24,288,289],{},"fleetEntryProblem(entry)"," says why an entry can't be used, or returns ",[24,292,293],{},"undefined",":",[29,296,297],{"language":31,"class":32,"wrap":14},[24,298,299,59,312,59,314,59,326,59,332,59,343,59,348,59,359],{"class":35},[37,300,301,303,306,308,310],{"class":39,"style":40},[37,302,44],{"style":43},[37,304,305],{"style":47}," { fleetEntryProblem } ",[37,307,51],{"style":43},[37,309,55],{"style":54},[37,311,58],{"style":47},[37,313],{"class":39,"style":40},[37,315,316,319,321,324],{"class":39,"style":40},[37,317,318],{"style":76},"fleetEntryProblem",[37,320,80],{"style":47},[37,322,323],{"style":54},"\"vps:2222\"",[37,325,86],{"style":47},[37,327,328],{"class":39,"style":40},[37,329,331],{"style":330},"color:#6E7781;--shiki-dark:#8B949E","\u002F\u002F '\"vps:2222\" has a port; write it as ssh:\u002F\u002Fvps:2222'",[37,333,334,336,338,341],{"class":39,"style":40},[37,335,318],{"style":76},[37,337,80],{"style":47},[37,339,340],{"style":54},"\"-oProxyCommand=x\"",[37,342,86],{"style":47},[37,344,345],{"class":39,"style":40},[37,346,347],{"style":330},"\u002F\u002F '\"-oProxyCommand=x\" starts with \"-\", so ssh would read it as an option'",[37,349,350,352,354,357],{"class":39,"style":40},[37,351,318],{"style":76},[37,353,80],{"style":47},[37,355,356],{"style":54},"\"tag:1st\"",[37,358,86],{"style":47},[37,360,361],{"class":39,"style":40},[37,362,363],{"style":330},"\u002F\u002F '\"tag:1st\" is not a Tailscale tag: write tag: and then a letter followed by letters, digits or dashes, such as \"tag:servers\"'",[20,365,366,367,370,371,374,375,378],{},"Nothing that passes the check is read by ssh as an option or split by a shell. ",[24,368,369],{},"hostProblem"," and ",[24,372,373],{},"tagProblem"," check one kind each, and ",[24,376,377],{},"isTag"," tells them apart.",[199,380,384],{"id":381,"anchor":382},"resolve-entries-to-targets",{"label":383,"icon":204},"Section titled \"Resolve entries to targets\"","Resolve entries to targets",[20,386,387,390,391,394],{},[24,388,389],{},"resolveHosts(places, entries, options)"," turns entries into ",[24,392,393],{},"FleetTarget","s, the machines to run on.",[396,397,398,402,409],"ul",{},[399,400,401],"li",{},"A named host stays as written.",[399,403,404,405,408],{},"A ",[24,406,407],{},"tag:"," entry becomes every machine on the tailnet with that tag, except this one. Each gets its MagicDNS name, or its Tailscale IP when MagicDNS is off or the name doesn't work. Tags match without regard to case.",[399,410,411,412,370,415,418],{},"A host you named wins over a tag's match for the same machine, and the first tag wins over later ones. Distinct explicit SSH destinations, such as ",[24,413,414],{},"deploy@box",[24,416,417],{},"admin@box"," or different ports, can still produce separate runs on the same machine.",[20,420,421],{},"It returns:",[210,423,424,434],{},[213,425,426],{},[216,427,428,431],{},[219,429,430],{},"Field",[219,432,433],{},"What it holds",[226,435,436,448,458,472],{},[216,437,438,443],{},[231,439,440],{},[24,441,442],{},"targets",[231,444,22,445,447],{},[24,446,393],{},"s to run on",[216,449,450,455],{},[231,451,452],{},[24,453,454],{},"warnings",[231,456,457],{},"A tag that matches no machine, or a machine with no name or address ssh takes",[216,459,460,465],{},[231,461,462],{},[24,463,464],{},"enrollment",[231,466,467,468,471],{},"Each entry's targets, or ",[24,469,470],{},"null"," when a tag skipped one of its machines",[216,473,474,479],{},[231,475,476],{},[24,477,478],{},"self",[231,480,481],{},"This machine as Tailscale lists it, when Tailscale was asked",[20,483,484],{},"A target can't always be run on. Then it says why:",[396,486,487,493],{},[399,488,489,492],{},[24,490,491],{},"offline: true",": Tailscale says the machine is offline, so ssh isn't tried.",[399,494,495,498],{},[24,496,497],{},"error",": the tag couldn't be expanded (Tailscale isn't installed, logged in or running), or no route was verified.",[20,500,501,502,505,506,509,510,513],{},"Before it trusts a tag's machine, fleethosts asks ",[24,503,504],{},"ssh -G"," where your ssh config sends each name, and checks that the name resolves to that machine's Tailscale addresses. A ",[24,507,508],{},"Host"," block that sends a name through a proxy, or to another machine, fails that check, and the target gets the error ",[24,511,512],{},"could not verify an SSH route to the Tailscale peer",".",[20,515,516,517,520,521,523,524,527],{},"The check runs with the exact command ssh will run, because ssh's config can send a host elsewhere for one command. That is why ",[24,518,519],{},"resolveHosts"," needs ",[24,522,155],{},", and why ",[24,525,526],{},"runOnHosts"," takes a resolver function: it builds the command, then hands it to your resolver.",[199,529,533],{"id":530,"anchor":531},"run-a-command",{"label":532,"icon":204},"Section titled \"Run a command\"","Run a command",[29,535,536],{"language":31,"class":32,"wrap":14},[24,537,538],{"class":35},[37,539,540,542,545,548,551,554,556,559],{"class":39,"style":40},[37,541,526],{"style":76},[37,543,544],{"style":47},"(places, targets, argv, timeoutMs ",[37,546,547],{"style":43},"=",[37,549,550],{"style":69}," 30_000",[37,552,553],{"style":47},", { here ",[37,555,547],{"style":43},[37,557,558],{"style":69}," true",[37,560,561],{"style":47}," })",[20,563,564,566,567,570,571,574],{},[24,565,442],{}," is a ",[24,568,569],{},"FleetTarget[]",", or a function that gets the remote command and returns them. ",[24,572,573],{},"argv"," is the command and its arguments; each one is quoted for the remote shell. Every machine runs it at the same time.",[20,576,577,578,294],{},"Each machine gives one ",[24,579,580],{},"RunResult",[29,582,583],{"language":31,"class":32,"wrap":14},[24,584,585,59,596,59,608,59,620,59,633,59,644,59,655,59,666,59,677],{"class":35},[37,586,587,590,593],{"class":39,"style":40},[37,588,589],{"style":43},"interface",[37,591,592],{"style":154}," RunResult",[37,594,595],{"style":47}," {",[37,597,598,601,603,606],{"class":39,"style":40},[37,599,600],{"style":154},"  host",[37,602,294],{"style":43},[37,604,605],{"style":69}," string",[37,607,58],{"style":47},[37,609,610,613,615,618],{"class":39,"style":40},[37,611,612],{"style":154},"  reachable",[37,614,294],{"style":43},[37,616,617],{"style":69}," boolean",[37,619,58],{"style":47},[37,621,622,625,628,631],{"class":39,"style":40},[37,623,624],{"style":154},"  exitCode",[37,626,627],{"style":43},"?:",[37,629,630],{"style":69}," number",[37,632,58],{"style":47},[37,634,635,638,640,642],{"class":39,"style":40},[37,636,637],{"style":154},"  stdout",[37,639,294],{"style":43},[37,641,605],{"style":69},[37,643,58],{"style":47},[37,645,646,649,651,653],{"class":39,"style":40},[37,647,648],{"style":154},"  stderr",[37,650,294],{"style":43},[37,652,605],{"style":69},[37,654,58],{"style":47},[37,656,657,660,662,664],{"class":39,"style":40},[37,658,659],{"style":154},"  error",[37,661,627],{"style":43},[37,663,605],{"style":69},[37,665,58],{"style":47},[37,667,668,671,673,675],{"class":39,"style":40},[37,669,670],{"style":154},"  truncated",[37,672,627],{"style":43},[37,674,558],{"style":69},[37,676,58],{"style":47},[37,678,679],{"class":39,"style":40},[37,680,681],{"style":47},"}",[210,683,684,705],{},[213,685,686],{},[216,687,688,691,696,701],{},[219,689,690],{},"Result",[219,692,693],{},[24,694,695],{},"reachable",[219,697,698],{},[24,699,700],{},"exitCode",[219,702,703],{},[24,704,497],{},[226,706,707,723,739,755,773],{},[216,708,709,712,717,720],{},[231,710,711],{},"The command exited",[231,713,714],{},[24,715,716],{},"true",[231,718,719],{},"its code",[231,721,722],{},"none",[216,724,725,728,732,734],{},[231,726,727],{},"The command was still running at the deadline",[231,729,730],{},[24,731,716],{},[231,733,722],{},[231,735,736],{},[24,737,738],{},"timed out after 30 s, so the command was told to stop",[216,740,741,744,748,750],{},[231,742,743],{},"The connection dropped",[231,745,746],{},[24,747,716],{},[231,749,722],{},[231,751,752],{},[24,753,754],{},"the connection dropped before the command finished",[216,756,757,760,765,767],{},[231,758,759],{},"ssh got no answer",[231,761,762],{},[24,763,764],{},"false",[231,766,722],{},[231,768,769,772],{},[24,770,771],{},"no answer within 30 s",", or ssh's last lines",[216,774,775,778,782,784],{},[231,776,777],{},"Offline in Tailscale, or a bad target",[231,779,780],{},[24,781,764],{},[231,783,722],{},[231,785,786],{},"why",[20,788,789,790,792],{},"Read ",[24,791,700],{}," only when it is there. A machine that didn't answer has no exit code, so it never reads as a failed command.",[20,794,795,796,799],{},"ssh runs with ",[24,797,798],{},"BatchMode=yes",", so a host that asks for a password is unreachable. The script goes to the host's login shell as base64, so fish and tcsh run it like sh.",[801,802,806],"h3",{"id":803,"anchor":804},"this-machine",{"label":805,"icon":204},"Section titled \"This machine\"","This machine",[20,808,809,810,813,814,817],{},"With ",[24,811,812],{},"here: true",", the default, the command also runs on this machine, from the home folder, and its result comes first under ",[24,815,816],{},"hostname()",". A target that turns out to be this machine is then left out, whatever it is called: an ssh alias, a MagicDNS name and an IP all can be. Each host checks for a folder this run made, which only this user on this machine owns.",[210,819,820,835],{},[213,821,822],{},[216,823,824,829,832],{},[219,825,826],{},[24,827,828],{},"here",[219,830,831],{},"Runs here",[219,833,834],{},"Targets that are this machine",[226,836,837,849,861],{},[216,838,839,843,846],{},[231,840,841],{},[24,842,716],{},[231,844,845],{},"yes",[231,847,848],{},"left out",[216,850,851,856,859],{},[231,852,853],{},[24,854,855],{},"\"leave out\"",[231,857,858],{},"no",[231,860,848],{},[216,862,863,867,869],{},[231,864,865],{},[24,866,764],{},[231,868,858],{},[231,870,871],{},"run like any host",[801,873,877],{"id":874,"anchor":875},"stopping",{"label":876,"icon":204},"Section titled \"Stopping\"","Stopping",[20,879,880,881,884,885,888,889,892,893,896,897,900,901,903],{},"A command still running at ",[24,882,883],{},"timeoutMs"," is stopped, with what it started. Over ssh, the command runs in its own process group (from ",[24,886,887],{},"setsid",", or ",[24,890,891],{},"perl"," on macOS) and watches its stdin. When the connection drops, the group gets ",[24,894,895],{},"SIGTERM",", then ",[24,898,899],{},"SIGKILL"," two seconds later. A command that traps ",[24,902,895],{}," still stops.",[20,905,906,907,910,911,913],{},"Output is kept up to 64 MiB per stream. Past that, ",[24,908,909],{},"truncated"," is ",[24,912,716],{}," and only the end is kept.",[199,915,919],{"id":916,"anchor":917},"record-the-fleet",{"label":918,"icon":204},"Section titled \"Record the fleet\"","Record the fleet",[20,921,922,925,926,929,930,933],{},[24,923,924],{},"recordHosts(places, entries)"," writes the entries to ",[24,927,928],{},"\u003Cstate>\u002Fhosts.json",", replacing it whole. ",[24,931,932],{},"recordedHosts(places)"," reads them back.",[29,935,936],{"language":31,"class":32,"wrap":14},[24,937,938,59,955],{"class":35},[37,939,940,943,946,948,950,952],{"class":39,"style":40},[37,941,942],{"style":76},"recordHosts",[37,944,945],{"style":47},"(places, [",[37,947,110],{"style":54},[37,949,113],{"style":47},[37,951,116],{"style":54},[37,953,954],{"style":47},"]);",[37,956,957,960,963],{"class":39,"style":40},[37,958,959],{"style":76},"recordedHosts",[37,961,962],{"style":47},"(places); ",[37,964,965],{"style":330},"\u002F\u002F [\"vps\", \"tag:servers\"]",[20,967,968,970,971,973],{},[24,969,959],{}," returns ",[24,972,293],{}," when there is no file, the file is malformed, or another config folder wrote it. An empty list is a fleet with no hosts, which is not the same as no record. The record lets a second program run on the fleet the first one last saw.",[199,975,979],{"id":976,"anchor":977},"tailscale",{"label":978,"icon":204},"Section titled \"Tailscale\"","Tailscale",[20,981,982,985,986,989,990,992,993,996,997,1000],{},[24,983,984],{},"tailnet(places)"," lists the other machines on the tailnet, from ",[24,987,988],{},"tailscale status --json",". When ",[24,991,976],{}," isn't on ",[24,994,995],{},"PATH",", fleethosts looks where the installers put it: Homebrew and the Mac app on macOS, Program Files on Windows. ",[24,998,999],{},"\u003CPROGRAM>_TAILSCALE"," names another CLI and turns that search off.",[1002,1004,1005,1010,1011],{"id":201,"depth":1003,"text":205},2,{"id":381,"depth":1003,"text":384},{"id":530,"depth":1003,"text":533,"children":1006},[1007,1009],{"id":803,"depth":1008,"text":806},3,{"id":874,"depth":1008,"text":877},{"id":916,"depth":1003,"text":919},{"id":976,"depth":1003,"text":979},{"path":1013,"title":1014,"description":1015},"\u002Fguide\u002Fplaces","Places","A Places object names your program and its folders. fleethosts writes and reads under that name only.",{"path":1017,"title":1018,"description":1019},"\u002Fguide\u002Fexec","Exec","Run a command to the end without throwing on its exit code, with support for timeouts and cancellation.",1796388536448,"7b1f70a7-2953-4287-ada9-b3dc097b349d"]