Web Application LaunchDaemon vs Terminal

Hi all, here’s an interesting one. I’ve built a small web application. When I use Apple’s LaunchDaemons to launch it, I get the Interruption Message every few minutes - causing the page to re-load and a new session is created. I’ve checked the .plist file in /Library/LaunchDaemons and it looks OK (to me). I’m using LaunchControl to manage things).

However, when I manually launch the application in the terminal, it runs fine and is stable.

Thoughts?

Regards,
Dave.

It sounds like launchd is possibly restarting your app every so often. When the app is quit and relaunched all sessions are lost. I did a quick Google and found an Apple Developer discussion, but the thread was trying to do the opposite of what you need to.

Hi Tim, it is unusual behaviour - the only option I’ve got left on the job is “Run at Load” to ensure it’s started back up in the event of a restart. I would expect the behaviour you’ve mentioned if I had the “Keep Alive No Matter What” option was added to the job. In that, if a process craps out, it just spawns a new one. This isn’t (or doesn’t appear to be) happening in this instance. Very strange indeed.

Check your logs, every time a Web 2.0 app successfully launches it prints a ready message to stdout. I might suggest you log the process ID as well just to make it obvious if this is the issue.

Indeed. I’m echoing all the .open events to system.debuglog so I can see what’s going on. It would definitely appear that the app isn’t quitting and being re-opened. Much head scratching.

Could it be that your app is crashing?

Definitely not crashing.

Keep in mind that running as a daemon is not the same as running in the Terminal. Terminal has a user profile and a path whereas the daemon could be running as root or an unprivileged user.

Any chance you could show us the plist file for your daemon?

1 Like

Hi Greg, here you go

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/
PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
	<key>Label</key>
	<string>com.ndtec.MBWebApp</string>
	<key>ProgramArguments</key>
	<array>
		<string>/Applications/WebApps/MBWebApp</string>
		<string>--secureport=9005</string>
		<string>--maxsecuresockets=400</string>
	</array>
	<key>RunAtLoad</key>
	<true/>
	<key>StandardErrorPath</key>
	<string>/Users/admin/Desktop/MBWebAppLogs/stderr</string>
	<key>StandardOutPath</key>
	<string>/Users/admin/Desktop/MBWebAppLogs/stdout</string>
</dict>
</plist>

Based on what you mentioned above, I’ve updated the .plist file and it appears stable now! Thank you so much!

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
	<key>GroupName</key>
	<string>staff</string>
	<key>InitGroups</key>
	<true/>
	<key>Label</key>
	<string>com.ndtec.MBWebApp</string>
	<key>ProgramArguments</key>
	<array>
		<string>/Applications/WebApps/MBWebApp </string>
		<string>--secureport=9005</string>
		<string>--maxsecuresockets=400</string>
	</array>
	<key>RunAtLoad</key>
	<true/>
	<key>StandardErrorPath</key>
	<string>/Users/admin/Desktop/MBWebApp/stderr</string>
	<key>StandardOutPath</key>
	<string>/Users/admin/Desktop/MBWebApp/stdout</string>
	<key>UserName</key>
	<string>admin</string>
	<key>WorkingDirectory</key>
	<string>/Users/admin</string>
</dict>
</plist>

So before you get away, consider creating a standard (non admin) user and using that instead. Just in case your app is ever able to do something dangerous (like deleting files) you wouldn’t want the app to have admin rights.

1 Like