Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

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.


Add it within a infinitive loop + `sleep 10` and now it automatically restarts if it crashes too! :)


haha, 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/


I'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).


Also 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?


Oh 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.


Main 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/


+1 Been running my servers this way, for years.


I'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/


Nice! 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)


Hmm, "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. :)


True.

[to be limpid, I just meant that a reboot could kill that server-in-tmux strategy ;P ]


Not sure if you read the linked article, but there is a strategy to restart services on boot, using crontab's @reboot feature


lol a startup I worked at literally have a prod web server deployed through tmux like this.


why? (actually curious)


Maybe never heard of systemd


I 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.


But... why not nohup then? Should work just as well, and it's POSIX




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: