m (→The plist) |
m (→The plist: Moved Type columns) |
||
Line 22: | Line 22: | ||
|- | |- | ||
! Key | ! Key | ||
! Type | |||
! Description | ! Description | ||
! Note | ! Note | ||
|- | |- | ||
| Label | | Label | ||
| String | |||
| Unique identifier for your daemon | | Unique identifier for your daemon | ||
| --- | | --- | ||
|- | |- | ||
| Program | | Program | ||
| String | |||
| This key maps to the first argument of execvp(3). If missing, the first Argument of ProgramArguments is used. | | This key maps to the first argument of execvp(3). If missing, the first Argument of ProgramArguments is used. | ||
| Only required in absense of '''ProgramArguments''' key | | Only required in absense of '''ProgramArguments''' key | ||
|- | |- | ||
| ProgramArguments | | ProgramArguments | ||
| Array of Strings | |||
| This key maps to the second argument of execvp(3). If missing, the Program key is used. | | This key maps to the second argument of execvp(3). If missing, the Program key is used. | ||
| Only required in absense of '''Program''' key | | Only required in absense of '''Program''' key | ||
|} | |} | ||
Line 47: | Line 47: | ||
|- | |- | ||
! Key | ! Key | ||
! Type | |||
! Description | ! Description | ||
|- | |- | ||
| UserName | | UserName | ||
| String | |||
| Specifies the user to run the job as | | Specifies the user to run the job as | ||
|- | |- | ||
| GroupName | | GroupName | ||
| String | |||
| Specifies the group to run the job as | | Specifies the group to run the job as | ||
|} | |} | ||
Line 64: | Line 64: | ||
|- | |- | ||
! Key | ! Key | ||
! Type | |||
! Description | ! Description | ||
|- | |- | ||
| RunAtLoad | | RunAtLoad | ||
| Boolean | |||
| Controls whether your job is launched at boot time (when launchd launches) or not. | | Controls whether your job is launched at boot time (when launchd launches) or not. | ||
|- | |- | ||
| LaunchOnlyOnce | | LaunchOnlyOnce | ||
| Boolean | |||
| Set this to true if you just want to execute your code once. | | Set this to true if you just want to execute your code once. | ||
|- | |- | ||
| Disabled | | Disabled | ||
| Boolean | |||
| Tells launchctl that it should not submit this job to launchd | | Tells launchctl that it should not submit this job to launchd | ||
|- | |- | ||
| EnvironmentVariables | | EnvironmentVariables | ||
| Dictionary of Strings | |||
| Allows you to set additional environmental variables for your job. As an example: DYLD_INSERT_LIBRARIES. | | Allows you to set additional environmental variables for your job. As an example: DYLD_INSERT_LIBRARIES. | ||
|- | |- | ||
| WatchPaths | | WatchPaths | ||
| Array of Strings | |||
| launchd will watch the given paths and it will launch your job when one of these paths has been modified. | | launchd will watch the given paths and it will launch your job when one of these paths has been modified. | ||
|- | |- | ||
| QueueDirectories | | QueueDirectories | ||
| Array of Strings | |||
| Similar to '''WatchPaths''' with the difference that watches directories not being empty. | | Similar to '''WatchPaths''' with the difference that watches directories not being empty. | ||
|- | |- | ||
| StartInterval | | StartInterval | ||
| Integer | |||
| This optional key causes the job to be started every N seconds. | | This optional key causes the job to be started every N seconds. | ||
|- | |- | ||
| StartCalendarInterval | | StartCalendarInterval | ||
| Dictionary of integers or array of dictionary of integers | |||
| Specify a date or time for your Job to be started. e.g every Monday at 7PM. | | Specify a date or time for your Job to be started. e.g every Monday at 7PM. | ||
|} | |} | ||
Line 105: | Line 105: | ||
|- | |- | ||
! Key | ! Key | ||
! Type | |||
! Description | ! Description | ||
|- | |- | ||
| KeepAlive | | KeepAlive | ||
| Boolean or dictionary of stuff (well said Apple) | |||
| Determines whether your job is to be kept continuously running. If this is set to true and your job exits, it will respawn. Keeping the daemon alive as of 'not exiting' is your job | | Determines whether your job is to be kept continuously running. If this is set to true and your job exits, it will respawn. Keeping the daemon alive as of 'not exiting' is your job | ||
|- | |- | ||
| TimeOut | | TimeOut | ||
| Integer | |||
| Idle time out (in seconds) to pass to the job. If not specified, the default time will be passed to launchd. | | Idle time out (in seconds) to pass to the job. If not specified, the default time will be passed to launchd. | ||
|- | |- | ||
| ExitTimeOut | | ExitTimeOut | ||
| Integer | |||
| The amount of time launchd waits before sending a SIGKILL signal. The default value is 20 seconds. The value zero is interpreted as infinity. | | The amount of time launchd waits before sending a SIGKILL signal. The default value is 20 seconds. The value zero is interpreted as infinity. | ||
|- | |- | ||
| ThrottleInterval | | ThrottleInterval | ||
| Integer | |||
| Jobs will be respawned not more than once every 10 seconds. This key overrides the default throttling policy of launchd. | | Jobs will be respawned not more than once every 10 seconds. This key overrides the default throttling policy of launchd. | ||
|} | |} | ||
Line 130: | Line 130: | ||
|- | |- | ||
! Key | ! Key | ||
! Type | |||
! Description | ! Description | ||
|- | |- | ||
| RootDirectory | | RootDirectory | ||
| String | |||
| This key allows you to change the root directory for your job before it launches. | | This key allows you to change the root directory for your job before it launches. | ||
|- | |- | ||
| WorkingDirectory | | WorkingDirectory | ||
| String | |||
| This key allows you to change the working directory for your job before it launches. | | This key allows you to change the working directory for your job before it launches. | ||
|- | |- | ||
| StandardInPath | | StandardInPath | ||
| String | |||
| You can choose a file where the data supplied by stdin will be saved, | | You can choose a file where the data supplied by stdin will be saved, | ||
|- | |- | ||
| StandardOutPath | | StandardOutPath | ||
| String | |||
| Output from stdout will be saved to that file when using stdio(3). | | Output from stdout will be saved to that file when using stdio(3). | ||
|- | |- | ||
| StandardErrorPath | | StandardErrorPath | ||
| String | |||
| Specify an error path where stdio(3)'s stderr is written to. | | Specify an error path where stdio(3)'s stderr is written to. | ||
|- | |- | ||
| Debug | | Debug | ||
| Boolean | |||
| Control wether launchd should adjust its log mask temporarily to LOG_DEBUG or not. | | Control wether launchd should adjust its log mask temporarily to LOG_DEBUG or not. | ||
|- | |- | ||
| WaitForDebugger | | WaitForDebugger | ||
| Boolean | |||
| Instructs the kernel to wait until a debugger is detached before executing any code in your daemon. | | Instructs the kernel to wait until a debugger is detached before executing any code in your daemon. | ||
|} | |} | ||
Line 167: | Line 167: | ||
|- | |- | ||
! Key | ! Key | ||
! Type | |||
! Description | ! Description | ||
|- | |- | ||
| inetdCompatibility | | inetdCompatibility | ||
| Dictionary | |||
| The daemon expects to be run as if it were launched from inetd | | The daemon expects to be run as if it were launched from inetd | ||
|} | |} | ||
Revision as of 13:25, 6 October 2014
Daemons are programs that run as a background process. These programs may or may not have a long life cycle and exist in a paradigm different to tweaks. They do not require to be injected onto other processes, that means that they exist by themselves.
Several tweaks and programs use them such as f.lux, gremlin, rocketbootstrap, SafariDownloadEnabler, ssh.
How to make a daemon
There's two steps: making a program and making a plist for it.
The program
While idle, the program should waste the least possible resources. Remember that it is working along with many other already existing processes.
Given that memory isn't shared across processes, one cannot call functions or get objects freely between processes. To solve this, one must use some form of IPC (notifications, XPC, sockets) to communicate with the daemon.
The plist
Place your plist, following the reverse DNS notation (com.your.daemon), in layout/Library/LaunchDaemons
.
Required Keys
Key | Type | Description | Note |
---|---|---|---|
Label | String | Unique identifier for your daemon | --- |
Program | String | This key maps to the first argument of execvp(3). If missing, the first Argument of ProgramArguments is used. | Only required in absense of ProgramArguments key |
ProgramArguments | Array of Strings | This key maps to the second argument of execvp(3). If missing, the Program key is used. | Only required in absense of Program key |
Permission related Keys
Key | Type | Description |
---|---|---|
UserName | String | Specifies the user to run the job as |
GroupName | String | Specifies the group to run the job as |
Launch related Keys
Key | Type | Description |
---|---|---|
RunAtLoad | Boolean | Controls whether your job is launched at boot time (when launchd launches) or not. |
LaunchOnlyOnce | Boolean | Set this to true if you just want to execute your code once. |
Disabled | Boolean | Tells launchctl that it should not submit this job to launchd |
EnvironmentVariables | Dictionary of Strings | Allows you to set additional environmental variables for your job. As an example: DYLD_INSERT_LIBRARIES. |
WatchPaths | Array of Strings | launchd will watch the given paths and it will launch your job when one of these paths has been modified. |
QueueDirectories | Array of Strings | Similar to WatchPaths with the difference that watches directories not being empty. |
StartInterval | Integer | This optional key causes the job to be started every N seconds. |
StartCalendarInterval | Dictionary of integers or array of dictionary of integers | Specify a date or time for your Job to be started. e.g every Monday at 7PM. |
Lifetime related Keys
Key | Type | Description |
---|---|---|
KeepAlive | Boolean or dictionary of stuff (well said Apple) | Determines whether your job is to be kept continuously running. If this is set to true and your job exits, it will respawn. Keeping the daemon alive as of 'not exiting' is your job |
TimeOut | Integer | Idle time out (in seconds) to pass to the job. If not specified, the default time will be passed to launchd. |
ExitTimeOut | Integer | The amount of time launchd waits before sending a SIGKILL signal. The default value is 20 seconds. The value zero is interpreted as infinity. |
ThrottleInterval | Integer | Jobs will be respawned not more than once every 10 seconds. This key overrides the default throttling policy of launchd. |
Control and Debug related Keys
Key | Type | Description |
---|---|---|
RootDirectory | String | This key allows you to change the root directory for your job before it launches. |
WorkingDirectory | String | This key allows you to change the working directory for your job before it launches. |
StandardInPath | String | You can choose a file where the data supplied by stdin will be saved, |
StandardOutPath | String | Output from stdout will be saved to that file when using stdio(3). |
StandardErrorPath | String | Specify an error path where stdio(3)'s stderr is written to. |
Debug | Boolean | Control wether launchd should adjust its log mask temporarily to LOG_DEBUG or not. |
WaitForDebugger | Boolean | Instructs the kernel to wait until a debugger is detached before executing any code in your daemon. |
Other Keys
Key | Type | Description |
---|---|---|
inetdCompatibility | Dictionary | The daemon expects to be run as if it were launched from inetd |
To be done: Subrows for Dictionary Keys, maybe add a few more keys