From 2b457bf372ef9c81d3a29582ff00898dc0299e2b Mon Sep 17 00:00:00 2001 From: Markus Makela Date: Mon, 11 May 2015 06:19:06 +0300 Subject: [PATCH] Updated init.d and systemd scripts. --- cmake/install_layout.cmake | 5 ++--- etc/init.d/maxscale.in | 4 ++-- etc/maxscale.service.in | 2 +- etc/postinst.in | 24 ++++++++++++++++++++---- etc/ubuntu/init.d/maxscale.in | 4 ++-- 5 files changed, 27 insertions(+), 12 deletions(-) diff --git a/cmake/install_layout.cmake b/cmake/install_layout.cmake index c55a25a32..e25bd0a8d 100644 --- a/cmake/install_layout.cmake +++ b/cmake/install_layout.cmake @@ -1,7 +1,4 @@ # Set the install layout -# Possible values: -# STANDALONE - Installs to /usr/local -# PACKAGE - Installs to /usr include(GNUInstallDirs) set(MAXSCALE_LIBDIR ${CMAKE_INSTALL_LIBDIR}/maxscale CACHE PATH "Library installation path") @@ -9,5 +6,7 @@ set(MAXSCALE_BINDIR ${CMAKE_INSTALL_BINDIR} CACHE PATH "Executable installation set(MAXSCALE_SHAREDIR ${CMAKE_INSTALL_DATADIR}/maxscale CACHE PATH "Share file installation path, includes licence and readme files") set(MAXSCALE_DOCDIR ${CMAKE_INSTALL_DOCDIR}/maxscale CACHE PATH "Documentation installation path, text versions only") set(MAXSCALE_CONFDIR ${CMAKE_INSTALL_SYSCONFDIR} CACHE PATH "Configuration file installation path, this is not usually needed") + +# This is the only hard-coded absolute path set(MAXSCALE_VARDIR /var CACHE PATH "Data file path (usually /var/)") diff --git a/etc/init.d/maxscale.in b/etc/init.d/maxscale.in index 4ee5ce0f4..70cdf5b3d 100755 --- a/etc/init.d/maxscale.in +++ b/etc/init.d/maxscale.in @@ -21,7 +21,7 @@ # MaxScale PIDFILE and LIB ############################################# -export MAXSCALE_PIDFILE=/var/run/maxscale/maxscale.pid +export MAXSCALE_PIDFILE=@MAXSCALE_VARDIR@/run/maxscale/maxscale.pid export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:@CMAKE_INSTALL_PREFIX@/@MAXSCALE_LIBDIR@/maxscale ############################### @@ -55,7 +55,7 @@ start() { CHECK_RET=$? [ $CHECK_RET -eq 0 ] && echo -n " found $my_check" && success && CHECK_RET=0 - daemon --pidfile $MAXSCALE_PIDFILE @CMAKE_INSTALL_PREFIX@/@MAXSCALE_BINDIR@/maxscale >& /dev/null + daemon --pidfile $MAXSCALE_PIDFILE @CMAKE_INSTALL_PREFIX@/@MAXSCALE_BINDIR@/maxscale --user=maxscale >& /dev/null RETVAL=$? [ $RETVAL -eq 0 ] && touch /var/lock/subsys/$servicename diff --git a/etc/maxscale.service.in b/etc/maxscale.service.in index 56b49d98f..50e781f30 100644 --- a/etc/maxscale.service.in +++ b/etc/maxscale.service.in @@ -4,7 +4,7 @@ After=network.target [Service] Type=forking -PIDFile=/var/run/maxscale/maxscale.pid +PIDFile=@MAXSCALE_VARDIR@/run/maxscale/maxscale.pid ExecStart=@CMAKE_INSTALL_PREFIX@/@MAXSCALE_BINDIR@/maxscale [Install] diff --git a/etc/postinst.in b/etc/postinst.in index fa0c4271c..f5b85f537 100755 --- a/etc/postinst.in +++ b/etc/postinst.in @@ -1,9 +1,25 @@ #!/bin/sh -mkdir -p /var/log/maxscale -mkdir -p /var/cache/maxscale -mkdir -p /var/run/maxscale -mkdir -p @CMAKE_INSTALL_PREFIX@/@MAXSCALE_SHARE_DIR@/ + +# Create directories +mkdir -p @MAXSCALE_LIBDIR@ +mkdir -p @MAXSCALE_BINDIR@ +mkdir -p @MAXSCALE_SHAREDIR@ +mkdir -p @MAXSCALE_DOCDIR@ +mkdir -p @MAXSCALE_CONFDIR@ +mkdir -p @MAXSCALE_VARDIR@/log/maxscale +mkdir -p @MAXSCALE_VARDIR@/lib/maxscale +mkdir -p @MAXSCALE_VARDIR@/cache/maxscale +mkdir -p @MAXSCALE_VARDIR@/run/maxscale + +# Create MaxScale user +if [ -f "/etc/passwd" -a "$(grep -c 'maxscale' /etc/passwd)" -eq 0 ] +then + useradd -s -r /bin/false maxscale + groupadd maxscale +fi + +# Copy init.d script and ldconfig file cp @CMAKE_INSTALL_PREFIX@/@MAXSCALE_SHAREDIR@/maxscale /etc/init.d/ cp @CMAKE_INSTALL_PREFIX@/@MAXSCALE_SHAREDIR@/maxscale.conf /etc/ld.so.conf.d/ /sbin/ldconfig diff --git a/etc/ubuntu/init.d/maxscale.in b/etc/ubuntu/init.d/maxscale.in index 27a73092c..315f16c5d 100755 --- a/etc/ubuntu/init.d/maxscale.in +++ b/etc/ubuntu/init.d/maxscale.in @@ -21,7 +21,7 @@ # MaxScale HOME, PIDFILE, LIB ############################################# -export MAXSCALE_PIDFILE=/var/run/maxscale/maxscale.pid +export MAXSCALE_PIDFILE=@MAXSCALE_VARDIR@/run/maxscale/maxscale.pid export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:@CMAKE_INSTALL_PREFIX@/@MAXSCALE_LIBDIR@/maxscale ############################### @@ -44,7 +44,7 @@ _RETVAL_STATUS_NOT_RUNNING=3 # stop/start/status related vars ################################# NAME=maxscale -DAEMON=@CMAKE_INSTALL_PREFIX@/@MAXSCALE_BINDIR@/maxscale +DAEMON=@CMAKE_INSTALL_PREFIX@/@MAXSCALE_BINDIR@/maxscale --user=maxscale # Source function library. . /lib/lsb/init-functions