MS SQL Server 2017 upstart script

By dose | October 30, 2019
Under: Uncategorized

I recently had to install a MS SQL Server 2017 on Linux. Unfortunately, the supplied scripts only support the stupid systemd, not upstart, so for Devuan or Debian Jessie without systemd, the script may be benificial:

!/bin/sh
### BEGIN INIT INFO
# Provides: mssql-server
# Required-Start:       $syslog $local_fs $network.
# Required-Stop:        $syslog $local_fs $network.
# Default-Start:        2 3 4 5
# Default-Stop:         0 1 6
# Short-Description: Microsoft SQL Server Database Engine
### END INIT INFO
 
DESC="Microsoft SQL Server Database Engine"
NAME=mssql-server
PIDFILE=/var/run/$NAME.pid
DAEMON="/opt/mssql/bin/sqlservr"
SCRIPTNAME=/etc/init.d/mssql-server
USER=mssql
 
. /lib/lsb/init-functions
 
# Exit if the package is not installed
[ -x "$DAEMON" ] || exit 0
 
case "$1" in
        start)
                log_daemon_msg "Starting $DESC" "$NAME"
                start-stop-daemon --start --quiet --oknodo --chdir /var/opt/mssql --background --make-pidfile --pidfile $PIDFILE --chuid $USER \
                        --exec $DAEMON -- $DAEMON_ARGS
                log_end_msg $?
                ;;
        stop)
                log_daemon_msg "Stopping $DESC" "$NAME"
                start-stop-daemon --stop --retry=TERM/15/KILL/5 --remove-pidfile --pidfile $PIDFILE
                status=$?
                rm -f $PIDFILE
                log_end_msg $?
                ;;
        status)
                pidofproc -p $PIDFILE $DAEMON >/dev/null
                status=$?
 
                if [ $status -eq 0 ]; then
                        log_success_msg "$DESC is running"
                else
                        log_failure_msg "$DESC is not running"
                fi
                exit $status
                ;;
        reload|force-reload)
                log_daemon_msg "Reloading $DESC configuration..."
                start-stop-daemon --stop --signal 1 --quiet --pidfile $PIDFILE --name $NAME
                log_end_msg $?
                ;;
        restart)
                $0 stop
                sleep 1
                $0 start
                ;;
        *)
                echo "Usage: $SCRIPTNAME {start|stop|restart|reload|force-reload|status}"
                exit 1
                ;;
esac

Unformtunately, MS SQL Server 2017 on Debian Jessie is a real pain to install. Newer versions tend to crash (coredump) very often and without a recent openssl-version from jessie-backports (which can only be installed with a little trick nowadays), it just drops every TCP connection to the server on client side with:

Sqlcmd: Error: Microsoft ODBC Driver 17 for SQL Server : TCP Provider: Error code 0x2746.
Sqlcmd: Error: Microsoft ODBC Driver 17 for SQL Server : Client unable to establish connection.

and on server side respectively with error 0x80090304

So we need a suitable version of MS SQL Server and the correct version of openssl to get it working.
Here is what seems to work here (currently stress testing with HammerDB before productive use):

apt-get install curl apt-transport-https
echo "deb http://archive.debian.org/debian/ jessie-backports main contrib non-free" >>/etc/apt/sources.list
echo 'Acquire::Check-Valid-Until no;' > /etc/apt/apt.conf.d/99no-check-valid-until
apt-get update
apt-get install -t jessie-backports openssl
curl https://packages.microsoft.com/keys/microsoft.asc | sudo apt-key add -
curl https://packages.microsoft.com/config/ubuntu/16.04/mssql-server-2017.list | sudo tee /etc/apt/sources.list.d/mssql-server.list
apt-get install mssql-server=14.0.1000.169-2
/opt/mssql/bin/sqlservr-setup