Lasso Soft Inc. > Home

[lp_site_restart]

Linklp_site_restart
AuthorBil Corry
CategoryUtility
Version8.5.x
LicensePublic Domain
Posted08 Mar 2007
Updated08 Mar 2007
More by this author...

Description

Restarts the current Lasso site.  No special permissions or passwords are needed.

The Lasso code for this tag requires that it's loaded from the root LassoStartup folder.  It will not work otherwise.

Note that this tag works by opening port 21012 for communication between the sites.  And to secure the port, it uses an internally-managed password in order to restart a site.

Sample Usage

lp_site_restart; // restart the site immediately

lp_site_restart: 2000; // restart the site in 2 seconds

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.

[

// NOTE: [lp_site_restart] will only work when this is loaded via the root LassoStartup

if: site_id == 0;

	// init server - create asyncronous listener
	{
		local:'keycodes' = map;
		local:'inbound' = net;
		#inbound->(bind: 21012);
		while: true;
			protect;
				handle_error;
					log_critical:'[lp_site_restart] ERROR: ' + error_msg;
					#connection->close;
				/handle;
				#inbound->listen;
				local:'connection' = #inbound->accept;		
				local:'command' = (string: (#connection->(read: 2048)));
				#command = #command->(split:' ');
				local:'cmmd' = #command->(get: 1);
				local:'site' = (integer: #command->(get: 2));
				local:'code' = #command->(get: 3);
				if: #cmmd->size && #site && #code->size == 1000;
					if: #cmmd->(equals:'RESTART', -Case);
						if: #keycodes->(find: #site) != null && #keycodes->(find: #site)->(equals: #code, -Case);
							log_critical: '[lp_site_restart] RESTARTING SITE #' + #site;
							#keycodes->(insert: #site = null); // reset key
							server_sitestop: #site;
							server_sitestart: #site;
						/if;
					else: #cmmd->(equals:'REGISTER', -Case);
						if: #keycodes->(find: #site) == null;
							#keycodes->(insert: #site = #code);
						/if;
					/if;
				/if;
				#connection->close;
			/protect;
		/while;
		#inbound->close;
	}->asasync;

	sleep: 1000; // give some time for the listener to kick on

else;

	// init client
	{
	
		// create siteRestartKey
		local:'siteRestartKey' = string;
		local:'alpha' = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!@#$%^&*()_+{}[];:,./<>?|`~';
		local:'upper' = #alpha->size;
		loop: 1000;
			#siteRestartKey += #alpha->(get: (math_random: -lower=1, -upper=#upper));
		/loop;
	
		// register siteRestartKey
		local:'outbound' = net;
		#outbound->(connect: '127.0.0.1', 21012);
		#outbound->(write:'REGISTER ' + site_id + ' ' + #siteRestartKey + ' \r\n');
		#outbound->close;	
	
		// create site-specific ctag using siteRestartKey
		process: "[
		define_tag:'restart', -namespace='_global_lp_site_',
			-description='Restarts the current Lasso site.',
			-priority='replace',
			-async,
			-optional='wait'; // time in milliseconds to wait before shutting down

			if: !(local_defined:'wait');
				local:'wait' = 10;
			/if;
			sleep: (integer: #wait);
			local:'outbound' = net;
			#outbound->(connect: '127.0.0.1', 21012);
			#outbound->(write:'RESTART " + site_id + " " + #siteRestartKey + " \r\n');
			#outbound->close;
		/define_tag;	
		]";
	
		
	}->run;

/if;


]

Comments

No comments

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