diff --git a/CMakeLists.txt b/CMakeLists.txt index 24995accb..3a3c4f38d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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}/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/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}/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) @@ -256,7 +256,7 @@ if(PACKAGE) install_program(${CMAKE_BINARY_DIR}/maxscale core) install_file(${CMAKE_BINARY_DIR}/maxscale.conf 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 # configurations to packaging done after the call will be ignored. diff --git a/cmake/package.cmake b/cmake/package.cmake index b465dcc76..d044e6e13 100644 --- a/cmake/package.cmake +++ b/cmake/package.cmake @@ -105,5 +105,5 @@ else() 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 "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() diff --git a/cmake/package_deb.cmake b/cmake/package_deb.cmake index 87e9bf577..188d782c0 100644 --- a/cmake/package_deb.cmake +++ b/cmake/package_deb.cmake @@ -6,7 +6,7 @@ set(CPACK_DEBIAN_PACKAGE_FILE_NAME "${CPACK_PACKAGE_NAME}") if(TARGET_COMPONENT STREQUAL "core" OR TARGET_COMPONENT STREQUAL "all") 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") set(CPACK_DEBIAN_PACKAGE_DESCRIPTION "${CPACK_PACKAGE_DESCRIPTION_SUMMARY}\n${DESCRIPTION_TEXT}") endif() diff --git a/cmake/package_rpm.cmake b/cmake/package_rpm.cmake index bad8f91c0..76136d647 100644 --- a/cmake/package_rpm.cmake +++ b/cmake/package_rpm.cmake @@ -39,7 +39,7 @@ set(CPACK_RPM_USER_FILELIST "${IGNORED_DIRS}") if(TARGET_COMPONENT STREQUAL "core" OR TARGET_COMPONENT STREQUAL "all") 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() if(EXTRA_PACKAGE_DEPENDENCIES) diff --git a/etc/postinst.in b/etc/postinst.in index 7cc2435b2..620d132b7 100755 --- a/etc/postinst.in +++ b/etc/postinst.in @@ -12,8 +12,9 @@ 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" ] && [ "$(grep -c 'maxscale' /etc/passwd)" -eq 0 ] +# Create MaxScale user if it doesnt' exist +getent passwd maxscale > /dev/null +if [ $? -eq 0 ] then groupadd -r maxscale useradd -r -s /bin/false -g maxscale maxscale @@ -63,7 +64,9 @@ then fi 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 if [ -d "/etc/init/" ] && [ -f "@CMAKE_INSTALL_PREFIX@/@MAXSCALE_SHAREDIR@/upstart/maxscale.conf" ] then @@ -77,6 +80,8 @@ else else echo "Could not find init script: @CMAKE_INSTALL_PREFIX@/@MAXSCALE_SHAREDIR@/maxscale" >& 2 fi + + service maxscale status > /dev/null && service maxscale restart > /dev/null fi # If no maxscale.cnf file is found in /etc, copy the template file there diff --git a/etc/postrm.in b/etc/prerm.in similarity index 83% rename from etc/postrm.in rename to etc/prerm.in index 2824942c8..0b05235c8 100755 --- a/etc/postrm.in +++ b/etc/prerm.in @@ -19,13 +19,15 @@ then if [ -f /usr/lib/systemd/system/maxscale.service ] then systemctl stop maxscale.service - systemctl disable maxscale.service + systemctl disable maxscale.service > /dev/null rm /usr/lib/systemd/system/maxscale.service + systemctl daemon-reload elif [ -f /lib/systemd/system/maxscale.service ] then systemctl stop maxscale.service - systemctl disable maxscale.service + systemctl disable maxscale.service > /dev/null rm /lib/systemd/system/maxscale.service + systemctl daemon-reload fi if [ -f /etc/logrotate.d/maxscale_logrotate ]