a short note on handling LaunchDaemons and LaunchAgents on your Mac environment.
What do they do:
It’s a service/program/script running in the background based on specific parameters it may restart automatically, do things on a regular basis or simply start and stop servers, databases and the likes.
Where are they:
/Library/LaunchDaemons
/Library/LaunchAgents
/Systems/Library/LaunchDaemons
/System/Library/LaunchAgents
What’s the difference:
A LaunchDaemon is run by the root user or the user specified in UserName.
A LaunchAgent is run by the currently logged in user.
System Integrity Protection:
With El Capitan, Apple introduced System Integrity Protection, as a security measure to protect files and folders on your Mac - specifically those in the root directory.
This means that when working with LaunchDaemons or LaunchAgents you will need to keep them under /Library/LaunchDaemons or /Library/LaunchAgents
Here’s a working example for a LaunchAgent I use to start NaviServer:
Anya is live and ready to show you everything. Watch her strip, dance, and perform exclusive shows just for you. Interact in real-time and make your fantasies come true.
✓ Live Streaming✓ Interactive Chat✓ Private Shows✓ HD Quality
Anya is LIVE right now
FREE
Free to watch • No registration required • HD streaming
A Step by Step Guide to further setup your fresh NaviServer install.
Part 1 - Getting Started: Installing NaviServer on MacOS
Part 2 - Configuring your NaviServer on Mac OS
Part 3 - A simple helloworld database interaction
Part 4 - Setting up OpenACS with NaviServer on MacOS
What I will cover in this part:
(A) Configuring your LaunchDaemons to start and stop NaviServer and PostgreSQL
(B) Setup your new database environment
(C) Configuring NaviServer to work with PostgreSQL
==================================================
Step (A) Conf(ront)(igur)ing your LaunchDaemons
==================================================
Some general concerns on designing integrated high quality linux applications.
One could use daemontools. However I did not get it to work on my Mac environment so I chose to stick with what Apple suggests: LaunchDaemon. If you still prefer daemontools maybe this example writeup will help you get started.
(1) Read up on what a LaunchDaemon is
This tutorial on launchd http://launchd.info/ gives a nice overview. Over at openacs.org some NaviServer related example LaunchDaemons already exist. If you still need more information this post is quite informative. Last but not least you can always consult Apple's mega documentation if in doubt.
Label is the key to identify this LaunchDaemon = org.naviserver.yourname
ProgramArguments contains an array of strings with the actual command to start NaviServer. Note that you need to add each parameter and value separately. Also, pay attention to add the foreground flag in order for launchd to see the process (backgroundinfo: http://superuser.com/a/1112872/311059)
I also define a StandardOutPath and StandardErrorPath feeding into /var/log/naviserver.log in order to keep track of dubious Daemon messages.
(3) Work with launchctl to list, load/unload, start/stop NaviServer
Note the different input paramaters for load/unload and start/stop.
(8) Ensure that the var log is writable for the postgres user
This can be particularly frustrating as the LaunchDaemon will through the following error in /var/log/system.log: Service could not initialize: 15G31
For superuser access login with postgres user (note the hash on the prompt):
psql94 -U postgres testdb
Drop the database if you don’t want it anymore. with drodb.
==================================================
Step (C) Configuring NaviServer to work with PostgreSQL
==================================================
For a successful database connection ensure the following setup for your conf.tcl file:
set db_host localhost
set db_port "5432"
set db_user yourUsername
set db_name testdb