Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 16 additions & 3 deletions build/windows/Makefile.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
# 1. Builds the certificate generator code in .NET and copy the binaries in zip file to ..\..\kubernetes\windows\omsagentwindows
# 2. Builds the out_oms plugin code in go lang into the shared object(.so) file and copy the out_oms.so file to ..\..\kubernetes\windows\omsagentwindows
# 3. copy the files under installer directory to ..\..\kubernetes\windows\omsagentwindows
# 4. Builds the livenessprobe cpp and copy the executable to the under directory ..\..\kubernetes\windows\omsagentwindows

$dotnetcoreframework = "netcoreapp3.1"

Expand Down Expand Up @@ -157,7 +158,7 @@ if ($isCDPxEnvironment) {

Write-Host("getting latest go modules ...")
go get
Write-Host("successfyullt got latest go modules") -ForegroundColor Green
Write-Host("successfully got latest go modules") -ForegroundColor Green

go build -ldflags "-X 'main.revision=$buildVersionString' -X 'main.builddate=$buildVersionDate'" -buildmode=c-shared -o out_oms.so .
}
Expand All @@ -167,16 +168,28 @@ Write-Host("copying out_oms.so file to : $publishdir")
Copy-Item -Path (Join-path -Path $outomsgoplugindir -ChildPath "out_oms.so") -Destination $publishdir -Force
Write-Host("successfully copied out_oms.so file to : $publishdir") -ForegroundColor Green

# compile and build the liveness probe cpp code
Write-Host("Start:build livenessprobe cpp code")
$livenessprobesrcpath = Join-Path -Path $builddir -ChildPath "windows\installer\livenessprobe\livenessprobe.cpp"
$livenessprobeexepath = Join-Path -Path $builddir -ChildPath "windows\installer\livenessprobe\livenessprobe.exe"
g++ $livenessprobesrcpath -o $livenessprobeexepath -municode
Write-Host("End:build livenessprobe cpp code")
if (Test-Path -Path $livenessprobeexepath){
Write-Host("livenessprobe.exe exists which indicates cpp build step succeeded") -ForegroundColor Green
} else {
Write-Host("livenessprobe.exe doesnt exist which indicates cpp build step failed") -ForegroundColor Red
exit
}

$installerdir = Join-Path -Path $builddir -ChildPath "common\installer"
Write-Host("copying common installer files conf and scripts from :" + $installerdir + " to :" + $publishdir + " ...")
$exclude = @('*.cs','*.csproj')
$exclude = @('*.cs','*.csproj', '*.cpp')
Copy-Item -Path $installerdir -Destination $publishdir -Recurse -Force -Exclude $exclude
Write-Host("successfully copied installer files conf and scripts from :" + $installerdir + " to :" + $publishdir + " ") -ForegroundColor Green

$installerdir = Join-Path -Path $builddir -ChildPath "windows\installer"
Write-Host("copying installer files conf and scripts from :" + $installerdir + " to :" + $publishdir + " ...")
$exclude = @('*.cs','*.csproj')
$exclude = @('*.cs','*.csproj', '*.cpp')
Copy-Item -Path $installerdir -Destination $publishdir -Recurse -Force -Exclude $exclude
Write-Host("successfully copied installer files conf and scripts from :" + $installerdir + " to :" + $publishdir + " ") -ForegroundColor Green

Expand Down
137 changes: 137 additions & 0 deletions build/windows/installer/livenessprobe/livenessprobe.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,137 @@
#ifndef UNICODE
#define UNICODE
#endif

#ifndef _UNICODE
#define _UNICODE
#endif

#include <Windows.h>
#include <tlhelp32.h>
#include <tchar.h>

#define SUCCESS 0x00000000
#define NO_FLUENT_BIT_PROCESS 0x00000001
#define FILESYSTEM_WATCHER_FILE_EXISTS 0x00000002
#define CERTIFICATE_RENEWAL_REQUIRED 0x00000003
#define FLUENTDWINAKS_SERVICE_NOT_RUNNING 0x00000004
#define UNEXPECTED_ERROR 0xFFFFFFFF

/*
check if the process running or not for given exe file name
*/
bool IsProcessRunning(const wchar_t *const executableName)
{
PROCESSENTRY32 entry;
entry.dwSize = sizeof(PROCESSENTRY32);

const auto snapshot = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, NULL);

if (!Process32First(snapshot, &entry))
{
CloseHandle(snapshot);
wprintf_s(L"ERROR:IsProcessRunning::Process32First failed");
return false;
}

do
{
if (!_wcsicmp(entry.szExeFile, executableName))
{
CloseHandle(snapshot);
return true;
}
} while (Process32Next(snapshot, &entry));

CloseHandle(snapshot);
return false;
}

/*
check if the file exists
*/
bool IsFileExists(const wchar_t *const fileName)
{
DWORD dwAttrib = GetFileAttributes(fileName);
return dwAttrib != INVALID_FILE_SIZE;
}

/*
Get the status of the service for given service name
*/
int GetServiceStatus(const wchar_t *const serivceName)
{
SC_HANDLE theService, scm;
SERVICE_STATUS_PROCESS ssStatus;
DWORD dwBytesNeeded;

scm = OpenSCManager(nullptr, nullptr, SC_MANAGER_ENUMERATE_SERVICE);
if (!scm)
{
wprintf_s(L"ERROR:GetServiceStatus::OpenSCManager failed");
return UNEXPECTED_ERROR;
}

theService = OpenService(scm, serivceName, SERVICE_QUERY_STATUS);
if (!theService)
{
CloseServiceHandle(scm);
wprintf_s(L"ERROR:GetServiceStatus::OpenService failed");
return UNEXPECTED_ERROR;
}

auto result = QueryServiceStatusEx(theService, SC_STATUS_PROCESS_INFO,
reinterpret_cast<LPBYTE>(&ssStatus), sizeof(SERVICE_STATUS_PROCESS),
&dwBytesNeeded);

CloseServiceHandle(theService);
CloseServiceHandle(scm);

if (result == 0)
{
wprintf_s(L"ERROR:GetServiceStatus:QueryServiceStatusEx failed");
return UNEXPECTED_ERROR;
}

return ssStatus.dwCurrentState;
}

/**
<exe> <servicename> <filesystemwatcherfilepath> <certificaterenewalpath>
**/
int _tmain(int argc, wchar_t *argv[])
{
if (argc < 5)
{
wprintf_s(L"ERROR:unexpected number arguments and expected is 5");
return UNEXPECTED_ERROR;
}

if (!IsProcessRunning(argv[1]))
{
wprintf_s(L"ERROR:Process:%s is not running\n", argv[1]);
return NO_FLUENT_BIT_PROCESS;
}

DWORD dwStatus = GetServiceStatus(argv[2]);

if (dwStatus != SERVICE_RUNNING)
{
wprintf_s(L"ERROR:Service:%s is not running\n", argv[2]);
return FLUENTDWINAKS_SERVICE_NOT_RUNNING;
}

if (IsFileExists(argv[3]))
{
wprintf_s(L"INFO:File:%s exists indicates Config Map Updated since agent started.\n", argv[3]);
return FILESYSTEM_WATCHER_FILE_EXISTS;
}

if (IsFileExists(argv[4]))
{
wprintf_s(L"INFO:File:%s exists indicates Certificate needs to be renewed.\n", argv[4]);
return CERTIFICATE_RENEWAL_REQUIRED;
}

return SUCCESS;
}
36 changes: 0 additions & 36 deletions build/windows/installer/scripts/livenessprobe.cmd

This file was deleted.

6 changes: 5 additions & 1 deletion kubernetes/omsagent.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -833,7 +833,11 @@ spec:
command:
- cmd
- /c
- C:\opt\omsagentwindows\scripts\cmd\livenessProbe.cmd
- C:\opt\omsagentwindows\scripts\cmd\livenessprobe.exe
- fluent-bit.exe
- fluentdwinaks
- "C:\\etc\\omsagentwindows\\filesystemwatcher.txt"
- "C:\\etc\\omsagentwindows\\renewcertificate.txt"
periodSeconds: 60
initialDelaySeconds: 180
timeoutSeconds: 15
Expand Down
2 changes: 1 addition & 1 deletion kubernetes/windows/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ RUN ./setup.ps1

COPY main.ps1 /opt/omsagentwindows/scripts/powershell
COPY ./omsagentwindows/installer/scripts/filesystemwatcher.ps1 /opt/omsagentwindows/scripts/powershell
COPY ./omsagentwindows/installer/scripts/livenessprobe.cmd /opt/omsagentwindows/scripts/cmd/
COPY ./omsagentwindows/installer/livenessprobe/livenessprobe.exe /opt/omsagentwindows/scripts/cmd/
COPY setdefaulttelegrafenvvariables.ps1 /opt/omsagentwindows/scripts/powershell

# copy ruby scripts to /opt folder
Expand Down