Skip to content
Petkir Blog
XLinkedinBluesky

The Christkind's - Deployment Dilemma

Code, Azure, Xmas20243 min read

Story

As the time for deployment approached, the Christkind was filled with excitement. After tirelessly working on the .NET 8 application, it was finally ready to be deployed on the server. However, as the Christkind began the deployment process, a wave of realization washed over it.

Oh no! The Christkind had made a little mistake. Instead of deploying on a Windows server, it was actually a Linux server equipped with Samba. Everything that had been meticulously planned and coded for a Windows environment was now irrelevant. Panic set in for a moment, as it stared at the console with a mix of confusion and concern.

But then, a spark of inspiration hit the Christkind. The beauty of the .NET solution was its cross-platform capability. The adjustments needed wouldn’t require a complete overhaul.

With newfound determination, the Christkind dove into the code, making the necessary changes to ensure compatibility with the Linux environment. It quickly updated paths, reconfigured services, and tested everything thoroughly.

"This is why I love .NET!" the Christkind exclaimed. The ease of making changes and the ability to adapt quickly saved the day. As the deployment progressed smoothly, the Christkind felt a surge of confidence and joy.

By embracing the flexibility of the .NET platform, the Christkind not only salvaged the situation but also gained a deeper appreciation for the power of cross-platform development. The deployment turned out to be a success, and with every adjustment, the Christkind became more adept at navigating the technical landscape.

With everything in place, the Christkind was now ready to focus on what truly mattered: spreading joy and excitement to children all over the world on Christmas Eve!

Bring the Service to Linux

Create a systemd Service File

Create the Service File: Use your preferred text editor to create a new service file for systemd:

sudo nano /etc/systemd/system/filewatcher.service

Insert the following content into the file (ensure you update the paths and user as necessary):

[Unit]
Description=File Watcher Service
After=network.target
[Service]
ExecStart=/usr/bin/dotnet /path/to/your/publish/FileWatcherService.dll
WorkingDirectory=/path/to/your/publish
Restart=always
RestartSec=10
SyslogIdentifier=filewatcher
User=your_username
Environment=ASPNETCORE_ENVIRONMENT=Production
[Install]
WantedBy=multi-user.target

Make sure to replace /path/to/your/publish with the actual path to your published binaries and your_username with your actual user name.

Save and Exit: Save the file and exit the editor (e.g., in nano, press Ctrl + X, then Y, and Enter).

Step 4: Enable and Start the Service

Reload the systemd Daemon: After creating the service file, reload the systemd daemon to recognize the new service:

sudo systemctl daemon-reload

Enable the Service: To ensure the service starts on boot, run:

sudo systemctl enable filewatcher.service

Start the Service: Now, start the service with:

sudo systemctl start filewatcher.service

Step 5: Verify the Service

Check the Service Status: To check if your service is running correctly, you can use:

sudo systemctl status filewatcher.service

This command will provide details about the service status, including any errors if it failed to start.

  1. View Logs: Use the journalctl command to view logs related to your service:
journalctl -u filewatcher.service -f

Remark

Running C# on Linux is surprisingly straightforward, isn't it?

Links

XMAS 2024 Overview