Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Panel
11. How do I create a startup script for my ioc?

The third and final script is specifically to setup and start your EPICS ioc.

The 'startupConsolestartup-laciepics-rtbd32.cmd' lets you start your EPICS ioc as a foreground process in your host.

This lets you observe the ioc boot process to catch errors and interact with the ioc shell via iocConsole.

This is useful during development for debugging. Once the ioc has been tested fully, you can automatically start and run the process in background.

Under linuxRT, your EPICS ioc must run as a real-time process. It must lock the kernel in memory.

The following command in your 'startupConsolestartup-laciepics-rtbd32.cmd' does that:

ulimit -l unlimited

The following line is also needed to run the ioc with real-time priorities:

ulimit -r unlimited

Finally, you will be running your ioc as a specific user called as 'laci' who has permissions to run this ioc:
Setup the permissions for this user 'laci':

umask 002

Now you are ready to start your IOC and have it run as a foreground process.

Create a directory called as 'vioc-b34-bd32' for your ioc as below:
 
mkdir $IOC/ioc-b34-bd32/vioc-b34-bd32

cd $IOC/ioc-b34-bd32/vioc-b34-bd32
 
Set up a soft link to the 'bin' directory of your IOC app that you created in step (6). This is where your executable is:

ln -s  /afs/slac/g/lcls/epics/R3-14-12-3_1-0/iocTop/Test/Development/bin/linuxRT-x86 bin

Create an ASCII text file called 'screenrc' with the following lines in it:

deflog on

logtstamp on

defscrollback 10000

'screenrc' is passed as an argument to the 'screen' process and allows us to customize a few parameters such as number of lines stored in history buffer that we can scroll back for viewing.

In the same directory $IOC/ioc-b34-my01/vioc-b34-my01, add a startup script 'iocStartup.cmd' for vioc-b34-my01:

It setups some shell environment variables used by all iocs, and starts the st.cmd file in your ioc boot directory.

The EPICS environment variables that are set in this script can be used by your application's st.cmd script.

The default st.cmd script generated by the module icdTemplates, expects the following environment values to be defined somewhere.

iocStartup.cmd may be a good place to define it:

epicsEnvSet("IOC_NAME","VIOC:B34:BD32")

epicsEnvSet("IOC_APP","/afs/slac/g/lcls/epics/R3-14-12-3_1-0/iocTop/Test/Development")

epicsEnvSet("IOC_BOOT","${IOC_APP}/iocBoot/vioc-b34-bd32")

epicsEnvSet("IOC_COMMON","/afs/slac/g/lcls/epics/iocCommon")

epicsEnvSet("SYS_FACILITY","SYS0")

In addition to setting these environment variables, this script also executes some scripts common to all EPICS IOCs, such as below:

${IOC_COMMON}/All/Dev/linuxRT_pre_st.cmd

${IOC_COMMON}/All/Dev/linuxRT_post_st.cmd

The IOC application startup occurs between the pre and post scirpts:

cd ${IOC_BOOT}

< st.cmd

...

Panel
13. How do I start my ioc and monitor it?

(a) You can directly ssh to your ioc as 'laci' from any LCLSDEV host:

ssh laci@ioc-b34-bd32

$ cd /afs/slac/g/lcls/epics/iocCommon/ioc-b34-bd32

Alternately, you can get a console to the target ioc-b34-bd32 using iocConsole and ssh as user "laci" from there:

iocConsole ioc-b34-bd32

When prompted to enter the "login" username as below, enter "laci".

Welcome to Buildroot

ioc-b34-bd32 login:

No password is needed. Just hit Enter an you will get the shell prompt "$".

 Ensure the caRepeater process is running on this CPU.

(b) Ensure your IOC is not already running as below:

$ screen -ls

No Sockets found in /tmp/uscreens/S-laci. 

You can also look for your application under all running processes and make sure one is not already running:

If it was running already, then you may get something as below:

$ ps -ef | grep MyTest

 2085 laci       0:07 bin/MyTest iocStartup.cmd 

(c) Change to $IOC/ioc-b34-bd32 and from there start your ioc as a foreground process as below: 

$ pwd

/home/laci

$ ls -lt

total 0

lrwxrwxrwx    1 root     lcls            45 Nov  5 15:11 bld -> /afs/slac/g/lcls/epics/iocCommon/ioc-b34-bd32

$ cd bld
Ensure that 'startupConsolestartup-laciepics-rtbd32.cmd' is in your current directory.

$ ls -lt | grep startupConsolestartup-laciepics-rtbd32.cmd

-rwxrwxr-x    1 8396     1020          1225 Nov  5 15:22 startupConsolestartup-laciepics-rtbd32.cmd

Start the ioc as a foreground process:

./startupConsolestartup-laciepics-rtbd32.cmd

You can observe the viocb34bd32 go through the boot process.

If you had an EVR230 and it was initialized correctly, you may see something as below before iocInit():

ErConfigure(0, 0, 0, 0, 1)

Try EvrOpen, device = /dev/era3

EVR Found with Firmware Revision 0x11000007

Found a PMC_EVR /dev/era3

Verify if all your drivers, modules and databases loaded correctly.

If you used iocConsole, you can scroll back and forth in the screen using <CTRL> A-[ and <CTRL>-A-]

If everything went well, you must get your interactive ioc shell prompt as below:

vioc-b34-bd32> 

(d) Once the ioc is started, you can interact with vioc-b34-bd32 from any LCLSDEV host via ssh laci@ioc-b34-bd32:

To attach a screen session:

screen  -r  vioc-b34-bd32

To detach from a screen session:

<CTRL> A D

(e) To exit an EPICS IOC Process type exit at the IOC Shell and you will be back at the "$" prompt:

vioc-b34-bd32>exit

If the IOC hangs too long while trying to exit, use <CTRL> C

Panel
14. How do I start my ioc automatically every time my server boots up?

You can start your ioc as a background process that will start up everytime your Linux server reboots, as follows:

In $IOC/ioc-b34-bd32, you can add another script 'startup-laci-rt.cmd' that lets you start your EPICS-based ioc as a background process in your host.

Invoke this script from  $IOC/ioc-b34-bd32/startup.cmd:

su laci -c /usr/local/lcls/epics/iocCommon/eioc-b34-bd32/startup-laci-rt.cmd

The above line starts another shell so that the user called "laci" can start the IOC Process as opposed to the "root" account

Remember, the kernel modules can only be loaded onto the kernel with "root" permissions but iocs can be run by users.

'startup-laci-rt.cmd' executes the EPICS-based IOC startup script and detaches it using the linux screen program

It contains the following lines which are similar to what we have in startupConsolestartup-laciepics-rtbd32.cmd:

export EPICS_IOCS=/afs/slac/g/lcls/epics/iocCommon

# Lock Kernel in memory
ulimit -l unlimited
# Run with real-time priorities
ulimit -r unlimited

# Set umask for the laci user
umask 002

# EPICS IOC Application Real-time Process

cd $EPICS_IOCS/ioc-b34-bd32/vioc-b34-bd32

 screen -h 8192 -c screenrc -dm -S vioc-b34-bd32 bin/MyTest iocStartup.cmd 

The above line will automatically start your ioc and have it running in the background, every time your server reboots

To view the console output from the running ioc, you can attach the screen process to it, as described below:

(1)   ssh into the ioc-b34-b32 as user  "laci":

ssh laci@ioc-b34-bd32

(2) To see the list of all EPICS iocs running on this CPU, at the console type:

screen  -ls

(3) To attach to vioc-b34-b32 that is running MyTest application:

screen -r vioc-b34-b32

...