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