Eric Norum wrote:
I suggest that you run the IOC daemon within a detached screen
session. This is how we start our 'soft' IOCs here. It is useful
in that it allows you to connect to the screen session and interact
with the IOC console when needed.
As has already been pointed out, this only seems to make sense under
an OS such as Unix or similar.
For our IOCs running on Linux, we use an xterm running on an X virtual
frame buffer (Xvfb) to host the soft IOC. The xterm runs Gnu screen,
which silently runs bash, which runs the IOC. This is all launched
from rc.local at boot time, and can be done from a headless host.
Later, one can attach to the Gnu screen session, and see what is
happening, or enter iocshell commands. Under Gnu screen, one can even
use the 'stuff' command to control and monitor the session to some
extent. We have arranged a web interface that is capable of stopping
and restarting the IOC using such a mechanism.
The code in rc.local (could, maybe should be given it's own proper
startup script) looks like this:
#====================================< rc.local
>==========================================
SCREEN_EPICS="IBCS EPICS"
#
# We run the EPICS IOC inside of Gnu screen sessions, so
# we can monitor them and send commands to their interactive
shells. We need
# a way to create a tty for them at boot time. The Xvfb provides
a virtual X server
# to support an xterm that can in turn support a bash shell.
#
echo "Launching X virtual framebuffer"
Xvfb :1 -fbdir /tmp &
# We really should do something more robust for this...
echo "Snoozing while the virtual X server finds it's fonts..."
sleep 10
export DISPLAY="localhost:1"
echo "Starting EPICS IOC xterm/screen"
xterm -e screen -S "$SCREEN_EPICS" su -c bash bomr &
echo "Snoozing while bash initializes..."
sleep 10
#
# Q: So what is all this `echo -ne '\015'` stuff?
# A: We are stuffing characters into a Gnu screen session, and
# this is how we stuff a 'newline'
#
# Help prevent exiting the base shell. Disable the 'exit' command.
# We can still exit the shell manually by typing 'Ctlr-D'
#
echo "Disabling 'exit' in EPICS bash shell"
screen -S "$SCREEN_EPICS" -X stuff "alias exit=''"`echo -ne '\015'`
echo "Starting EPICS IOC"
screen -S "$SCREEN_EPICS" -X stuff "cd
/usr1/local/epics/appl/bacnet"`echo -ne '\015'`
screen -S "$SCREEN_EPICS" -X stuff "./startup.ibcs"`echo -ne '\015'`
# echo Done
#=================================================================================
We disable the bash 'exit' command to ruggedize the system against
accidental termination through the Web interface. Sending 'exit' twice
in a row will first exit the IOC, then exit bash, killing the entire
Gnu screen session.
On Jun 8, 2006, at 4:58 AM, Christophe Moins wrote:
Hello,
I would like to daemonize an ioc process but I have not managed to
do it till now.
I tried to implement the classical solution by using the fork and
setsid routines but then the readout is not correctly performed by
the ioc.
Is there a simple way to do it ?
Thanks
Christophe