Hi Patrick, On Tue, Jan 28, 2020 at 09:29:20AM +0100, Patrick Kristiansen wrote: | Hi Ingo | | Thank you for your reply. | | I can't say I disagree with your and the OpenBSD team's attitude about | bug-free daemons. But I am just a lowly application programmer, and | sometimes I introduce horrible bugs that make our systems crash. In many | cases it will be preferable to just start the process again (and, of | course, fix the bug) for the purposes of keeping our business running. | | But another use for daemon(8) is for its ability to detach the child | process from the controlling terminal and furthermore redirect its | stdout/stderr to syslog. Is there some mechanism to do that from the | shell? Perhaps a combination of nohup and starting a background job?
What I do to run a "normal" (non-daemon) program like a daemon, is to start it in tmux. To have this start during system startup, I have an @reboot cronjob: ---------------------------------------------------------------------- [weerd@cube] $ cat ~/bin/conlog #!/bin/sh # conlog: start a tmux session with cu logging to a file ###################################################################### # Can be used with the following @reboot cron line to start at boot: # # @reboot /home/weerd/bin/conlog PATH=/bin:/usr/bin LOG="/home/weerd/data/conlog/log.`date +%s`" mkdir -p `dirname ${LOG}` tmux new -d "script -c 'cu -l cuaU0 -s 115200' ${LOG}" ---------------------------------------------------------------------- At reboot, this will start a new (detached) tmux session that launches cu (under script) to log the serial console output from another OpenBSD machine. I can attach the tmux session and interact with the console of that machine if necessary. For the purpose of restarting crashing programs, you could do something similar: run your program in a tmux session (convenient to attach to when you want to look at its stdout/stderr output) and script something to restart when it errors out. You could then also send yourself e-mail to alert you to the restart. Cheers, Paul 'WEiRD' de Weerd -- >++++++++[<++++++++++>-]<+++++++.>+++[<------>-]<.>+++[<+ +++++++++++>-]<.>++[<------------>-]<+.--------------.[-] http://www.weirdnet.nl/