Is there a way to join an interactive session of a process that was ran on boot with /etc/rc.local, or send it "stop" over STDIN on reboot/shutdown and wait for it to end before shutting down?
Asked
Active
Viewed 182 times
1 Answers
0
As has been explained in comments, you need to “save” the process's stdin somehow. By default, depending on the init system, this may be the console, or /dev/null
. To be able to attach to the process, use a screen multiplexer such as Screen or tmux. See also How can I disown a running process and associate it to a new screen shell?
In /etc/rc.local
, run something like
screen -S mydaemon -md /usr/local/bin/mydaemon --some-option
To attach to the program interactively, you would then run
screen -S mydaemon -rd
To automatically send keystrokes to the program (see sending text input to a detached screen):
screen -S mydaemon -p 0 -X stuff 'bye^M'

Gilles 'SO- stop being evil'
- 829,060
-
-
@JanNovák That sends keyboard input to the application, which you requested in the question. – Gilles 'SO- stop being evil' Jul 23 '17 at 15:48
screen
ortmux
you could certainly do that – Eric Renouf Jul 18 '17 at 11:31screen
ortmux
, they'll have their own psuedo-tty that you can attach to any time you like, and detach from again and they'll keep going. They're really useful if you're going to want something to continue across sessions in particular. I use it to start some jobs then ssh from another machine to see how they're going for example – Eric Renouf Jul 18 '17 at 13:29rc.local
has been superseded on many operating systems, several times over on some. It only thus works at all via backwards compatibility shims. Exactly how those backwards compatibility shims work varies, moreover. With several of themrc.local
does not even have an interactive session and a controlling terminal.rc.local
thus does not work the same everywhere, and you need to be specific about what operating system this question pertains to. – JdeBP Jul 18 '17 at 13:31wait
after you send it the stop, or keep checking withpgrep
or similar – Eric Renouf Jul 18 '17 at 13:33rc.local
are different in each. You really do need to be specific. In the wider picture, you should of course forget aboutrc.local
. – JdeBP Jul 18 '17 at 21:22