Lasso Soft Inc. > Home

[RD_lassoService_pid]

LinkRD_lassoService_pid
AuthorWade Maxfield
CategoryUtility
Version8.5.x
LicensePublic Domain
Posted16 Apr 2009
Updated27 May 2009
More by this author...

Description

Returns the pid (Process ID) of the LassoService8 process using ps via the OS_Process tag.

Optionally it can write to a .pid file for use with standard system monitoring tools.

Intended usage:
Place it in your LassoStartup folder along with

RD_lassoService_pid(-cmd='write');


and each site will create it's own /tmp/LassoService8_{Site_ID}.pid file on start up.

Requires OS_Process, and Mac OS X (should work on linux based servers as well). Tested on Lasso Professional 8.5, but may work on 8.1.

For more info on how to use this tag as part of a system to monitor and automatically restart Lasso see Monitoring Lasso with Monit on LassoTech

Sample Usage

RD_lassoService_pid(); // get the pid for current site via ps / os_process

RD_lassoService_pid(-cmd='write'); // write the pid for the current site to .pid file

RD_lassoService_pid(-cmd='read'); // read the pid for the current site from .pid file

RD_lassoService_pid(-cmd='write', -siteID=3); // write the pid for site 3 to .pid file

Source Code

Click the "Download" button below to retrieve a copy of this tag, including the complete documentation and sample usage shown on this page. Place the downloaded ".inc" file in your LassoStartup folder, restart Lasso, and you can begin using this tag immediately.

lassoService_pid
//
//	Description:
//
//		This tag reports LassoService8 pid, and optionally reads or writes
//		to a pid file at /tmp/Lasso8Service_{siteid}.pid. All via [os_process]
//
//	Usage:
//
//		generally to be called at startup from LassoStartup folder
//
//
//  Note:
//
//		Requires OS_Process
//		Developed and tested on/for Mac OS X, it may work on Linux but will
//		probably require tweaking of shell/os_process commands
//		Doesn't do anything useful on Windows
//		
//		

if(lasso_tagexists('os_process'));
	define_tag(
		'RD_lassoService_pid',
		-optional='cmd',
		-type='string',
		-optional='siteID',
		-type='integer',
		-privileged,
		-priority='replace',
		-description='Reports LassoService8 pid, optionally reads or writes to pid file at /tmp/Lasso8Service_{siteid}.pid. All via [os_process].'
	);

		!local_defined('cmd') ? local('cmd' = '');
		!local_defined('siteID') ? local('siteID' = Site_ID);
		local('os') = lasso_version( -lassoplatform);

		local('out') = string;

		if(#os >> 'Win');
			local('out') = -1;
		else;
			select(#cmd);
				case('write_sh'); // write the pid of Lasso8Service.sh
					local('shell') = os_process(
						'/bin/bash',
						(: '-c', 'ps -o pid,command -au lasso | grep [L]asso8Service.sh | awk \'{print $1}\' > /tmp/LassoService8.pid; cat /tmp/LassoService8.pid')
					);
					local('out') += #shell->read;
					!#out->size ? #out = #shell->readerror;
					#shell->close;


				case('write'); // write the pid to a .pid file, and return the written value
					local('oldpid') = RD_lassoService_pid(-cmd='read', -siteID=#siteID);
					local('pid') = RD_lassoService_pid(-siteID=#siteID);

					// Only update pid file if pid has changed
					if: Integer(#pid) != Integer(#oldpid);
						local('shell') = os_process(
							'/bin/bash',
							(: '-c', 'echo ' + Integer(#pid) + ' > /tmp/LassoService8_' + #siteID + '.pid; cat /tmp/LassoService8_' + #siteID + '.pid')
						);
						local('out') += #shell->read;
						!#out->size ? #out = #shell->readerror;
						#shell->close;
					else;
						#out = #pid;
					/if;


				case('read'); // read the pid from the .pid file
					local('shell') = os_process(
						'/bin/bash',
						(: '-c', 'cat /tmp/LassoService8_' + #siteID + '.pid')
					);
					local('out') += #shell->read;
					!#out->size ? #out = #shell->readerror;
					#shell->close;


				case(''); // get the current pid without the .pid file
					// check current pid
					if: #siteID == 0;
						local('shell') = os_process(
							'/bin/bash',
							(: '-c', 'ps -o pid,command -au lasso | grep [L]asso8Service$ | awk \'{print $1}\'')
						);
					else;
						local('shell') = os_process(
							'/bin/bash',
							(: '-c', 'ps -o pid,command -au lasso | grep [l]assosite_' + #siteID + ' | awk \'{print $1}\'')
						);
					/if;
					local('out') += #shell->read;
					!#out->size ? #out = #shell->readerror;
					#shell->close;

			/select;

		/if;

		return(#out);

	/define_tag;
/if;


// write the pid file on startup
RD_lassoService_pid(-cmd='write');


// since os_process tag doesn't exist for site0, let's explicitly process the
// pid when any other lasso site starts.
// This is mainly in case Lasso is started via ./consoleLassoService.command
// or you haven't modified /LassoAdmin/Lasso8Service.sh to create a .pid file
// automatically
RD_lassoService_pid(-cmd='write', -siteid=0);


?>

Comments

27 Jul 2012, Marc Pinnell

NOTE: Broken for L8.6

To fix:

On line 95:

Change:

(: '-c', 'ps -o pid,command -au lasso | grep [l]assosite_' + #siteID + ' | awk \'{print $1}\'')

to:

(: '-c', 'ps -o pid,command -au lasso | grep [l]assosite_8.6_' + #siteID + ' | awk \'{print $1}\'')

Note the addition of the "8.6_" that fixed it.

Please log in to comment

Subscribe to the LassoTalk mail list

LassoSoft Inc. > Home

 

 

©LassoSoft Inc 2015 | Web Development by Treefrog Inc | PrivacyLegal terms and Shipping | Contact LassoSoft