Skynet has built-in function for remotely self-updating its own PHP source code. When you send to clusters the @self_update command, all clusters whitch receive this command will launch update procedure. When you are sending @self_update command you must specify location of skynet cluster with new code. When updating, cluster will connect with it. At next, cluster with new source code will show their code and destination clusters will read this code and replace own code with it. How it works?
Let's imagine that we have two Skynet clusters in two different locations: skynet_old.php and skynet_new.php.
E.g.:
http://localhost/foo/skynet_old.php
and
http://localhost/bar/skynet_new.php
When skynet_old.php is your old file with some code and skynet_new.php is the newest compiled version (e.g. with new functions whitch you build-in) you can send request to all old clusters from this new one (or from another cluster). Example: if you'll send @self_update command from skynet_new.php to remotely placed skynet_old.php and specify skynet_new.php as source for updating procedure then skynet_old.php will connect with skynet_new.php and ask it for show its own code. At next, skynet_new.php will show it own source code and old cluster will get this. Finally, skynet_old.php will replace own code with this new one. Of course, you can send @self_update command to more than one cluster at once. If you do this then all older clusters will update with new one. You can do this, even if other clusters are on different servers with this one command: @self_update.
When sending @self_update command you need specify address to cluster witch is source with new PHP code. After updating, clusters whitch was updated will response with update result:
You will see parameters in response:
@<<self_update_success
or if any errors occurs:
@<<self_update_error
with update procedure results.
Parameters:
source - source address to cluster with new code
Usage (PHP code):
You can send @self_update command from event listener:
/src/SkynetUser/MyListener.php:
public function onRequest($context)
{
if($context == "beforeSend")
{
$this->request->set('@self_update', array('source' => 'ADDRESS_TO_SOURCE_CLUSTER'));
}
}
When ADDRESS_TO_SOURCE_CLUSTER is address to cluster with new code, in our case this is:
http://localhost/bar/skynet_new.php
So, command above will update all clusters with code of this one.
By default, command sended like that will be send to all clusters, e.g.:
http://localhost/foo/skynet_old.php
http://localhost/foo2/skynet_old.php
http://localhost/foo3/skynet_old.php
http://localhost/foo4/skynet_old.php
If you need to update only one specified cluster you must use @to command, e.g.:
/src/SkynetUser/MyListener.php:
public function onRequest($context)
{
if($context == "beforeSend")
{
$this->request->set('@self_update', array('source' => 'ADDRESS_TO_SOURCE_CLUSTER'));
$this->request->set('@to', 'ADDRESS_TO_OLD_CLUSTER');
}
}
When ADDRESS_TO_OLD_CLUSTER is an address to cluster you want to update.
Usage (webconsole):
@self_update source:"ADDRESS_TO_SOURCE_CLUSTER";
Command specified like that will send request to all clusters.
To specify one cluster as a receiver you add @to command:
@self_update source:"ADDRESS_TO_SOURCE_CLUSTER";
@to "ADDRESS_TO_OLD_CLUSTER";
Usage (CLI mode):
php skynet_new.php -b -send "@self_update source:'ADDRESS_TO_SOURCE_CLUSTER'"
or
php skynet_new.php -b -send "@self_update source:'ADDRESS_TO_SOURCE_CLUSTER'; @to 'ADDRESS_TO_OLD_CLUSTER'"
All updates results are put logs into database and text logs (if enabled).
You can see this logs in DATABASE VIEW and in your logs folder.
After update procedure all clusters will have THE SAME source code as source.
Self-update procedure is executes on destination clusters in onResponse (beforeSend) event.
BE CAREFUL WHEN UPDATING: If you accidentally send wrong source or source with errors it is possible to loose connection with clusters. Update only with fully stable and tested compilations.
NOTE: When updating remote cluster then connection with updating cluster can be refused for a while and no response will received.