A tiny TIL: how run multiple servers in a single Bash script, such that when the Bash script is terminated with Ctrl+C all of the servers are terminated as well
https://til.simonwillison.net/bash/multiple-servers
A tiny TIL: how run multiple servers in a single Bash script, such that when the Bash script is terminated with Ctrl+C all of the servers are terminated as well 12 comments
@simon great! next up, work out how to set up a pipeline of bash-parented PIDs, with the stout of each fed to the stdin of the next, and with each subprocess automatically restarted and replumbed on any abnormal edit. Bash is scary powerful. About the only thing I couldn't do in it is use arrays without leaking memory... @simon I'm loving your TIL format! This one made my (unpublished) list recently: http://redsymbol.net/articles/bash-exit-traps/ @simon you have no idea how many google searches I sent this week looking for something like this for windows. Asked ChatGPT to convert to powershell: https://chat.openai.com/share/952e5a0f-3769-4888-9910-93f0453bdf4d Excited to try it tomorrow. Thanks! @coderanger @simon I was gonna quip that Bash is a prime example where ChatGPT is a bad choice because 99% of Bash scripts out there are dangerous, hot garbage. |
@simon Good idea. ☺️
You might also want to add the Bash "strict mode" to the script to avoid potential problems: https://github.com/d2s/dot/blob/43071d52e7a2f450a4b71d41681c8e89081381c1/scripts/install-npm-packages.sh#L7