maria-developers team mailing list archive
-
maria-developers team
-
Mailing list archive
-
Message #03432
Install MariaDB as a Windows service in the installer
Hi everyone,
This patch adds a page to the Windows installer that asks the user if he
wants to set up MariaDB as a Windows service.
The way to do this is to hack the NSIS template for CPack. IMHO, this is
a bad way, but it is the recommended (and only) way to do stuff like this.
The patch in the attached file install-service.patch is the only thing
necessary for the current sources. It's a one liner. So far so good :)
The actual patch adds a file win\cmake\NSIS.template.in which is a copy
of the NSIS.template.in from CMake. The attached patch
NSIS.template.in.patch shows the diff with the code I have added.
Bo Thorsen.
Monty Program AB.
--
MariaDB: MySQL replacement
Community developed. Feature enhanced. Backward compatible.
=== modified file 'CMakeLists.txt'
--- CMakeLists.txt 2010-06-29 09:26:10 +0000
+++ CMakeLists.txt 2010-06-29 10:45:37 +0000
@@ -342,6 +342,9 @@
SET(CPACK_RESOURCE_FILE_LICENSE ${CMAKE_SOURCE_DIR}/COPYING)
SET(CPACK_GENERATOR NSIS)
+# Use our own NSIS template
+set(CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/win/cmake" ${CMAKE_MODULE_PATH})
+
# Installer components and grouping
SET(CPACK_COMPONENT_GROUP_SERVER_DESCRIPTION "The files necessary for running the MariaDB server.")
SET(CPACK_COMPONENT_GROUP_DEVELOPMENT_DESCRIPTION "Files used in development on the MariaDB server.")
--- \Program Files (x86)\CMake 2.8\share\cmake-2.8\Modules\NSIS.template.in 2010-03-16 18:52:34.000000000 +0100
+++ win\cmake\NSIS.template.in 2010-06-30 11:55:34.936755500 +0200
@@ -19,6 +19,10 @@
Var ADD_TO_PATH_CURRENT_USER
Var INSTALL_DESKTOP
Var IS_DEFAULT_INSTALLDIR
+
+ Var INSTALL_AS_SERVICE
+ Var INSTALL_AS_SERVICE_CHECKBOX
+
;--------------------------------
;Include Modern UI
@@ -27,6 +31,10 @@
;Default installation folder
InstallDir "$PROGRAMFILES\@CPACK_PACKAGE_INSTALL_DIRECTORY@"
+;Include the nsDialogs package
+ !include nsDialogs.nsh
+ !include LogicLib.nsh
+
;--------------------------------
;General
@@ -383,7 +391,35 @@
Pop $1
Pop $0
FunctionEnd
-
+
+Function InstallServicePage
+ !insertmacro MUI_HEADER_TEXT "Service Setup" "Run MariaDB automatically."
+
+ nsDialogs::Create /NOUNLOAD 1018
+ Pop $0
+
+ ${If} $0 == error
+ Abort
+ ${EndIf}
+
+ ${NSD_CreateLabel} 0u 0u 100% 9u "Should MariaDB be installed as a service?"
+ Pop $0
+
+ ${NSD_CreateCheckBox} 0u 14u 100% 16u "&Yes, please install the service."
+ Pop $INSTALL_AS_SERVICE_CHECKBOX
+ GetFunctionAddress $0 ServiceCheckBoxClicked
+ nsDialogs::OnClick /NOUNLOAD $INSTALL_AS_SERVICE_CHECKBOX $0
+
+ ${NSD_CreateLabel} 0u 30u 100% 35u "If this option is checked, this installer will add MariaDB to the list of services and start it."
+ Pop $0
+
+ nsDialogs::Show
+FunctionEnd
+
+Function ServiceCheckBoxClicked
+ ${NSD_GetState} $INSTALL_AS_SERVICE_CHECKBOX $INSTALL_AS_SERVICE
+FunctionEnd
+
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; Uninstall sutff
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
@@ -557,6 +593,8 @@
@CPACK_NSIS_PAGE_COMPONENTS@
+ Page custom InstallServicePage
+
!insertmacro MUI_PAGE_INSTFILES
!insertmacro MUI_PAGE_FINISH
@@ -718,6 +756,12 @@
@CPACK_NSIS_EXTRA_INSTALL_COMMANDS@
+ ${If} $INSTALL_AS_SERVICE == ${BST_CHECKED}
+ ;MessageBox MB_OK "Install the service"
+ nsExec::Exec '"$INSTDIR\bin\mysqld.exe" --install "@CPACK_PACKAGE_NAME@-@CPACK_PACKAGE_VERSION@"'
+ nsExec::Exec 'net start "@CPACK_PACKAGE_NAME@-@CPACK_PACKAGE_VERSION@"'
+ ${EndIf}
+
SectionEnd
Section "-Add to path"
@@ -818,6 +862,9 @@
@CPACK_NSIS_EXTRA_UNINSTALL_COMMANDS@
+ nsExec::Exec 'net stop "@CPACK_PACKAGE_NAME@-@CPACK_PACKAGE_VERSION@"'
+ nsExec::Exec '"$INSTDIR\bin\mysqld.exe" --remove "@CPACK_PACKAGE_NAME@-@CPACK_PACKAGE_VERSION@"'
+
;Remove files we installed.
;Keep the list of directories here in sync with the File commands above.
@CPACK_NSIS_DELETE_FILES@
Follow ups