You might have already noticed that some jobs are automatically launched when the Haiku system starts.
In this article let's review how it's done, and in which case it can be useful to define a launch daemon for your applications packages or for your personal usage.
Before moving forward, the launch daemon is making a difference between a service and a job :
Now let's review that in details.
The existing system launch daemon is available in "/system/data/launch".
Open a Terminal and type :
cd /system/data/launch
lpe system
You should see the below services or jobs :
For instance, let's check the "net_server" service :
launch_roster list | grep net_server
You can retrieve the information relative to this service :
launch_roster info x-vnd.haiku-net_server
According to the help option, you can start/stop/restart a service or a job :
In case of a service, the stop command seems to not be effective :
In case of a job, the stop command is effective, however for the job below, it has been restarted by the system :
Now let's check the interesting part : the user launch daemon :)
The user launch daemon is available in "/system/data/user_launch".
To review the existing setup, open a Terminal and type :
/system/data/user_launch
lpe user &
Let's review - for instance - the user launch for LaunchBox :
job x-vnd.Haiku-LaunchBox {
launch /system/apps/LaunchBox
if setting ~/config/settings/LaunchBox/main_settings autostart
on initial_volumes_mounted
legacy
no_safemode
}
This setup indicates that "x-vnd.Haiku-LaunchBox" :
If you go further in the "user" file, you should see the "UserBootScript" below :
The "~/config/settings/boot/UserBootscript" is really interesting in case you need to start some specific commands during the boot of the system.
We will review that at the end of this article.
Last point, as you can see at the end of this "user" file, there's a run section where:
Do you know that with launch_roster command, you can list the existing targets ?
launch_roster list-targets
Let's start the installer target then to check !
launch_roster start installer
It's working as expected :)
Now suppose you would like to create a new launch daemon for a specific usage.
For that you need to create the directory "user_launch" in "/system/non-packaged/data/" :
mkdir -p /system/non-packaged/data/user_launch
A good example is the PostgreSQL package which is not including a launch daemon once installed.
First install PostgreSQL server as explained in the Install PostgreSQL article.
Let's fix the auto-start of the server by adding a new user launch daemon.
In a terminal type :
lpe /system/non-packaged/data/user_launch/postgresql
Do a copy/paste of the below :
job x-vnd.postgresql {
launch /bin/pg_ctl -D /boot/home/postgresql -l /boot/home/postgresql/postgresql.log start
no_safemode
legacy
on initial_volumes_mounted
}
Save the file and quit.
Restart the sytem.
Open a Terminal, and verify the server is ready, and that you can connect to the server :
pg_isready
psql -h localhost -U postgres -W
Great !
You don't need anymore to start the server manually each time your system is starting.
If you remember, there's also the "UserBootScript" which is called during the system start process.
In case you don't want to bother with user launch daemon, the alternative is to modify this file.
First remove the "/system/non-packaged/data/user_launch/postgresql" created before.
Then edit this boot script file :
lpe ~/config/settings/boot/UserBootscript &
And paste the below line, to start the server when the system starts :
pg_ctl -D /boot/home/postgresql -l /boot/home/postgresql/postgresql.log start
Reboot your system and checks the results.
The "pg_isready" should indicate the server is ready as well !
I hope you have found this article interesting.
You can check for the existing documentation on the official website on the "Introduction to the Launch Daemon" page.