The HostAgent is a cross-platform service that can run as:
- Windows Service on Windows
- systemd daemon on Linux
- Console application for development/debugging
# Build for current platform
dotnet build src/Linksoft.PowerController.HostAgent
# Publish self-contained executable
dotnet publish src/Linksoft.PowerController.HostAgent -c Release -o ./publishThe HostAgent is configured via appsettings.json:
{
"Mqtt": {
"Enabled": false,
"Mode": "External",
"External": {
"Host": "localhost",
"Port": 1883,
"UseTls": false
},
"Embedded": {
"Port": 1883
},
"Topics": {
"BaseTopic": "powercontroller",
"StatusInterval": 30
}
}
}- External: Connect to an existing MQTT broker
- Embedded: Run a built-in MQTT broker (set
Modeto"Embedded")
dotnet run --project src/Linksoft.PowerController.HostAgentThe application will run in the foreground and can be stopped with Ctrl+C.
- Windows 10/11 or Windows Server 2016+
- Administrator privileges
-
Publish the application:
dotnet publish src/Linksoft.PowerController.HostAgent -c Release -o C:\Services\LinksoftPowerController
-
Create the Windows Service:
sc.exe create "LinksoftPowerController" ` binPath="C:\Services\LinksoftPowerController\Linksoft.PowerController.HostAgent.exe" ` start=auto ` displayname="Linksoft Power Controller"
-
Set service description (optional):
sc.exe description "LinksoftPowerController" "IoT Power Controller Host Agent - manages remote power control via REST API and MQTT"
-
Start the service:
sc.exe start "LinksoftPowerController"
# Check status
sc.exe query "LinksoftPowerController"
# Stop service
sc.exe stop "LinksoftPowerController"
# Remove service
sc.exe delete "LinksoftPowerController"Logs are written to logs/hostagent-YYYYMMDD.log in the application directory.
- Linux with systemd (Ubuntu 18.04+, Debian 10+, RHEL 8+, etc.)
- .NET Runtime 10.0 or self-contained publish
-
Publish the application:
dotnet publish src/Linksoft.PowerController.HostAgent -c Release -o /opt/linksoft/powercontroller
-
Set permissions:
sudo chmod +x /opt/linksoft/powercontroller/Linksoft.PowerController.HostAgent
-
Create systemd service file:
sudo nano /etc/systemd/system/linksoft-powercontroller.service
Add the following content:
[Unit] Description=Linksoft Power Controller Host Agent Documentation=https://github.com/Linksoft/Linksoft.IoT.PowerController After=network.target [Service] Type=notify ExecStart=/opt/linksoft/powercontroller/Linksoft.PowerController.HostAgent WorkingDirectory=/opt/linksoft/powercontroller Restart=always RestartSec=10 User=root Environment=DOTNET_ENVIRONMENT=Production Environment=ASPNETCORE_URLS=http://*:5000 [Install] WantedBy=multi-user.target
-
Enable and start the service:
sudo systemctl daemon-reload sudo systemctl enable linksoft-powercontroller sudo systemctl start linksoft-powercontroller
# Check status
sudo systemctl status linksoft-powercontroller
# View logs
sudo journalctl -u linksoft-powercontroller -f
# Stop service
sudo systemctl stop linksoft-powercontroller
# Restart service
sudo systemctl restart linksoft-powercontroller
# Disable service
sudo systemctl disable linksoft-powercontroller- File logs:
/opt/linksoft/powercontroller/logs/hostagent-YYYYMMDD.log - Journal logs:
journalctl -u linksoft-powercontroller
Once running, the HostAgent exposes:
| Endpoint | Method | Description |
|---|---|---|
/system/info |
GET | Get system information (uptime, hostname, shutdown status) |
/system/shutdown |
POST | Initiate shutdown (modes: Immediate, Delayed, Scheduled) |
/scalar/v1 |
GET | Interactive API documentation |
New-NetFirewallRule -DisplayName "Linksoft Power Controller" -Direction Inbound -Port 5000 -Protocol TCP -Action Allowsudo ufw allow 5000/tcp- Check logs in the
logs/directory - Verify
appsettings.jsonis valid JSON - Ensure the port (default 5000) is not in use
- Verify broker is reachable:
telnet <host> 1883 - Check MQTT configuration in
appsettings.json - Review logs for connection errors
Ensure the service has appropriate permissions:
sudo chown -R root:root /opt/linksoft/powercontroller
sudo chmod +x /opt/linksoft/powercontroller/Linksoft.PowerController.HostAgent