forked from netdata/netdata
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Run the agent as a Windows service. (netdata#17766)
* Run the agent as a Windows service. This commit contains the boilerplate code for running the agent as a Windows service. We start the agent's main as a separate thread, although this is not strictly required based on my experiments. We need similar logic for calling netdata's exit function when someone wants to stop the agent. However, at this point we need to resolve the issue of gaps when running the agent as a service. It seems that sleeping for one second with `sleep(1)`, actually sleeps for 2 to 4 seconds on my setup. Once we resolve this, the work that remains concerns packaging: ie. installing the binaries at the proper places so that the relevant DLLs are found. To test this PR you need to: - Build the agent: ./packaging/utils/compile-on-windows.sh - Install the files: `ninja -C build/ install` - Copy the main binary: `cp ./build/netdata /usr/bin/` - (Only once) Create the netdata service: `sc.exe config Netdata binPath="C:\msys64\usr\bin\netdata"` - Start the service: `sc.exe start Netdata` A couple notes: - The health and the spawn client have been disabled for the time being. They will be re-enabled once we finish the agent-as-service issue and the packaging. - Last time I checked, the agent crashes after a while when using dbengine. In order to have something that works correctly, you should specify memory-mode ram in your netdata.conf. * Add windows version for sleep_usec_with_now * Split install prefix from runtime prefix These paths are always the same for non-Windows systems. On Windows, RFS is the top-level installation path. With the current setup, Netdata will be installed at C:\msys64\opt\netdata at packaging time. However, the layout of the application means that when the agent starts, it'll look as if everything was installed at /. * Do not use mold linker on Windows. * Use modern UI for installer. * Make the service delayed-auto * Use mutexes instead of spinlocks. * Update service handling logic. * Add proper ifdefs for spinlock implementation. * Initialize analytics spinlock * Add a macro to build the agent as regular cli tool. * Add makensis dependency * Let installer know it's installing Netdata. * Disable pluginsd on Windows When pluginsd is enabled, the agent freezes approximately 20% of the time during startup. * Add service description. * Return pthread_join result * Print tag when we fail to join a thread. * Do not use mutexes instead of spinlocks. * Assorted changes to service/main code. * Rework service functions. With the current implementation we are not getting any MUTEX_LOCK errors and thread joining succeeds. The only case where joining fails is the parallel initialization of dbengine threads, which we can easily avoid by serializing the initialization step. * Rework main functions This will allow someone to run the agent either as a service or as a command-line tool. * Change runtime prefix only when building for packaging. * Install binaries and dlls. * Make netdata claiming through UI work correctly. * Fix netdata path
- Loading branch information
1 parent
a38e6ee
commit e99da8b
Showing
19 changed files
with
615 additions
and
86 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
#!/usr/bin/env bash | ||
|
||
if [ "$#" -lt 1 ]; then | ||
echo "Usage: $0 <command1> <command2> ... <commandN>" | ||
exit 1 | ||
fi | ||
|
||
results=() | ||
|
||
for arg in "$@"; do | ||
while IFS= read -r line; do | ||
results+=("$line") | ||
done < <(ldd "$arg" | grep /usr/bin | awk '{ print $3 }') | ||
done | ||
|
||
printf "%s\n" "${results[@]}" | sort | uniq |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,34 +1,58 @@ | ||
Outfile "netdata-installer.exe" | ||
InstallDir "C:\netdata" | ||
!include "MUI2.nsh" | ||
|
||
Name "Netdata" | ||
Outfile "netdata-installer.exe" | ||
InstallDir "$PROGRAMFILES\netdata" | ||
RequestExecutionLevel admin | ||
|
||
Section | ||
SetOutPath $INSTDIR | ||
WriteUninstaller $INSTDIR\uninstaller.exe | ||
SectionEnd | ||
!define MUI_ABORTWARNING | ||
!define MUI_UNABORTWARNING | ||
|
||
Section "Install MSYS2 environment" | ||
SetOutPath $TEMP | ||
!insertmacro MUI_PAGE_WELCOME | ||
!insertmacro MUI_PAGE_DIRECTORY | ||
!insertmacro MUI_PAGE_INSTFILES | ||
!insertmacro MUI_PAGE_FINISH | ||
|
||
SetCompress off | ||
File "C:\msys64\msys2-installer.exe" | ||
nsExec::ExecToLog 'cmd.exe /C "$TEMP\msys2-installer.exe" in --confirm-command --accept-messages --root $INSTDIR' | ||
!insertmacro MUI_UNPAGE_CONFIRM | ||
!insertmacro MUI_UNPAGE_INSTFILES | ||
!insertmacro MUI_UNPAGE_FINISH | ||
|
||
Delete "$TEMP\msys2-installer.exe" | ||
SectionEnd | ||
|
||
Section "Install MSYS2 packages" | ||
ExecWait '"$INSTDIR\usr\bin\bash.exe" -lc "pacman -S --noconfirm msys/libuv msys/protobuf"' | ||
SectionEnd | ||
!insertmacro MUI_LANGUAGE "English" | ||
|
||
Section "Install Netdata" | ||
SetOutPath $INSTDIR\opt\netdata | ||
|
||
SetOutPath $INSTDIR | ||
SetCompress off | ||
|
||
File /r "C:\msys64\opt\netdata\*.*" | ||
|
||
ClearErrors | ||
ExecWait '"$SYSDIR\sc.exe" create Netdata binPath= "$INSTDIR\usr\bin\netdata.exe" start= delayed-auto' | ||
IfErrors 0 +2 | ||
DetailPrint "Warning: Failed to create Netdata service." | ||
|
||
ClearErrors | ||
ExecWait '"$SYSDIR\sc.exe" description Netdata "Real-time system monitoring service"' | ||
IfErrors 0 +2 | ||
DetailPrint "Warning: Failed to add Netdata service description." | ||
|
||
ClearErrors | ||
ExecWait '"$SYSDIR\sc.exe" start Netdata' | ||
IfErrors 0 +2 | ||
DetailPrint "Warning: Failed to start Netdata service." | ||
|
||
WriteUninstaller "$INSTDIR\Uninstall.exe" | ||
SectionEnd | ||
|
||
Section "Uninstall" | ||
nsExec::ExecToLog 'cmd.exe /C "$INSTDIR\uninstall.exe" pr --confirm-command' | ||
ClearErrors | ||
ExecWait '"$SYSDIR\sc.exe" stop Netdata' | ||
IfErrors 0 +2 | ||
DetailPrint "Warning: Failed to stop Netdata service." | ||
|
||
ClearErrors | ||
ExecWait '"$SYSDIR\sc.exe" delete Netdata' | ||
IfErrors 0 +2 | ||
DetailPrint "Warning: Failed to delete Netdata service." | ||
|
||
RMDir /r "$INSTDIR" | ||
SectionEnd |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.