How to create a Windows service for Mac OS X?

On Windows, you can create an application that can be installed as a service. This type of application is called the Windows service. What would be the equivalent of services on Mac OS X? How are they implemented and where to start learning about it?

I would like to create a service to perform a task automatically and start it and stop it on demand.

+6
source share
2 answers

You need to make friends with launchd . You need to create launchd configuration files that are located in one of five locations:

  • ~/Library/LaunchAgents : user agents provided by the user.

  • /Library/LaunchAgents : agents for each user provided by the administrator.

  • /Library/LaunchDaemons : System-wide daemons provided by the administrator.

  • /System/Library/LaunchAgents : Agents for each user provided by Mac OS X.

  • /System/Library/LaunchDaemons : System-wide daemons provided by Mac OS X.

A daemon is a system-wide service for which there is one instance for all clients. Agent - This is a service that runs for each user.

The configuration files are in the form of a list of properties .

The syntax is simple but easy to make mistakes. The Wikipedia article provides a good summary of options if the man page is not to your liking.

Essentially, what you do is install somewhere the actual command line tool (your service), and then create the launchd configuration plan and put it in one of the above locations. You can configure plist so that launchd starts your service at startup, either periodically or in response to various actions (for example, the contents of a folder).

There is a good in-depth article here.

+9
source

You should take a look at launchd , you can do a lot of great things with it. For example, steam told launchd that whenever steam is removed, run the steam_delete helper tool. This auxiliary tool helps you to completely remove steam from your system.

Others include google chrome auto-update mechanism on OS X.

Link to help you get started: Devdaily startd examples

+4
source

Source: https://habr.com/ru/post/901852/


All Articles