/** Copyright 2017 Haiku, Inc. All rights reserved.* Distributed under the terms of the MIT License.** Authors:* Axel DΓΆrfler, axeld@pinc-software.de*//*!\page launch_intro Introduction to the Launch DaemonIn general, you should name your jobs/services after the application signature(if possible), and name the configuration files accordingly (in each casewithout the "application/" prefix). Alternatively, you may use the name of yourpackage as file name. If you do so, you may want to include the version, too,but do not add the version to the name of a job.A "service" is re-started automatically by the launch_daemon as soon as it'squit (or has crashed). Use a "job" instead, if you don't want this behavior.Let's start with a simple example:<code>service x-vnd.MyGreatServer {}</code>This will register a service named MyGreatServer, and assumes it uses a BServerbased application object. It will automatically launch the server eitherduring system boot (when you place your configuration file in<code>/system/data/launch/</code>), or after user login (when it's in<code>~/config/data/launch/</code>) via its signature (which it constructsusing the job's name). Furthermore, it will create a port for the server, sothat it can be immediately be talked to.Unfortunately, BServer is private as of now, and you didn't want to make agreat effort to subclass it. In this case, you have to notify the launch_daemonof this fact by adding a "legacy" to that configuration:\codeservice x-vnd.MyGreatServer {legacy}\endcodeIf you want to save the cycles for querying for your server, you can alsodirectly specify the file that should be launched; in this case, the job nameis just a name. This could look like this:\codeservice x-vnd.MyGreatServer {launch /path/to/my/great/serverlegacy}\endcodeThis method also allows you to add additional launch arguments like this:\codeservice x-vnd.MyGreatServer {launch /path/to/my/great/server --debug-modelegacy}\endcodeIf you do not want to enable the service by default, but only provide atemplate or basic configuration for the user, you can disable it like this:\codeservice x-vnd.MyGreatServer {launch /path/to/my/great/server --debug-modelegacydisabled}\endcodeYou can then override this in the settings by redefining the service, andoverwrite the parts you want to change. In this case, it might just be:\codeservice x-vnd.MyGreatServer {disabled false}\endcodeThe rest of the configuration will stay intact.If you only want to launch your application depending on the currentenvironment, you can define conditions which must be met to launch yourapplication at all, and events which will trigger launching your application.In the configuration file, this could look like this:\codeservice x-vnd.MyGreatServer {launch /path/to/my/great/serverif {not safemodefile_exists /path/to/license/file}on {demand}}\endcodeAlternatively, there are shortcuts for two of the above items, and you couldalso write it like this:\codeservice x-vnd.MyGreatServer {launch /path/to/my/great/serverif {file_exists /path/to/license/file}no_safemodeon_demand}\endcodeIf you have only single line conditions/events, you may also omit the curlybraces completely:\codeservice x-vnd.MyGreatServer {launch /path/to/my/great/serverif file_exists /path/to/license/fileno_safemodeon demand}\endcodeNote, the "on demand" does not use the "on_demand" shortcut, but just saves thecurly braces of "on { demand }".You can also use operators like "and", "or", and "not" in conditions. If youput more than one condition into an "if" they must all be true in order to meetthe condition. Conditions will be evaluated every time the launch_daemon has areason to start your application -- the outcome of the condition may changeover time.Likewise, if you put more than one event into an "on" only one of them needs tobe triggered in order to launch your job. While the event processing is alreadyprepared to allow for an "and" operator, this is not yet available.You can also specify the environment variables for your application. They canbe either specified directly, or you can let a shell script define them for you:\codeservice x-vnd.MyGreatServer {env {from_script /path/to/my/script.shLC_CTYPE C.UTF-8}launch /path/to/my/great/server}\endcodeIf you want to move the job into a specific target, you can write it like this:\codetarget my-target {service x-vnd.MyGreatServer {launch /path/to/my/great/server}}\endcodeYou will be able to move jobs into targets around in the configuration files,but this has not been implemented at the time of this writing.Like jobs, and services, targets can use conditions, events, and environmentvariables. If you do not specify an event for your target, it will not launchautomatically unless it's requested by name. Furthermore, jobs within yourtarget will not be available unless the target has been launched eithermanually or by event.You can also let the launch_daemon create resources for your application, likeadditional named ports. These ports will be available to other applicationswithout having to launch your application, and will belong to the launch_daemonthroughout their lifetime.Finally, there is a "run" directive that you can use to launch targetsunconditionally. The "run" directive also allows to use conditions, but addsthe additional keywords "then", and "else" like this:\coderun {if read_onlythen installerelse desktop}\endcodeYou can also use curly braces if you like or want to run more than one job.It's a good idea to look at the existing configuration files to get an idea howthis is all supposed to work.*/