2017-05-24

Startup script to run Sybase ASE automatically after unix booting

Unfortunately after installation when the server is rebooted, Sybase is not starting automatically. The  problem is, that Sybase installation is done using a non privileged account, so there is no way to modify system files starting Sybase automatically.

Below you can find a script, that can be used to automatically manage Sybase on Linux machine and it can be probably also used on other Unix machines. You can call it with start or stop or restart parameter, so this is a good candidate to use it with every systemd compatible operating system.

If you would like to have Sybase starting after each OS boot perform following configuration. Create a service file and save it as /etc/systemd/sysctl/sybase.service. If required change the path to point to correct location of the scrip sybase_start

[Unit]
Description=SYBASE ASE
After=network.target

[Service]
ExecStart=/opt/sap/sybase_start start
Type=forking
PIDFile=/opt/sap/sybase.pid
ExecStop=/opt/sap/sybase_start stop

[Install]
WantedBy=multi-user.target
As you see, we need to have additional script named sybase_start. Note the paths that are used at the beginning of the script. Starting sybase is easy, however stopping may be slightly tricky. Server should generally be stopped using the SQL shutdown command, but than the password needs to be given in clear text in the script. As I don't like this solution I decided to kill the dataserver process, what is not compliant with Sybase best practices, but you can change this.Just comment my command and uncomment the other one.

Content of /opt/sap/sybase_start script:

#!/bin/sh
#
# Startup script for Sybase ASE
#
# description: Sybase Adaptive Server Enterprise
# is a SQL database server.
# processname: dataserver

#change the path to where sybase has been installed and how your server is named
SYBASE=/opt/sap
SERVER=SAP01

# Source environment variables.
. $SYBASE/SYBASE.sh

# Find the name of the script
NAME=`basename $0`

# For SELinux we need to use 'runuser' not 'su'
if [ -x /sbin/runuser ]
then
        SU=runuser
else
        SU=su
fi

start() {
        SYBASE_START=$"Starting ${NAME} service: "
        $SU sap -c ". $SYBASE/SYBASE.sh; $SYBASE/$SYBASE_ASE/bin/startserver \
-f $SYBASE/$SYBASE_ASE/install/RUN_${SERVER} > /dev/null"
        ret=$?
        if [ $ret -eq 0 ]
        then
                showserver | grep dataserver | awk '{ print $4 }' > /opt/sap/sybase.pid
                echo "$SYBASE_START Success."
        else
                echo "$SYBASE_START Failed!"
              exit 1
        fi
}

stop() {
        echo -n $"Stopping ${NAME} service: "

 #password needs to be given in clear text:
        #$SU sap -c ". $SYBASE/SYBASE.sh; isql -S $SERVER -U sa -P '******' < \
#$SYBASE/$SYBASE_ASE/upgrade/shutdown.sql > /dev/null"

 #kill the process
        pkill dataserver

        ret=$?
        if [ $ret -eq 0 ]
        then
                echo "Success."
        else
                echo "Failed!"
                exit 1
        fi
}


restart() {
        stop
        start
}


case "$1" in

        start)
                start
                ;;
        stop)
                stop
                ;;
        restart)
                restart
                ;;
        *)
                echo $"Usage: $0 {start|stop|restart}"
                exit 1
esac
exit 0

Having those 2 files, now the service should be registered. Issue following commands:

1. To force systemd to note that a new service has been created:
 
systemctl daemon-reload

2. To enable the systemd to start the Sybase at boot:
 
systemctl enable sybase.service

3. To start the service manually:
 
systemctl start sybase.service

4. To check the status of the service:
 
systemctl status sybase.service

3. To stop the service manually:
 
systemctl stop sybase.service

If you would like to have also the backup server running after server boot, than similar pair of files should be created:

/etc/systemd/sysctl/sybase.service


[Unit]
Description=SYBASE ASE BS
After=network.target

[Service]
ExecStart=/opt/sap/sybase_bs_start start
Type=forking
PIDFile=/opt/sap/sybase_bs.pid
ExecStop=/opt/sap/sybase_bs_start stop

[Install]
WantedBy=multi-user.target

/opt/sap/sybase_start




#!/bin/sh
#
# Startup script for Sybase Backup Server
#
# description: Sybase Adaptive Server Enterprisea Backup Server
# is a SQL database backup server.
# processname: backupserver

SYBASE=/opt/sap
SERVER=SAP01_BS

# Source environment variables.
. $SYBASE/SYBASE.sh

# Find the name of the script
NAME=`basename $0`

# For SELinux we need to use 'runuser' not 'su'
if [ -x /sbin/runuser ]
then
        SU=runuser
else
        SU=su
fi

start() {
        SYBASE_START=$"Starting ${NAME} service: "
        $SU sap -c ". $SYBASE/SYBASE.sh; $SYBASE/$SYBASE_ASE/bin/startserver \
-f $SYBASE/$SYBASE_ASE/install/RUN_${SERVER} > /dev/null"
        ret=$?
        if [ $ret -eq 0 ]
        then
                showserver | grep backupserver | awk '{ print $4 }' > /opt/sap/sybase_bs.pid
                echo "$SYBASE_START Success."
        else
                echo "$SYBASE_START Failed!"
              exit 1
        fi
}

stop() {
        echo -n $"Stopping ${NAME} service: "

 #password needs to be given in clear text
        #$SU sap -c ". $SYBASE/SYBASE.sh; isql -S $SERVER -U sa -P '' < \
        #$SYBASE/$SYBASE_ASE/upgrade/shutdown.sql > /dev/null"
        #or execute sql command:
        #shutdown SYB_BACKUP with nowait

 #kill the process:
        pkill backupserver

        ret=$?
        if [ $ret -eq 0 ]
        then
                echo "Success."
        else
                echo "Failed!"
                exit 1
        fi
}


restart() {
        stop
        start
}


case "$1" in


        start)
                start
                ;;
        stop)
                stop
                ;;
        restart)
                restart
                ;;
        *)
                echo $"Usage: $0 {start|stop|restart}"
                exit 1
esac
exit 0

Remember to register this service as it was done with the previous one.

Have fun!

2 comments:

  1. I see some info in KBA 2020192 that ASE does some level of processing in response to a SIGTERM signal. I wonder if there's any risk of corruption?

    ReplyDelete
  2. The backup server start scrip must be modified

    ReplyDelete

SAP Adaprive Server Enterprise

SAP Adaprive Server Enterprise
SAP Adaprive Server Enterprise