[RD_lassoService_pid]

Description

Link: [RD_lassoService_pid]
Author: Wade Maxfield
Category: Utility
Version: 8.5.x
License: Public Domain
Posted: Apr. 16, 2009
Updated: May. 27, 2009
More by this author...

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

Parameters

-cmd string, optional Optionally read or write to pid file
-siteID integer, optional Optionally specify the Site_ID to process

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.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
<?LassoScript
//............................................................................
/*

	{lassoVrsnMin=	8.5 }
	{lassoVrsnMax=	8.5.5 }

	{author=	Wade Maxfield }
	{authorEmail=	info@raindance.co.nz }
	{authorHTTP=	www.raindance.co.nz }

	{maintvsrn=	1.0 }
	{maintrelease=	1.0.0 }
	{maintdate=	2009-04-17 }
	{maintauthor=	Wade Maxfield }
	{maintnotes=	initial release }

*/
//............................................................................


//=============================================================================
//
//	->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

none

Email:


Password:



Newest

Most Popular

Support tagSwap.net