pre-deactivate - error if process running

Bjarne D Mathiesen macintosh at mathiesen.info
Fri May 25 01:45:09 PDT 2012


Ryan Schmidt wrote:
> 
> On May 24, 2012, at 16:02, Craig Treleaven wrote:
> 
>> I'd like to add a check to my in-progress portfile, testing whether the main server process ("mythbackend") is running and refusing to deactivate if so.  The reason is that launchd will keep trying to restart the missing program every 10 seconds--apparently without end! Floods the console log with messages even though there is little other harm.
>>
>> I've searched around a bit and can't find any ports that seem to do that sort of test.  Could someone point me to some sample code?  I suppose something like 'ps -Ac | grep interestingprogram'?

If you remove the plist file, /launchctl unload <plist-file>/ will fail
So you'll have to resort to /launchctl remove <label>/

> 
> This is really something we should implement in MacPorts base. MacPorts should prevent you from deactivating a port you loaded; you should be required to unload the port first.

launchctl has a mechanism for inquiring about jobs :

list [-x] [label]
	...
	If [label] is specified, prints information about the requested
	job. If [-x] is specified, the information for the specified job
	is output as an XML property list.

eg :

pro17:LaunchDaemons root# grep -A 1 -i label info.mathiesen.*
info.mathiesen.apache.httpd.plist:<key>Label</key>
info.mathiesen.apache.httpd.plist-<string>org.apache.httpd</string>
--
info.mathiesen.dovecot2.plist:<key>Label</key>
info.mathiesen.dovecot2.plist-<string>info.mathiesen.dovecot2</string>

for a program that has been loaded ::
pro17:LaunchDaemons root# launchctl list org.apache.httpd
{
	"Label" = "org.apache.httpd";
	"LimitLoadToSessionType" = "System";
	"OnDemand" = false;
	"LastExitStatus" = 0;
	"PID" = 44050;
	"TimeOut" = 30;
	"ProgramArguments" = (
		"/macports/apache2/bin/httpd";
		"-D";
		"FOREGROUND";
		"-D";
		"MACOSXSERVER";
	);
};

for a program that's not loaded ::
pro17:LaunchDaemons root# launchctl list info.mathiesen.dovecot2
launchctl list returned unknown response


:-)
-- 
Bjarne D Mathiesen
København N ; Danmark ; Europa
----------------------------------------------------------------------
denne besked er skrevet i et totalt M$-frit miljø
MacOS X 10.7.3 Lion ; 2.8GHz Intel Core i7 ; 16GB 1067MHz DDR3


More information about the macports-dev mailing list