How to setup an SSH Monitor daemon

9. How to setup an SSH Monitor daemon#

Running an IOC program as a daemon is really convenient in production. It’s very useful - among other things - in order to log the IOC Shell, in order to allow multiple users to share the same IOC Shell screen at the same time, in order to access and leave the IOC Shell at any point in time without having to restart the IOC program, etc.

If you wonder how to daemonize an IOC program, here are two suggestions with procServ and tmux.


9.1. procServ daemon#

Prerequisites:

procServ can be used as an easy daemonizer, e.g. with the SSH Monitor IOC program used as an example in the .cmd and .substitutions how-to:

$ procServ -n "sshmonitorTarget1" -c /path/to/myTargetMonitoringTop/iocBoot/iocMyTargetMonitoring/ -i ^D^C 20000 ./st_target1.cmd

Important

With the above command, the procServ instance associated to the IOC program is attached to the TCP port 20000. You want to make sure to use different and unique TCP port numbers for each new procServ instance associated to other IOC programs (that are run in parallel).

9.2. procServ tips#

  • Find procServ PID:

    $ pgrep procServ
    $ ps -aux | grep "procServ"
    
  • Find the SSH Monitor IOC program (running inside procServ) PID:

    $ pgrep sshmonitorTarget1
    $ ps -aux | grep "sshmonitorTarget1"
    
  • Restart the SSH Monitor IOC program (running inside procServ) by just killing it: procServ will restart it automatically:

    $ pgrep sshmonitorTarget1
        > 123123
    $ sudo kill -9 123123
    
  • Connect locally to procServ:

    $ telnet 127.0.0.1 20000
    
  • Quit procServ - without stopping the IOC program - by entering Ctrl + AltGr + ] and then enter quit.

  • Connect remotely to procServ:

    $ ssh host-username@<host-ip-address> -t telnet 20000
    

See also

For more details about procServ, see ralphlange/procServ


9.3. tmux daemon#

Prerequisites:

tmux can also be used as an easy daemonizer, e.g. with the SSH Monitor IOC program used as an example in the .cmd and .substitutions how-to:

$ tmux new-session -d -s sshmonitorTarget1 'cd /path/to/myTargetMonitoringTop/iocBoot/iocsshmonitor && ./st_target1.cmd'

9.4. tmux tips#

  • Enter your sshmonitorTarget1 tmux session (i.e. your {SSH_Monitor}} IOC Shell for target1):

    $ tmux a -t sshmonitorTarget1
    
    • Help screen (Q to quit):

      Ctrl+b ?
      
    • Scroll in window:

      Ctrl+b PageUp/PageDown
      
    • Enter scroll mode:

      Ctrl+b [
      

      (then up/down arrow keys and/or pageup/pagedown)

    • Exit scroll mode:

      > q
      
    • Detach from tmux without stopping the IOC program:

      Ctrl+b d
      
  • Stop the tmux daemon and associated IOC program:

    $ tmux kill-session -t sshmonitorTarget1
    
  • List currently running tmux daemons:

    $ tmux ls # or `$ tmux list-sessions`