by _iyrr · 10y ago · 0 comments
screen -dmS myservice /blah/start.sh
Fit that line somewhere in a properly constructed init.d file and you're good to go. And if you need to execute a safe stop from that program through some interactivity: screen -S myservice -X stuff "stop\n"
And voila. It sends a line of text over followed by an enter key. Elegant, useful. You can reattach session to see what's happening at any time. Love me some screen.When the process exits in that screen session, screen session is closed so that you can rely on screen -list.
"Daemon mode" is the mode for tmux, and the whole stack is designed to be extremely scriptable. "tmux send-keys" does what you're referring to, here, but essentially anything you can do interactively, you can do via the command-line.
Not to say you shouldn't just keep doing what works for you! But figured I'd at least make mention of tmux as an alternative... I'm a fan. :)
Since I use screen fairly often, it had never occurred to me (until fairly recently) that you can rely on it to start with a machine reboot -- and yet have the very familiar interface available to you when you want to intervene. Something to be said about muscle memory.
And yet, this is a default shortcut for command mode in tmux. "But you can configure it!" — one might say. No, I won't be doing it on every system I manage, I have better things to do.
It all started with less(1)... Configuring it is a pain in the butt. One day, I couldn't remember how to do it on a new machine, so I just performed the following command...
scp ~/.*less* ~/*less* newmachine:
It was wonderful! Now I do the same thing for my emacs config, and my .xsession, and my hosts files, etc.