Skip to content

Commit

Permalink
bugfix & feat: CWD of the Windows Service and delete svc if it alread…
Browse files Browse the repository at this point in the history
…y exists

Change the working directory of the service to the root directory
of the application so that poetry can run.

Delete the service if it already exists
  • Loading branch information
gshiva committed Dec 27, 2023
1 parent aa19e8d commit 8e4510a
Showing 1 changed file with 20 additions and 1 deletion.
21 changes: 20 additions & 1 deletion .github/workflows/cd.yml
Original file line number Diff line number Diff line change
Expand Up @@ -58,5 +58,24 @@ jobs:
- name: Setup Windows Service (Windows Only)
if: runner.os == 'Windows' && success()
run: |
New-Service -Name "pygptcourse" -BinaryPathName "poetry run python ${{ github.workspace }}/src/pygptcourse/main.py"
$ServiceName = "PyGPTCourseService"
$WorkingDir = "${{ github.workspace }}"
$AppPath = "src\pygptcourse\main.py"
$PoetryPath = "poetry.exe"
$ServiceCommand = "powershell.exe -Command `"cd $WorkingDir; & $PoetryPath run python $AppPath`""
# Check if the service exists and delete it if so
$service = Get-Service -Name $ServiceName -ErrorAction SilentlyContinue
if ($service) {
Write-Output "Service $ServiceName exists. Deleting..."
sc.exe delete $ServiceName
# Optional: Wait for the service to be fully deleted
while (Get-Service -Name $ServiceName -ErrorAction SilentlyContinue) {
Start-Sleep -Seconds 2
}
}
# Create the service using sc.exe
sc.exe create $ServiceName binPath= $ServiceCommand start= auto
sc.exe start $ServiceName
shell: pwsh

0 comments on commit 8e4510a

Please sign in to comment.