You are not logged in.

#1 2015-05-12 18:54:46

anadyr
Member
Registered: 2005-02-10
Posts: 225

[SOLVED] Trigger action once port is up

Hi,

On my computer I have two programs installed that start as systemctl services after the other. The first program is oracle-xe, a non free DBMS which I have installed from AUR. The second program is TOPdesk, a professional service management tool which is not publicly available. TOPdesk depends on oracle-xe; it connects to the oracle-database via port 1521. The problem is that TOPdesk often fails to start because the "systemctl start oracle-xe" commands ends before the functionality of oracle-xe is available. In particular port 1521 is not up yet when the TOPdesk service is started.

I want to solve this problem with a recursive bash script, which basically stops TOPdesk from starting until port 1521 is up. I then call this script from within the systemctl service, either in the oracle-xe.service after the oracle command, or in the TOPdesk service before the TOPdesk command.

/usr/bin/port1521check.sh file

#!/bin/sh
#
# this is a recursive bash script

if [ CHECK-IF-PORT-1521-IS-UP ]; then
   echo oracle-xe is up
   else
   sleep 1
   echo waiting for oracle-xe
   /usr/bin/port1521check.sh
fi

The exact issue here is the CHECK-IF-PORT-1521-IS-UP in the script above. How should this be solved?

These are the two systemctl files that are called. Note the commented line that refers to the script /usr/bin/port1521check.sh

oracle-xe.service file

[Unit]
Description=Oracle XE

[Service]
Type=oneshot
ExecStart=/etc/rc.d/oracle-xe start
#ExecStart=/usr/bin/port1521check.sh
ExecStop=/etc/rc.d/oracle-xe stop
RemainAfterExit=yes

[Install]
WantedBy=multi-user.target

topdesk54.service file

[Unit]
Description=TOPdesk 5.4SP1
Requires=oracle-xe.service
After=oracle-xe.service

[Service]
Type=forking
PIDFile=/opt/topdesk54/TOPdesk.pid
ExecStart=
#ExecStart=/usr/bin/port1521check.sh
ExecStart=/opt/topdesk54/topdesk start defaults
ExecStop=/opt/topdesk54/topdesk stop
RemainAfterExit=yes

[Install]
WantedBy=multi-user.target

Firstly, do you think I am I on the right track with this approach? Secondly, what command or script can I use to actually make this script see that port 1521 is up? Is it possible to use nmap output of a scan of localhost? Google has not been very helpful with this issue.

Many thanks in advance!

Last edited by anadyr (2015-05-14 07:14:27)

Offline

#2 2015-05-12 21:15:38

branch
Member
Registered: 2014-03-16
Posts: 209

Re: [SOLVED] Trigger action once port is up

Only type=oneshot can have multiple ExecStart= lines, so you cannot call port1521check.sh from topdesk54.service in this manner. I would probably write a wrapper script for topdesk54 that waits for the port then exec's it. You can use nc -z to test a port. Also the env has been sanitized so you may not have a PATH. Also, tail recursion is wierd. So, something like:

#!/usr/bin/bash
until /usr/bin/nc -z -w1 localhost 1521 ; do
        echo waiting for oracle-xe
        /usr/bin/sleep 1
done
echo oracle-xe is up
exec /opt/topdesk54/topdesk "$@"

Offline

#3 2015-05-14 07:15:41

anadyr
Member
Registered: 2005-02-10
Posts: 225

Re: [SOLVED] Trigger action once port is up

nc -z exactly provides the functionality that I want. Many thanks!

Offline

Board footer

Powered by FluxBB