4 ms·
Using screen in daemon mode. screen -dmS myservice /blah/start.sh Fit that line somewhere in a properly constructed init.d file and you're good to go. An
by pp19dd 10y ago
Using screen in daemon mode.
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.
- zzalpha 10y agoNot to start a flamewar, but have you looked at tmux for this kind of thing? "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. :)
- atemerev 10y agoCtrl-B is the _worst_ shortcut ever devised (which is why it is used rarely... except on tmux). Just _thinking_ about it gives me the pain. My hand hurts. 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.
- zzalpha 10y agoEh, fair enough. I just reconfigure it and move on, but I grant you that doesn't necessarily work for everyone. shrug
- reedlaw 10y agoHave you ever tried using the alt/ctrl/shift keys on the other hand side? So for Ctrl-B you would use the right-hand pinky to hit ctrl and the left-hand index finger to hit B.
- daveloyall 10y agoOne of my "Why didn't I start doing this sooner?!" moments was copying my config files to all my machines. 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.
- dpcx 10y agohttps://github.com/nugget/netskel https://github.com/nugget/netskel is excellent for this; or you could always put everything in to a "dotfiles" repo that the cool kids are doing now.
- pp19dd 10y agoMany ways to accomplish the same thing in Linux, starting with a popen() call. ;) so thanks for pointing out tmux. 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.