4 ms·
My favorite antipattern is, you can just leave a script that does an event loop running in the foreground, detatch tmux, and voila, you have a 'server'. Works
by digitalsushi 4y ago
My favorite antipattern is, you can just leave a script that does an event loop running in the foreground, detatch tmux, and voila, you have a 'server'. Works great in a pinch or when you just don't need to finish it.
- lolive 4y ago+1 Been running my servers this way, for years.
- simplerhosting 4y agoI've only recently started running my servers this way, and I've taken this to the next level with bubblewrap: https://tobykurien.com/simpler-linux-selfhosting/ https://tobykurien.com/simpler-linux-selfhosting/
- lolive 4y agoNice! From my experience, really what you want next is a working tmux-resurrect. Or, at least, all your services runners to be in .sh scripts (and not just in your so evanescant bash history)
- chrisweekly 4y agoHmm, "evanescant" seems wrong... sure enough, that's an obscure Latin word, vs intended "evanescent" (~synonymous w/ "ephemeral", ie soon-disappearing). PS comment is in spirit of knowlege-sharing not pedantry. :)
- lolive 4y agoTrue. [to be limpid, I just meant that a reboot could kill that server-in-tmux strategy ;P ]
- simplerhosting 4y agoNot sure if you read the linked article, but there is a strategy to restart services on boot, using crontab's @reboot feature
- capableweb 4y agoAdd it within a infinitive loop + `sleep 10` and now it automatically restarts if it crashes too! :)
- simplerhosting 4y agohaha, exactly what I've been doing (yes, sleep 10 as well!) I also added bubblewrap for security and wrapped it all up in a nice script to list/stop/start services, see https://tobykurien.com/simpler-linux-selfhosting/ https://tobykurien.com/simpler-linux-selfhosting/
- opan 4y agoI've started doing this with a few programs using sleep 1 and a while loop. First was ncmpcpp as it would declare itself too small and quit sometimes when my terminal with tmux resized, this way it'd either reopen when I adjusted pane sizes to fix it or when I restored the whole window to the other size. Next I did it for stig because I'd often press q to quit by accident or because it occasionally hits an issue where you can't view a torrent's detailed info anymore, fixed by a restart. Lastly for the aerc mail client which will frequently stop being able to reach mail servers and tell me I can't archive mail or something, so I just quit it and now it restarts (not sure if there's another way to make it reconnect).
- lajosbacs 4y agoAlso been doing this for years. And always wondered about possible disadvantages, or is there any reason why it is not used like this by everyone?
- iamjackg 4y agoOh I've definitely been doing it for years, but only for things I don't care very much about. For example, I used to have a password protected livestream of a camera that was literally an ffmpeg command running in a tmux session that would pipe MJPEG data to an nginx instance, and tmux was by far the easiest way to get it going. But the moment I want reliability, automatic restarts, or something easily reproducible, I switch to systemd or a Docker container.
- simplerhosting 4y agoMain disadvantages: restart services if they crash (so run them in a loop); security and isolation of services from each other and the OS; restart services on reboot. I've solved these problems: https://tobykurien.com/simpler-linux-selfhosting/ https://tobykurien.com/simpler-linux-selfhosting/
- chrislan815 4y agolol a startup I worked at literally have a prod web server deployed through tmux like this.
- afhammad 4y agowhy? (actually curious)
- killingtime74 4y agoMaybe never heard of systemd
- yummypaint 4y agoI do this all the time to run data acquisition systems for accelerator experiments. It also allows multiple users to connect at once. We have our whole analysis pipeline hosted in tmux sessions too.
- lou1306 4y agoBut... why not nohup then? Should work just as well, and it's POSIX