Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to create a Windows service for Mac OS X?

Tags:

macos

service

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

I would like to create a service to execute a task automatically, and starting and stopping it on demand.

like image 638
willyMon Avatar asked Nov 18 '11 22:11

willyMon


People also ask

How do I create a service in macOS X?

To create a service workflow that runs a script Launch Automator, found in /Applications/ . Create a new Automator document. When prompted, choose a document type of Service and click Choose. At the top of the Automator document, configure the service.

How do I support Microsoft Windows applications on OSX?

To run Windows in a virtual machine within macOS, use Parallels Desktop , VMware Fusion , or VirtualBox . This method will allow you to run Mac and Windows applications concurrently, though the virtual machine does not support as much Windows functionality as a dual-boot configuration.


2 Answers

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

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

  • /Library/LaunchAgents: Per-user agents provided by the administrator.

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

  • /System/Library/LaunchAgents: Per-user agents provided by Mac OS X.

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

A daemon is a system-wide service of which there is one instance for all clients. An agent is a service that runs on a per-user basis.

Configuration files are in the form of a property list.

The syntax is simple but it's easy to get it wrong. The Wikipedia article has a good summary of the options if the man page is not to your liking.

Essentially, what you do is install your actual command-line tool (your service) somewhere and then create a launchd configuration plist and place it in one of the above locations. You can configure the plist so that launchd runs your service at launch or periodically, or in response to various actions (such as the contents of a folder changing).

There is a good in-depth article here.

like image 88
Rob Keniger Avatar answered Sep 24 '22 19:09

Rob Keniger


You should take a look at launchd, you can do a lot of nifty stuff with it. For instance, steam has told launchd that whenever steam is deleted, run steam_delete helper tool. This helper tool helps you in uninstalling steam completely from your system.

Others include the auto update mechanism of google chrome on OS X.

A link to help you get started: Devdaily launchd examples

like image 29
Antwan van Houdt Avatar answered Sep 22 '22 19:09

Antwan van Houdt