5353
5454 - name : Publish API
5555 if : ${{ github.event.release.prerelease == false }}
56- run : dotnet publish "MessagingService\MessagingService.csproj" --configuration Release --output publishOutput -r win -x64 --self-contained
56+ run : dotnet publish "MessagingService\MessagingService.csproj" --configuration Release --output publishOutput -r linux -x64 --self-contained
5757
5858 - name : Build Release Package
5959 run : |
7979 dotnet nuget push Nugets/MessagingService.IntegrationTesting.Helpers.${{ steps.get_version.outputs.VERSION }}.nupkg --api-key ${{ secrets.PRIVATEFEED_APIKEY }} --source ${{ secrets.PRIVATEFEED_URL }} --skip-duplicate
8080
8181 deploystaging :
82- runs-on : stagingserver
82+ runs-on : [ stagingserver, linux]
8383 needs : buildlinux
8484 environment : staging
8585 name : " Deploy to Staging"
@@ -88,31 +88,77 @@ jobs:
8888 - name : Download the artifact
89899090 with :
91- name : messagingservice
92-
93- - name : Remove existing Windows service
91+ name : securityservice
92+ path : /tmp/securityservice # Download to a temporary directory
93+
94+ - name : Remove existing service (if applicable)
9495 run : |
95- $serviceName = "Transaction Processing - Messaging Service"
96- # Check if the service exists
97- if (Get-Service -Name $serviceName -ErrorAction SilentlyContinue) {
98- Stop-Service -Name $serviceName
99- sc.exe delete $serviceName
100- }
101-
96+ SERVICE_NAME="securityservice"
97+ if systemctl is-active --quiet "$SERVICE_NAME"; then
98+ echo "Stopping existing service..."
99+ sudo systemctl stop "$SERVICE_NAME"
100+ fi
101+ if systemctl is-enabled --quiet "$SERVICE_NAME"; then
102+ echo "Disabling existing service..."
103+ sudo systemctl disable "$SERVICE_NAME"
104+ fi
105+ if [ -f "/etc/systemd/system/${SERVICE_NAME}.service" ]; then
106+ echo "Removing existing service unit file..."
107+ sudo rm "/etc/systemd/system/${SERVICE_NAME}.service"
108+ sudo systemctl daemon-reload
109+ fi
110+
102111 - name : Unzip the files
103112 run : |
104- Expand-Archive -Path messagingservice.zip -DestinationPath "C:\txnproc\transactionprocessing\messagingservice" -Force
105-
106- - name : Install as a Windows service
113+ sudo mkdir -p /opt/txnproc/transactionprocessing/securityservice
114+ sudo unzip -o /tmp/securityservice/securityservice.zip -d /opt/txnproc/transactionprocessing/securityservice
115+
116+ # IMPORTANT: Add a step to ensure the .NET runtime is installed on the server
117+ # This assumes it's not already there. If your base image already has it, you can skip this.
118+ - name : Install .NET Runtime
119+ run : |
120+ # Example for Ubuntu. Adjust based on your .NET version (e.g., 8.0, 7.0)
121+ # and if you need the SDK or just the runtime.
122+ # This uses Microsoft's package repository for the latest versions.
123+ wget https://packages.microsoft.com/config/ubuntu/$(lsb_release -rs)/packages-microsoft-prod.deb -O packages-microsoft-prod.deb
124+ sudo dpkg -i packages-microsoft-prod.deb
125+ rm packages-microsoft-prod.deb
126+ sudo apt update
127+ sudo apt install -y aspnetcore-runtime-9.0
128+
129+ - name : Install and Start as a Linux service
107130 run : |
108- $serviceName = "Transaction Processing - Messaging Service"
109- $servicePath = "C:\txnproc\transactionprocessing\messagingservice\MessagingService.exe"
110-
111- New-Service -Name $serviceName -BinaryPathName $servicePath -Description "Transaction Processing - Messaging Service" -DisplayName "Transaction Processing - Messaging Service" -StartupType Automatic
112- Start-Service -Name $serviceName
131+ SERVICE_NAME="securityservice"
132+ # The WorkingDirectory is crucial for .NET apps to find appsettings.json and other files
133+ WORKING_DIRECTORY="/opt/txnproc/transactionprocessing/securityservice"
134+ DLL_NAME="SecurityService.dll" # Your application's DLL
135+ SERVICE_DESCRIPTION="Transaction Processing - Security Service"
136+
137+ # Create a systemd service file
138+ echo "[Unit]" | sudo tee /etc/systemd/system/${SERVICE_NAME}.service
139+ echo "Description=${SERVICE_DESCRIPTION}" | sudo tee -a /etc/systemd/system/${SERVICE_NAME}.service
140+ echo "After=network.target" | sudo tee -a /etc/systemd/system/${SERVICE_NAME}.service
141+ echo "" | sudo tee -a /etc/systemd/system/${SERVICE_NAME}.service
142+ echo "[Service]" | sudo tee -a /etc/systemd/system/${SERVICE_NAME}.service
143+ # IMPORTANT: Use 'dotnet' to run your DLL
144+ echo "ExecStart=/usr/bin/dotnet ${WORKING_DIRECTORY}/${DLL_NAME}" | sudo tee -a /etc/systemd/system/${SERVICE_NAME}.service
145+ echo "WorkingDirectory=${WORKING_DIRECTORY}" | sudo tee -a /etc/systemd/system/${SERVICE_NAME}.service
146+ echo "Restart=always" | sudo tee -a /etc/systemd/system/${SERVICE_NAME}.service
147+ echo "User=youruser" # IMPORTANT: Change to a dedicated, less privileged user
148+ echo "Group=yourgroup" # IMPORTANT: Change to a dedicated, less privileged group
149+ echo "Environment=ASPNETCORE_ENVIRONMENT=Production" | sudo tee -a /etc/systemd/system/${SERVICE_NAME}.service # Example
150+ echo "" | sudo tee -a /etc/systemd/system/${SERVICE_NAME}.service
151+ echo "[Install]" | sudo tee -a /etc/systemd/system/${SERVICE_NAME}.service
152+ echo "WantedBy=multi-user.target" | sudo tee -a /etc/systemd/system/${SERVICE_NAME}.service
153+
154+ # Reload systemd, enable, and start the service
155+ sudo systemctl daemon-reload
156+ sudo systemctl enable "$SERVICE_NAME"
157+ sudo systemctl start "$SERVICE_NAME"
158+ sudo systemctl status "$SERVICE_NAME" --no-pager # For debugging/verification
113159
114160 deployproduction :
115- runs-on : productionserver
161+ runs-on : [ productionserver, linux]
116162 needs : [buildlinux, deploystaging]
117163 environment : production
118164 name : " Deploy to Production"
@@ -121,25 +167,71 @@ jobs:
121167 - name : Download the artifact
122168123169 with :
124- name : messagingservice
125-
126- - name : Remove existing Windows service
170+ name : securityservice
171+ path : /tmp/securityservice # Download to a temporary directory
172+
173+ - name : Remove existing service (if applicable)
127174 run : |
128- $serviceName = "Transaction Processing - Messaging Service"
129- # Check if the service exists
130- if (Get-Service -Name $serviceName -ErrorAction SilentlyContinue) {
131- Stop-Service -Name $serviceName
132- sc.exe delete $serviceName
133- }
134-
175+ SERVICE_NAME="securityservice"
176+ if systemctl is-active --quiet "$SERVICE_NAME"; then
177+ echo "Stopping existing service..."
178+ sudo systemctl stop "$SERVICE_NAME"
179+ fi
180+ if systemctl is-enabled --quiet "$SERVICE_NAME"; then
181+ echo "Disabling existing service..."
182+ sudo systemctl disable "$SERVICE_NAME"
183+ fi
184+ if [ -f "/etc/systemd/system/${SERVICE_NAME}.service" ]; then
185+ echo "Removing existing service unit file..."
186+ sudo rm "/etc/systemd/system/${SERVICE_NAME}.service"
187+ sudo systemctl daemon-reload
188+ fi
189+
135190 - name : Unzip the files
136191 run : |
137- Expand-Archive -Path messagingservice.zip -DestinationPath "C:\txnproc\transactionprocessing\messagingservice" -Force
138-
139- - name : Install as a Windows service
192+ sudo mkdir -p /opt/txnproc/transactionprocessing/securityservice
193+ sudo unzip -o /tmp/securityservice/securityservice.zip -d /opt/txnproc/transactionprocessing/securityservice
194+
195+ # IMPORTANT: Add a step to ensure the .NET runtime is installed on the server
196+ # This assumes it's not already there. If your base image already has it, you can skip this.
197+ - name : Install .NET Runtime
198+ run : |
199+ # Example for Ubuntu. Adjust based on your .NET version (e.g., 8.0, 7.0)
200+ # and if you need the SDK or just the runtime.
201+ # This uses Microsoft's package repository for the latest versions.
202+ wget https://packages.microsoft.com/config/ubuntu/$(lsb_release -rs)/packages-microsoft-prod.deb -O packages-microsoft-prod.deb
203+ sudo dpkg -i packages-microsoft-prod.deb
204+ rm packages-microsoft-prod.deb
205+ sudo apt update
206+ sudo apt install -y aspnetcore-runtime-9.0
207+
208+ - name : Install and Start as a Linux service
140209 run : |
141- $serviceName = "Transaction Processing - Messaging Service"
142- $servicePath = "C:\txnproc\transactionprocessing\messagingservice\MessagingService.exe"
143-
144- New-Service -Name $serviceName -BinaryPathName $servicePath -Description "Transaction Processing - Messaging Service" -DisplayName "Transaction Processing - Messaging Service" -StartupType Automatic
145- Start-Service -Name $serviceName
210+ SERVICE_NAME="securityservice"
211+ # The WorkingDirectory is crucial for .NET apps to find appsettings.json and other files
212+ WORKING_DIRECTORY="/opt/txnproc/transactionprocessing/securityservice"
213+ DLL_NAME="SecurityService.dll" # Your application's DLL
214+ SERVICE_DESCRIPTION="Transaction Processing - Security Service"
215+
216+ # Create a systemd service file
217+ echo "[Unit]" | sudo tee /etc/systemd/system/${SERVICE_NAME}.service
218+ echo "Description=${SERVICE_DESCRIPTION}" | sudo tee -a /etc/systemd/system/${SERVICE_NAME}.service
219+ echo "After=network.target" | sudo tee -a /etc/systemd/system/${SERVICE_NAME}.service
220+ echo "" | sudo tee -a /etc/systemd/system/${SERVICE_NAME}.service
221+ echo "[Service]" | sudo tee -a /etc/systemd/system/${SERVICE_NAME}.service
222+ # IMPORTANT: Use 'dotnet' to run your DLL
223+ echo "ExecStart=/usr/bin/dotnet ${WORKING_DIRECTORY}/${DLL_NAME}" | sudo tee -a /etc/systemd/system/${SERVICE_NAME}.service
224+ echo "WorkingDirectory=${WORKING_DIRECTORY}" | sudo tee -a /etc/systemd/system/${SERVICE_NAME}.service
225+ echo "Restart=always" | sudo tee -a /etc/systemd/system/${SERVICE_NAME}.service
226+ echo "User=youruser" # IMPORTANT: Change to a dedicated, less privileged user
227+ echo "Group=yourgroup" # IMPORTANT: Change to a dedicated, less privileged group
228+ echo "Environment=ASPNETCORE_ENVIRONMENT=Production" | sudo tee -a /etc/systemd/system/${SERVICE_NAME}.service # Example
229+ echo "" | sudo tee -a /etc/systemd/system/${SERVICE_NAME}.service
230+ echo "[Install]" | sudo tee -a /etc/systemd/system/${SERVICE_NAME}.service
231+ echo "WantedBy=multi-user.target" | sudo tee -a /etc/systemd/system/${SERVICE_NAME}.service
232+
233+ # Reload systemd, enable, and start the service
234+ sudo systemctl daemon-reload
235+ sudo systemctl enable "$SERVICE_NAME"
236+ sudo systemctl start "$SERVICE_NAME"
237+ sudo systemctl status "$SERVICE_NAME" --no-pager # For debugging/verification
0 commit comments