Skip to Content
Technical Articles

SAP SQL Anywhere Tips – AutoStartup on Linux (Ver.17)

First

*This blogpost created upon request. If you have any question or request .Please feel free to request.

When running SAP SQL Anywhere Ver.17 on Linux, you may want to start the SAP SQL Anywhere database as a service along with the OS startup. Unexpectedly, there was no description in the manual, so this time I will explain how to do it.

Note: Environment variables setting

Several environment variables are required for controlling SAP SQL Anywhere on Linux. It is summarized in file named sa_config.sh (and sa_config.csh) in the bin64 or bin32 directory of your SQL Anywhere installation.

    • Whether to use under bin32 or bin64 depends on whether to use the 32-bit version of SQL Anywhere or the 64-bit version of SQL Anywhere.

By default of SQL Anywhere 17, the following files are created.

#!/bin/sh
#

# the following lines set the SA location.
SQLANY17="/opt/sqlanywhere17"
export SQLANY17

[ -r "$HOME/.sqlanywhere17/sample_env64.sh" ] && . "$HOME/.sqlanywhere17/sample_env64.sh"
[ -z "${SQLANYSAMP17:-}" ] && SQLANYSAMP17="/opt/sqlanywhere17/samples"
export SQLANYSAMP17

# the following lines add SA binaries to your path.
PATH="$SQLANY17/bin64:$SQLANY17/bin32:${PATH:-}"
export PATH
NODE_PATH="$SQLANY17/node:${NODE_PATH:-}"
export NODE_PATH

# the following lines are required to load the various shared objects of SA
PATH="$SQLANY17/bin64/jre180/bin:${PATH:-}"
LD_LIBRARY_PATH="$SQLANY17/bin64/jre180/lib/amd64/client:$SQLANY17/bin64/jre180/lib/amd64/server:$SQLANY17/bin64/jre180/lib/amd64:$SQLANY17/bin64/jre180/lib/amd64/native_threads:${LD_LIBRARY_PATH:-}"
export PATH
[ -z "${JAVA_HOME:-}" ] && JAVA_HOME="$SQLANY17/bin64/jre180"
export JAVA_HOME
LD_LIBRARY_PATH="$SQLANY17/lib32:${LD_LIBRARY_PATH:-}"
LD_LIBRARY_PATH="$SQLANY17/lib64:${LD_LIBRARY_PATH:-}"
export LD_LIBRARY_PATH

By reading this file, the necessary environment variables will be set. If you are using bash (etc.), it looks like the following.

$ source /opt/sqlanywhere17/bin64/sa_config.sh

Of course, you can set synonymous environment variables and paths without reading this file. These environment variables are required to control SAP SQL Anywhere. It may be possible to incorporate it into .bashrc of the OS user who manages it so that it can be read at login.

Systemd and SysVinit

When starting as a “service” on Linux, it seems that SysVinit was used once, and now Systemd is used more often. This depends on your Linux distribution and should be investigated. It seems that newer distributions use systemd. The “dbsvc” utility attached to the Linux version of SAP SQL Anywhere has the function to create the Service file used by Systemd in Ver.17. Earlier versions support SysVinit.

Ver.17 – dbsvc utility

This utility creates a Service file for use with Systemd.

http://dcx.sap.com/index.html#sqla170/en/html/813df9e16ce21014bf5cdf75390e9c94.html

First of all, prepare a database file that can be started with dbsrv17 / dbeng17 and the command parameters used for starting.

dbsrv17/dbeng17 <options> <dbfile>

*Make a note of the <options> and <dbfile> parts.

The dbsvc utility use <options> and <dbfile> for paramater.

Then, prepare a session such as SSH with a user who has write permission to /etc/init.d, or a root user that has set the environment variables for SAP SQL Anywhere explained above. Recently, it seems that there are many cases where sudo is used.

$ sudo bash

root # source /opt/sqlanywhere17/binXX/sa_config.sh

*XX=32 or 64.

You may prepare a shell for the root user as above. Then run the dbsvc command. The basics are as follows.

root # dbsvc -a <username> -t <network|personal> -w <servicename> <options> <dbfile>

<username> : The user name that runs the dbsrv17 / dbeng17 process. Use OS-username that you normally run dbsrv17/dbeng17.

<network|personal> : network server (dbsev17) or personal server (dbeng17)

<servicename> : The service name used on Systemd. “SA_” is automatically added at the beginning.

<options> <dbfile> : It is the parameter used at startup with dbsrv17 / dbeng17 that I wrote down earlier

Example:

root # dbsvc -a ubuntu -t network -w demo -n demo -o /home/ubuntu/database/serverlog.txt /home/ubuntu/database/demo.db
SQL Anywhere Service Utility 17.0.10.6127
Creating SQL Anywhere service: demo File: /lib/systemd/system/SA_demo.service

Note: An error will occur if the “pkg-config” package is not installed on your Linux .Please install it beforehand with “apt install pkg-config” etc.

As shown in the command output, a service file is created under / lib / systemd / system /. The file looks like this:

[Unit]
Description=SQLAnywhere Network demo service
After=syslog.target network.target local-fs.target

[Service]
Type=forking
Nice=0
User=ubuntu
PIDFile=/run/SA_demo/service.pid
Environment="TMP=/tmp/\x2eSQLAnywhere"
Environment="ODBCINI="
Environment="PIDFILE=/run/SA_demo/service\x2epid"
Environment="SERVICENAME=demo"
Environment="SVC_IFACE=systemd"
Environment="SQLANYDIR=/opt/sqlanywhere17"
Environment="BIN=bin64"
Environment="BITNESS=64"
Environment="DBSVC_TYPE=network"
Environment="SVC_TOOL_CMDLINE='-n' 'demo' '-o' '/home/ubuntu/database/serverlog.txt' '/home/ubuntu/database/demo.db' '-ud' "
ExecStartPre=-/bin/rm -f "/run/SA_demo/service\x2epid"
ExecStopPost=/bin/rm -f "/run/SA_demo/service\x2epid"
ExecStart=/opt/sqlanywhere17/bin64s/dbsvc RUNSERVICECMD start

# INPUTCMD=dbsvc '-a' 'ubuntu' '-t' 'network' '-w' 'demo' '-n' 'demo' '-o' '/home/ubuntu/database/serverlog.txt' '/home/ubuntu/database/demo.db'

If you can create this file, check if it can be started as a service. Check like a following.
(The startup method and confirmation method as a service are also as follows.)

Note: After executing dbsvc, it is better to reload services with “systemctl daemon-reload” .

Start Service:

root # systemctl start SA_demo

The service name specified here is “SA_” + the name specified with -w of dbsvc.

Check the service status :

root # systemctl status SA_demo

The following is displayed and you can check whether it is active or not.

SA_demo.service – SQLAnywhere Network demo service
Loaded: loaded (/lib/systemd/system/SA_demo.service; enabled; vendor preset:
Active: active (running) since Tue 2020-05-19 07:30:53 UTC; 8s ago
Process: 26239 ExecStopPost=/bin/rm -f /run/SA_demo/service.pid (code=exited,
Process: 26261 ExecStart=/opt/sqlanywhere17/bin64s/dbsvc RUNSERVICECMD start (
Process: 26258 ExecStartPre=/bin/rm -f /run/SA_demo/service.pid (code=exited,
Main PID: 26847 (dbsrv17)
Tasks: 25
Memory: 11.3M
CPU: 1.716s
CGroup: /system.slice/SA_demo.service
mq26847 /opt/sqlanywhere17/bin64s/../bin64/dbsrv17 -n demo -o /home/u

*Besides this, it is good to check if the actual process exists by “ps -ef | grep dbsrv17” etc.

Stop Service:

root # systemctl stop SA_demo

How to set as AutoStart ?

Some processing is required to automatically start this created Service.
Please note that automatic startup will not be enabled with “systemctl enable SA_<service name>” at this time.

In particular

[Unit]
Description=SQLAnywhere Network demo service
After=syslog.target network.target local-fs.target

[Service]
Type=forking
Nice=0
User=ubuntu
PIDFile=/run/SA_demo/service.pid
Environment="TMP=/tmp/\x2eSQLAnywhere"
Environment="ODBCINI="
Environment="PIDFILE=/run/SA_demo/service\x2epid"
Environment="SERVICENAME=demo"
Environment="SVC_IFACE=systemd"
Environment="SQLANYDIR=/opt/sqlanywhere17"
Environment="BIN=bin64"
Environment="BITNESS=64"
Environment="DBSVC_TYPE=network"
Environment="SVC_TOOL_CMDLINE='-n' 'demo' '-o' '/home/ubuntu/database/serverlog.txt' '/home/ubuntu/database/demo.db' '-ud' "
ExecStartPre=-/bin/rm -f "/run/SA_demo/service\x2epid"
ExecStopPost=/bin/rm -f "/run/SA_demo/service\x2epid"
ExecStart=/opt/sqlanywhere17/bin64s/dbsvc RUNSERVICECMD start

# INPUTCMD=dbsvc '-a' 'ubuntu' '-t' 'network' '-w' 'demo' '-n' 'demo' '-o' '/home/ubuntu/database/serverlog.txt' '/home/ubuntu/database/demo.db'

[Install]
WantedBy=multi-user.target

Add [Install] and WantedBy entries at the end of the file as above.

* For the contents of this Service file, please refer to the manuals on the Linux and various explanation web sites before setting. Required if there are requirements such as SAP SQL Anywhere must be started before your application is started. This example sets what seems to be the most common example.

And then

root # systemctl enable SA_demo

Activate the service with above.

Let’s restart the OS. If the dbsrv17 / dbeng17 process is running with the ps command, you are done.

 

Additional Note:

In the above example, the argument to dbsrv17 / dbeng17 was used as it is as the argument to dbsvc, but when using it as a service, consider using a configuration file. Otherwise, you will need to edit the service file when changing the database configuration parameters. If you set it to read the configuration file, it will be read, so you can reflect the changes without editing the service file.

Let’s do it!:

There are many ways to start process/service automatically on Linux. There may be a simpler method depending on the OS (distribution), so please check the OS manual and consider which method to use.

Have a nice day!

Be the first to leave a comment
You must be Logged on to comment or reply to a post.