---
title: "Script Distribution"
canonical: "https://documentation.chaos.com/space/VRAYSWARM/112689711/Script%20Distribution"
format: markdown
---
This page provides information about distributing V-Ray builds to V-Ray Swarm peers by Script.


## **Overview**

---

The Script distribution method is performed by the System Administrator or an advanced user. It saves V-Ray versions to `<data-directory>/VRay/import/ `directory on every peer.


## **Workflow**

---

1. Create a shared directory on your server.
2. Put V-Ray distributions there.
3. Mount it on all peers.
4. Stop Swarm on all peers.
5. Change the setting `vrayImportDir` on them to point out to the shared directory.
6. Start Swarms on all peers.

4,5,6 are needed only if your shared directory is not located in `<data-directory>/VRay/import/`. If this directory contains V-Ray builds for different OSs, only some of them will be successfully deployed. However, deployment attempts will be performed approximately every 10 seconds, which will load a machine. So, the best approach is to create multiple shared directories: one per OS + architecture (for example: `Windows_x86/, Windows_Arm64/, Linux_x86/)`and to put relevant V-Ray archives/installers there.

This can be done with scripts, for example, with *PowerShell* or *bash *or similar. Such script should upload/send V-Ray archive or an installer to a special Swarm endpoint, It is` localhost:1113/api/vray/upload` where 1113 is the `webPort `setting and 1113 is its default value. Example for curl:

`curl -v -Fqueued=false -F \ `  
`file=@$HOME/tmp/vray-lin-df715d3c8ff9.tar\ `  
`localhost:1113/api/vray/upload`

And the script could do something very similar. From this simple example, it can be seen that there are parameters - queued and file.  
So, the API is:

1. `<peer-IP>:<webPort>/api/vray/upload    HTTP POST`
  - `<peer-IP>` is the IP of the peer, for the local Swarm localhost can be used
  - `webPort `by default is 1113 if it was not changed in swarm.yaml settings
  Parameters of the POST request are:
  - 
    - `queued `is a boolean flag, if it is `false `(JSON representation is used), then the uploaded file is processed immediately (synchronous or rapid call). If it is `true`, then the uploaded file will be put to `<data-directory>/VRay/import/` and will be imported little bit later (see `uploadsQueuePeriod` Swarm’s setting, by default: 10 seconds)
  - `file `is the uploaded file itself (an archive of supported format or an installer of supported format). Installers by default are not allowed, to allow them, change the `allowExecutables` Swarm’s setting.  
  
When a file is uploaded in **rapid mode** (`queued `is `false`):  
  
Wait until the file upload and deployment are completed. When you get the response, it means the V-Ray file was fully deployed (and it is ready to be shared with other peers being saved in the `<data-directory>/VRay/import/` directory).  
Responses can include an error message if V-Ray was not deployed successfully.  
If there are failures, the file is removed.  
If the operation is successful, V-Ray is deployed/installed, its archive/installer file is in the `<data-directory>/VRay/import/ directory.`  
And if the operation is successful, the response includes a JSON dictionary as follows:
  `{ "deployedInDirectory": <path>,`  
`  "uploadedFileSize": <int>,`  
`  "tmpFile": <path>,`  
`  "takenSeconds": <int>,`  
`  "uploadedVrayVersion": <version-dictionary> }`
  When a file is uploaded in **queued mode** (`queued` is `true`):  
  
The uploaded files are saved in the import folder - it is queued.  
Wait until the uploading of a file completes, but not the deployment.  
You receive a response that the file was queued.  
Responses include a JSON dictionary as follows:
  `{ "queuedAs": <path>,`  
`  "uploadedFileSize": <int>,`  
`  "tmpFile": <path> }`
  If rapid or queues **upload fails**, the response includes JSON dictionary such as:  
  
`{"message": <str>, "tmpFile": <path>}`  
  
If such version already exists (such detection is able only with uploads of archives), the error JSON dictionary inside the larger JSON response is:
  `{ "message": <str>, "tmpFile": <path>,`  
`  "uploadedVrayVersion": <version-dictionary> }`
  Where <version-dictionary> is a JSON dictionary like:
  `{ "_revHash": "e8197af2",`  
`  "_ver": {"_major":6,"_minor":20,"_release":10} }.`
  It corresponds to a `<version-str> `as` 6.20.10-e8197af2` when it is a part of a file name in `<data-directory>/VRay/import/` directory.
  In both bad cases (failure, already existing version) temporary file will be removed and everything will be in a state as before.  
   
So, the whole (large) JSON is:  
  
`{<tag-str>: <one-of-dictionaries-above>}`  
  
where `<tag-str>` is one of these strings:
  Examples of responses:
  `{ "ExistingUR":`  
`  {"message":"V-Ray version already exists",`  
`   "tmpFile":"/tmp/servant-multipart106588-2922.buf",`  
`   "uploadedVrayVersion":`  
`     {"_revHash":"e8197af2",`  
`      "_ver": {"_major":6,"_minor":20,"_release":10} }}}`
  Another one:
  `{`  
`  "RapidUR": {`  
`     "takenSeconds": 6,`  
`     "tmpFile": "/tmp/servant-multipart106588-2924.buf",`  
`     "uploadedFileSize": 458321016,`  
`     "deployedInDirectory":`  
`       "/tmp/VRay/vray-6.20.10-e8197af2",`  
`     "uploadedVrayVersion": {`  
`       "_revHash": "e8197af2",`  
`       "_ver": {`  
`         "_major": 6,`  
`         "_minor": 20,`  
`         "_release": 10 }`  
`     }`  
`  }`  
`}`
  
2. `<peer-IP>:<webPort>/debug/allowExecutables    HTTP GET`

- <peer-IP> and webPort are the same as before  
This call returns a boolean flag “are executables allowed?”. It can be changed in the swarm.yaml settings (add  `allowExecutables`: true)