How do I start a MonoDevelop software program as a system service on Windows, Linux, and Mac? Windows appears to not have a system service setting. I have a WCF service that essentially runs from command line. Even if I have to run from command line, I will need to be able to start the command line server on startup.

Apologies for the weird tech, all you have to do is compile MonoDevelop for windows as per the instructions, and when you have a good WCF service you need to remember to set up the project as conventional command line until we can figure out how to run as service.

I am going to have overloads for this service on all those flavors, but linux and windows is most pressing.

billie01579 commented: I go through this same issue +0

Dani AI

Generated

If your WCF host already runs as a console app, the most portable approach is to keep that host and let each OS start it at boot. On Windows, that means a Windows Service; on Linux, a systemd service; on macOS, a launchd job. ’s TopShelf tip is solid if you want your console host to behave like a service without writing ServiceBase boilerplate. TopShelf also runs under Mono; its install/uninstall helpers are Windows-only, so on Linux/macOS you still run the console under the platform’s service manager. (topshelf.readthedocs.io)

Windows (Service Control Manager):

sc.exe create MyWcfSvc binpath= "C:\path\MyWcf.exe" start= auto
sc.exe start MyWcfSvc

That registers and starts your executable as a service. You can set recovery options and descriptions with other sc.exe subcommands. (learn.microsoft.com)

Linux (systemd):

# /etc/systemd/system/mywcf.service
[Unit]
Description=My WCF host
After=network.target

[Service]
ExecStart=/usr/bin/mono /opt/myapp/MyWcf.exe
Restart=on-failure

[Install]
WantedBy=multi-user.target

Then enable and start:

sudo systemctl enable --now mywcf.service

This gives you proper logging and restarts; systemd stops services with SIGTERM first, so be sure your host shuts down cleanly. ()

macOS (launchd, system-wide):

# /Library/LaunchDaemons/com.example.mywcf.plist
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0"><dict>
  <key>Label</key><string>com.example.mywcf</string>
  <key>ProgramArguments</key>
  <array><string>/usr/local/bin/mono</string><string>/opt/myapp/MyWcf.exe</string></array>
  <key>RunAtLoad</key><true/>
  <key>KeepAlive</key><true/>
</dict></plist>

Load and enable:

sudo launchctl bootstrap system /Library/LaunchDaemons/com.example.mywcf.plist
sudo launchctl enable system/com.example.mywcf

Folders and tooling are documented in Apple’s Terminal User Guide. (support.apple.com)

Notes:

  • If you prefer Windows-style ServiceBase on Linux, mono-service can host it directly. (mankier.com)
  • asked about tech choice: if you ever migrate off Mono, server-side WCF isn’t part of modern .NET; consider CoreWCF or gRPC instead. (learn.microsoft.com)

Recommended Answers

All 3 Replies

The more I read https://www.mono-project.com/docs/web/wcf/ the more I thought I would never use this. Why not just use Visual Studio (a free version) and then for Linux do what you must there?

Also, is the service so specific it can't be done in the usual other languages? As in JAVA.

Have a look at a library called TopShelf. They have managed to quiet elegantly abstract all the service nuances out into a friendly interface.

Why the down vote?

commented: I didn't do it. +15
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.