MXS-2969: Restart MaxScale on upgrade

Renamed the postrm script to prerm since it is executed before
uninstallation.

Silenced the output of the systemctl disable commands and added a
conditional restart of MaxScale if a MaxScale instance is running.

Use getent instead of grep to detect if the maxscale user needs to be
created.
This commit is contained in:
Markus Mäkelä
2020-04-20 13:42:56 +03:00
parent c3ddcb9056
commit be567b6029
6 changed files with 17 additions and 10 deletions

View File

@ -119,7 +119,7 @@ configure_file(${CMAKE_SOURCE_DIR}/include/maxscale/paths.h.in ${CMAKE_BINARY_DI
configure_file(${CMAKE_SOURCE_DIR}/include/maxscale/adminusers.h.in ${CMAKE_BINARY_DIR}/include/maxscale/adminusers.h @ONLY) configure_file(${CMAKE_SOURCE_DIR}/include/maxscale/adminusers.h.in ${CMAKE_BINARY_DIR}/include/maxscale/adminusers.h @ONLY)
configure_file(${CMAKE_SOURCE_DIR}/server/test/maxscale_test.h.in ${CMAKE_BINARY_DIR}/include/maxscale/maxscale_test.h @ONLY) configure_file(${CMAKE_SOURCE_DIR}/server/test/maxscale_test.h.in ${CMAKE_BINARY_DIR}/include/maxscale/maxscale_test.h @ONLY)
configure_file(${CMAKE_SOURCE_DIR}/etc/postinst.in ${CMAKE_BINARY_DIR}/postinst @ONLY) configure_file(${CMAKE_SOURCE_DIR}/etc/postinst.in ${CMAKE_BINARY_DIR}/postinst @ONLY)
configure_file(${CMAKE_SOURCE_DIR}/etc/postrm.in ${CMAKE_BINARY_DIR}/postrm @ONLY) configure_file(${CMAKE_SOURCE_DIR}/etc/prerm.in ${CMAKE_BINARY_DIR}/prerm @ONLY)
configure_file(${CMAKE_SOURCE_DIR}/etc/upstart/maxscale.conf.in ${CMAKE_BINARY_DIR}/upstart/maxscale.conf @ONLY) configure_file(${CMAKE_SOURCE_DIR}/etc/upstart/maxscale.conf.in ${CMAKE_BINARY_DIR}/upstart/maxscale.conf @ONLY)
configure_file(${CMAKE_SOURCE_DIR}/test/maxscale_test.cnf ${CMAKE_BINARY_DIR}/maxscale.cnf @ONLY) configure_file(${CMAKE_SOURCE_DIR}/test/maxscale_test.cnf ${CMAKE_BINARY_DIR}/maxscale.cnf @ONLY)
configure_file(${CMAKE_SOURCE_DIR}/test/maxscale_test_secondary.cnf ${CMAKE_BINARY_DIR}/maxscale_secondary.cnf @ONLY) configure_file(${CMAKE_SOURCE_DIR}/test/maxscale_test_secondary.cnf ${CMAKE_BINARY_DIR}/maxscale_secondary.cnf @ONLY)
@ -256,7 +256,7 @@ if(PACKAGE)
install_program(${CMAKE_BINARY_DIR}/maxscale core) install_program(${CMAKE_BINARY_DIR}/maxscale core)
install_file(${CMAKE_BINARY_DIR}/maxscale.conf core) install_file(${CMAKE_BINARY_DIR}/maxscale.conf core)
install_program(${CMAKE_BINARY_DIR}/postinst core) install_program(${CMAKE_BINARY_DIR}/postinst core)
install_program(${CMAKE_BINARY_DIR}/postrm core) install_program(${CMAKE_BINARY_DIR}/prerm core)
# The inclusion of CPack needs to be the last effective packaging related command. All # The inclusion of CPack needs to be the last effective packaging related command. All
# configurations to packaging done after the call will be ignored. # configurations to packaging done after the call will be ignored.

View File

@ -105,5 +105,5 @@ else()
endif() endif()
message(STATUS "You can install startup scripts and system configuration files for MaxScale by running the 'postinst' shell script located at ${CMAKE_INSTALL_PREFIX}.") message(STATUS "You can install startup scripts and system configuration files for MaxScale by running the 'postinst' shell script located at ${CMAKE_INSTALL_PREFIX}.")
message(STATUS "To remove these installed files, run the 'postrm' shell script located in the same folder.") message(STATUS "To remove these installed files, run the 'prerm' shell script located in the same folder.")
endif() endif()

View File

@ -6,7 +6,7 @@ set(CPACK_DEBIAN_PACKAGE_FILE_NAME "${CPACK_PACKAGE_NAME}")
if(TARGET_COMPONENT STREQUAL "core" OR TARGET_COMPONENT STREQUAL "all") if(TARGET_COMPONENT STREQUAL "core" OR TARGET_COMPONENT STREQUAL "all")
set(CPACK_DEBIAN_PACKAGE_SHLIBDEPS ON) set(CPACK_DEBIAN_PACKAGE_SHLIBDEPS ON)
set(CPACK_DEBIAN_PACKAGE_CONTROL_EXTRA "${CMAKE_BINARY_DIR}/postinst;${CMAKE_BINARY_DIR}/postrm") set(CPACK_DEBIAN_PACKAGE_CONTROL_EXTRA "${CMAKE_BINARY_DIR}/postinst;${CMAKE_BINARY_DIR}/prerm")
elseif(TARGET_COMPONENT STREQUAL "devel") elseif(TARGET_COMPONENT STREQUAL "devel")
set(CPACK_DEBIAN_PACKAGE_DESCRIPTION "${CPACK_PACKAGE_DESCRIPTION_SUMMARY}\n${DESCRIPTION_TEXT}") set(CPACK_DEBIAN_PACKAGE_DESCRIPTION "${CPACK_PACKAGE_DESCRIPTION_SUMMARY}\n${DESCRIPTION_TEXT}")
endif() endif()

View File

@ -39,7 +39,7 @@ set(CPACK_RPM_USER_FILELIST "${IGNORED_DIRS}")
if(TARGET_COMPONENT STREQUAL "core" OR TARGET_COMPONENT STREQUAL "all") if(TARGET_COMPONENT STREQUAL "core" OR TARGET_COMPONENT STREQUAL "all")
set(CPACK_RPM_POST_INSTALL_SCRIPT_FILE ${CMAKE_BINARY_DIR}/postinst) set(CPACK_RPM_POST_INSTALL_SCRIPT_FILE ${CMAKE_BINARY_DIR}/postinst)
set(CPACK_RPM_PRE_UNINSTALL_SCRIPT_FILE ${CMAKE_BINARY_DIR}/postrm) set(CPACK_RPM_PRE_UNINSTALL_SCRIPT_FILE ${CMAKE_BINARY_DIR}/prerm)
endif() endif()
if(EXTRA_PACKAGE_DEPENDENCIES) if(EXTRA_PACKAGE_DEPENDENCIES)

View File

@ -12,8 +12,9 @@ mkdir -p @MAXSCALE_VARDIR@/lib/maxscale
mkdir -p @MAXSCALE_VARDIR@/cache/maxscale mkdir -p @MAXSCALE_VARDIR@/cache/maxscale
mkdir -p @MAXSCALE_VARDIR@/run/maxscale mkdir -p @MAXSCALE_VARDIR@/run/maxscale
# Create MaxScale user # Create MaxScale user if it doesnt' exist
if [ -f "/etc/passwd" ] && [ "$(grep -c 'maxscale' /etc/passwd)" -eq 0 ] getent passwd maxscale > /dev/null
if [ $? -eq 0 ]
then then
groupadd -r maxscale groupadd -r maxscale
useradd -r -s /bin/false -g maxscale maxscale useradd -r -s /bin/false -g maxscale maxscale
@ -63,7 +64,9 @@ then
fi fi
mkdir -p /etc/systemd/system/maxscale.service.d mkdir -p /etc/systemd/system/maxscale.service.d
systemctl enable maxscale.service systemctl enable maxscale.service > /dev/null
systemctl is-active maxscale.service --quiet && systemctl restart maxscale.service
else else
if [ -d "/etc/init/" ] && [ -f "@CMAKE_INSTALL_PREFIX@/@MAXSCALE_SHAREDIR@/upstart/maxscale.conf" ] if [ -d "/etc/init/" ] && [ -f "@CMAKE_INSTALL_PREFIX@/@MAXSCALE_SHAREDIR@/upstart/maxscale.conf" ]
then then
@ -77,6 +80,8 @@ else
else else
echo "Could not find init script: @CMAKE_INSTALL_PREFIX@/@MAXSCALE_SHAREDIR@/maxscale" >& 2 echo "Could not find init script: @CMAKE_INSTALL_PREFIX@/@MAXSCALE_SHAREDIR@/maxscale" >& 2
fi fi
service maxscale status > /dev/null && service maxscale restart > /dev/null
fi fi
# If no maxscale.cnf file is found in /etc, copy the template file there # If no maxscale.cnf file is found in /etc, copy the template file there

View File

@ -19,13 +19,15 @@ then
if [ -f /usr/lib/systemd/system/maxscale.service ] if [ -f /usr/lib/systemd/system/maxscale.service ]
then then
systemctl stop maxscale.service systemctl stop maxscale.service
systemctl disable maxscale.service systemctl disable maxscale.service > /dev/null
rm /usr/lib/systemd/system/maxscale.service rm /usr/lib/systemd/system/maxscale.service
systemctl daemon-reload
elif [ -f /lib/systemd/system/maxscale.service ] elif [ -f /lib/systemd/system/maxscale.service ]
then then
systemctl stop maxscale.service systemctl stop maxscale.service
systemctl disable maxscale.service systemctl disable maxscale.service > /dev/null
rm /lib/systemd/system/maxscale.service rm /lib/systemd/system/maxscale.service
systemctl daemon-reload
fi fi
if [ -f /etc/logrotate.d/maxscale_logrotate ] if [ -f /etc/logrotate.d/maxscale_logrotate ]