Background service on MacOS

Hi, I'm working on an application on MacOS. It contains a port-forward feature on TCP protocol.

This application has no UI, but a local HTTP server where user can access to configure this application.

I found that my application always exit for unknown purpose after running in backgruond for minutes. I think this is about MacOS's background process controlling.

Source codes and PKG installers are here: https://github.com/burningtnt/Terracotta/actions/runs/16494390417

First a word on terminology:

I'm working on an application on MacOS.

In the context of macOS when we say application (or app) we mean something that’s double clickable in the Finder, shows up in the Dock, has a menu bar, and so on. Your product doesn’t do that, so it’s not an app.

There are a variety of other ways to run programs on the Mac, including command-line tools, launchd daemons, launchd agents, and login items. And programs without UIs can still use app-like packaging, resulting in a background-only app or a UI element.

The best path forward here depends on two criteria:

  • What is the desired lifecycle of your program?
  • How do you want to managed install and uninstall?

The first one is key. Do your want your program to run all the time? Automatically for each user who logs in? Or only when the user explicitly starts it, with the implication being that it stops when the user logs out?

Most network-facing programs want to run all the time, with just a single instance of the running program, and thus are usually run as a launchd daemon. Is that what you’re looking for?

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"

In the context of macOS when we say application (or app) we mean something that’s double clickable in the Finder, shows up in the Dock, has a menu bar, and so on. Your product doesn’t do that, so it’s not an app.

How do you want to managed install and uninstall?

I've made this Rust application being packed in to a PKG installer, which installs a valid terracotta.app bundle to Application dir. Therefore, Users can run this application by cdouble clicking the icon in Finder and it will show up in the dock. So, THIS IS A APPLICATION.

What is the desired lifecycle of your program?

I want to make my program being runned in background ONLY AFTER users manually launch the application. Therefore, their won't be much performance waste when my application hasn't being launched since the computer start. And the application will exit and no longer running in the background if certain condition is met, for example, there's no traffic for the application on the port-forward feature. (Of course, there will be a pop-up or other kinds of notification.)

Or, if this expectation cannot be fulfilled, constantly running in the background is acceptable.

Background service on MacOS
 
 
Q