The primary agent — the supervisor of a Yuneta node. It manages the lifecycle
of every other yuno (create / run / kill / update / delete), owns the realms
and their on-disk layout, exposes the control plane, and coordinates inter-yuno
communication. ycommand, ystats, ylist and ybatch talk to this yuno by
default.
Starting and stopping it: systemd¶
Since 7.25.22 the two agents run as native systemd units,
yuneta_agent.service and yuneta_agent22.service, independent of each
other. systemd starts them at boot and supervises the process that matters:
the agent’s own watcher (which relaunches the agent if it crashes) is the
unit’s main process, through --pid-file. The packages install and enable
both units.
systemctl status yuneta_agent # state, main pid, last lines of its log
sudo systemctl restart yuneta_agent # the main agent alone
sudo systemctl restart yuneta_agent22 # agent22 alone
journalctl -u yuneta_agent -n 50 # what systemd saw (start, stop, failures)service yuneta_agent ... and service yuneta_agent22 ... reach the same
units. The SysV script is still installed, and under systemd it drives the
PAIR of units, as it always treated the two agents:
sudo /etc/init.d/yuneta_agent ... | What it does |
|---|---|
start | Starts the main agent’s unit, then agent22’s, once the main one is up (a broken binary never takes both down). |
stop | Stops the main agent alone. agent22, the escape hatch, keeps running. |
restart | Restarts the main agent, and starts agent22 if it was not running. |
status | Reports both. |
What to know before touching them:
Starting a unit needs root, as the SysV script always did (it ran
su - yuneta). Stopping does not:--stoprun asyunetaends the agent in order, and its unit goesinactive./yuneta/agent/yuneta_agent --config-file=/yuneta/agent/yuneta_agent.json --stopAn agent started by hand runs OUTSIDE its unit.
yuneta_agent --startlaunched from a shell is a process of that shell: systemd does not see it,systemctl statussaysinactive, and the next boot is the unit’s, not yours. To put it back,sudo /etc/init.d/yuneta_agent start(it stops the agent found outside and starts the unit) orsudo systemctl restart yuneta_agent.A new agent binary is deployed with the unit: move the binary into place and restart that unit, one agent at a time, never both.
cp yuneta_agent /yuneta/agent/yuneta_agent.new mv /yuneta/agent/yuneta_agent.new /yuneta/agent/yuneta_agent sudo restorecon /yuneta/agent/yuneta_agent # only on SELinux (RHEL / Rocky) sudo systemctl restart yuneta_agentOn RHEL and Rocky, systemd cannot exec a file labelled
default_t, and everything under/yunetais: the package writes abin_trule for both agents into the policy (semanage fcontext, which requirespolicycoreutils-python-utilswhereselinux-policyis installed), andrestorecongives a file moved in by hand that label back -- amvkeeps the label of the source. Without it the unit dies with203/EXEC(“Failed to locate executable ... Permission denied”).The yunos outlive a restart of their agent. They are in the unit’s cgroup, but a stop takes only the agent (
KillMode=process). The journal says “Found left-over process” for them at the next start, which is that rule working.A node built from source (no package) gets the units by hand, from the repo’s templates:
sudo install -m 0644 packages/templates/yuneta_agent.service \ packages/templates/yuneta_agent22.service /usr/lib/systemd/system/ sudo systemctl daemon-reload sudo systemctl enable yuneta_agent yuneta_agent22 /yuneta/agent/yuneta_agent22 --config-file=/yuneta/agent/yuneta_agent22.json --stop sudo systemctl restart yuneta_agent22 # agent22 first, then: /yuneta/agent/yuneta_agent --config-file=/yuneta/agent/yuneta_agent.json --stop sudo systemctl restart yuneta_agentA development machine where the agents run as the developer adds a drop-in,
/etc/systemd/system/yuneta_agent.service.d/override.conf(and the same for agent22), with[Service],User=<you>,Group=<you>.
Why each line of the units is there (Type=forking, KillMode=process,
Restart=no, ExecStop, ExecStopPost) is in
Entry point §4.7 and in the comments of the units themselves.
Control plane ports¶
| URL | Purpose |
|---|---|
ws://127.0.0.1:1991 | Local, plaintext control plane (default for ycommand) |
wss://0.0.0.0:1993 | Secure control plane (TLS + OAuth2) |
Connecting out to a control center¶
When the node has an owner (node_owner ≠ "none"), the agent starts an
outbound C_IEVENT_CLI client service named controlcenter and dials the
control center. The remote URL is assembled from config variables:
tcps://(^^__sys_machine__^^).(^^__node_owner__^^).(^^__output_url__^^)that is, tcps://<machine>.<node_owner>.<output_url>, where __output_url__
defaults to yunetacontrol.com:1988 (1994 up to 7.30.3), and the link trusts
only /yuneta/agent/certs/controlcenter.crt. With an empty/none owner the
agent does not dial out.
A node points its agent at another control center from its json file
(/yuneta/agent/yuneta_agent.json, 7.30.5+), with the same key the agent’s
main.c uses for the default:
"global": {
"controlcenter.__json_config_variables__": {
"__output_url__": "yunetacontrol.com:1988"
}
}A top-level __json_config_variables__ in that file changes nothing: its scope
is the file itself, and the agent’s urls are in main.c. The input urls
(ws://127.0.0.1:1991, wss://0.0.0.0:1993) cannot be changed from the file.
The agent shows who it is with its own key (7.30.10+). On the link to the
control center the agent presents its own pair,
/yuneta/agent/certs/yuneta_agent.{crt,key}, as the client certificate. Each
node makes that pair for itself (see The agent’s own certificate in the
installation guide). The control center pins the node’s uuid to the key once an
operator accepts it (controlcenter, “Each node’s key”). A
node with no pair cannot open that link: the connection fails and says so in
the log, and the agent’s unit makes the pair again at its next start. Since
7.30.11 the accepted key is also the agent’s login: the agent needs no token
(controlcenter.jwt) in its json, and the package’s template carries none. A
new node connects with its key, and appears in the control center’s
list-nodes as knocking until an operator accepts it with the key the node
gives: its install prints it, and so does yuneta-agent-cert key on the node.
The agent verifies who asks (7.30.9+). The control center forwards an
operator’s command with an operator assertion: a short token that the
control center signs for this node (aud is the node uuid), and that names
the operator (sub). The agent verifies the assertion with the control
center’s public key (Authz.assertion_jwks in its main.c). Then it takes
the sub as the operator, and ignores the __username__ that the control
center wrote.
A command with no assertion is of the principal
controlcenter. Examples are a control center with no key, or a request with no user.A bad assertion is refused: another key, another node, or expired by more than the day of leeway (
Authz.assertion_time_leeway).
The agent accepts the day of leeway because a box whose clock drifts must still take its control center’s commands. To take the control center’s word again, put this in the json file:
"global": {
"controlcenter.verify_operator": false
}See C_IEVENT_CLI and
C_AUTHZ. See controlcenter for the
signing side.
Audit files¶
The agent writes every command that it runs to a daily audit file in
/yuneta/realms/agent/agent/audit/ (use_audit_command_file, on by default).
An agent whose commands cannot be audited at start does not run. If the
agent cannot make the audit directory, or cannot create or open the file in
it, at start, it stops, as a yuno whose file log cannot open. The cause goes to
stdout and syslog, and the watcher relaunches the agent until the cause is
fixed: 2 s after the first stop, then at a growing interval, up to one
relaunch a minute (Entry point §4.3).
The causes are a disk with no space left (ENOSPC: the
min_free_disk_percentage threshold is not checked at start), a read-only
file system, the permissions or the owner of /yuneta/realms/agent/agent/ or
of audit/, or a file with the name audit in place of the directory:
rotatory_open(): Cannot create '/yuneta/realms/agent/agent/audit' directory, Read-only file system
rotatory_open(): Cannot create '/yuneta/realms/agent/agent/audit/302-29_10_2026.log' file, Permission deniedUp to 7.29.3 an audit directory that the agent failed to make gave the agent no
path, and the agent ran with no audit of commands. The only trace was
“path EMPTY” in syslog. The path itself is always built: its root
(/yuneta) and domain (realms/agent/agent) are in the fixed configuration
of the agent. If it cannot be built, the agent logs one ERROR, “Command
audit: the path of the audit file cannot be built, the agent does not run”,
with the parts of the path (root_dir, domain_dir, subdir, filename),
and stops the same way.
Once the agent runs, a failure of the audit does not stop it: the commands go on running, without their records.
When the free space of the disk goes below
min_free_disk_percentage(default 20 %), the audit stops writing and drops the records. Syslog has one line when it stops and one when it writes again, with the number of records dropped. The free space is checked again every few records.When the file of a new day (or of a size rotation) cannot be made or opened, syslog has one line, and each next record tries again. Syslog has one more line when the file is open again.
To run the agent with no audit, set agent.use_audit_command_file to
false inside the global that /yuneta/agent/yuneta_agent.json already
has, next to the keys there, and restart the agent. Do not add a second
global: a JSON object keeps only one of two keys with the same name, so the
other keys (agent.agent_environment, and the log of the agent with it) are
lost. With the keys of the packaged file:
{
"global": {
"agent.agent_environment": {
"daemon_log_handlers": {
"to_file": {
"filename_mask": "W.log"
}
}
},
"controlcenter.jwt": "",
"authz.master": true,
"authz.authz_service": "agent",
"agent.use_audit_command_file": false
},
"environment": {
"node_owner": "none"
}
}(The rest of the file, such as __json_config_variables__, stays as it is.)
A read-only command (
list-*,view-*,stats,nodes,help, …) is recorded with the command, the date and the user only. A command with a__reset__value (stats-yuno stats=__reset__) is not read-only.Any other command also gets its
source(the console purpose and each inter-yuno hop: role, yuno, service, user, host) and its parameters.A
content64(a binary, a config) is never written: only its size and the sha256 of the decoded content.A secret (a parameter named like
password,pwd,secret,token,jwt,api_key,cookie,authorization,private_key, …) is never written: its value is<redacted>, whatever else the name holds:api_key_max,token_modeandtoken_endpointare redacted here, while the traces show them (a name ABOUT a credential:is_secret_name_any(). Up to 7.25.21 the record wrote them in clear). So is whatevermask_secrets_inline()masks in a string, by the same rules and the same function (mark_secrets_inline()): a JWT or a JWE (two parts or more), the credential afterBearerorBasic, aname: valueof a secret’s name (X-Auth-Token: xisX-Auth-Token: <redacted>), every word of a password written with blanks, and, stricter than the SDK, the word afterBearerwhatever it is. Up to 7.26.9 the record’s JWT was three parts exactly, and a JWE was written in clear. Wherever they are: also in theuser, the hops ofsource, the console purpose and the console name, which a peer sends (a field of those longer than 1024 bytes is written as its size and sha256 only). For example a hop whose user is a JWT and whose host has 4095 bytes is written"user":"<redacted>","host":"<4095 bytes, not scanned, sha256:HEX>".The command word is taken as the command parser takes it (any case, quotes, aliases):
WRITE-TTYandEV_WRITE_TTYarewrite-tty.The scan of a command is one pass in linear time, and one record scans at most 128 MB: a longer string is written as its size and sha256 only.
Every record is flushed to the file before the command runs.
A console keystroke (
write-tty) keeps only the fact: who, when, which console, how many writes and bytes. Nothing of what was typed, not even a hash. The writes of one user into one console make one burst of up to 60 seconds: its first write is recorded at once, the rest in one record when the burst ends.
{"command":"list-yunos","date":"2026-09-24T10:00:00.000000000+0200","user":"operator@example.com"}
{"command":"install-binary id=auth_bff content64='<33554432 bytes sha256:401b36b9…>'","date":"…","user":"yuneta","kw":{}}
{"command":"set-user-pwd username=bob password=<redacted>","date":"…","user":"yuneta","kw":{}}
{"command":"write-tty","date":"…","user":"operator@example.com","console":"console-1","writes":1,"bytes":1}
{"command":"write-tty","date":"…","user":"operator@example.com","console":"console-1","writes":212,"bytes":230,"until":"…"}Up to 7.25.4 an install-binary of a 32 MB yuno wrote 134 MB (the base64 three
times). Now it writes about 500 bytes.
A day that crosses max_megas_audit_file (500 MB) continues in .OLD.1,
.OLD.2 and so on. No piece of a day is removed. The attribute audit_keep_days
(default 7, 0 = keep all) is the retention: at start, and when a new audit
file begins (inside the write of its first record, also while the disk is
below min_free_disk_percentage), the agent removes the
audit files older than that and logs one INFO line with their names. Only
files with the name shape of the audit mask are removed. A clock set back
across midnight empties no audit file. For example, to keep 30 days, put this in
/yuneta/agent/yuneta_agent.json and restart the agent:
{
"global": {
"agent.audit_keep_days": 30
}
}An old audit/ directory from 7.25.4 or earlier needs no manual cleaning: the
first start removes what is older than audit_keep_days. Details and the full
list of read-only commands in the agent’s audit files.
Listing the node’s directories¶
The dir-* commands list a directory tree of the node: dir-yuneta,
dir-realms, dir-repos, dir-store (subdirectory= below /yuneta,
/yuneta/realms, /yuneta/repos, /yuneta/store, and match= a regular
expression of the names), dir-logs and dir-local-data (id= of a yuno).
The data is the list of full paths, sorted:
ycommand -c 'dir-store subdirectory=mqtt_broker match=.*\.json'A tree that cannot be listed -- the directory does not exist, cannot be
opened or cannot be read, a match that is not a regular expression, no
memory for an entry -- answers -1, and says which directory. The cause is
in the agent’s log:
-1: yuneta_agent^agent: cannot list '/yuneta/store/nope', see the logUp to 7.25.4 each of them answered an EMPTY list with result 0, which reads
as “the directory is empty”. A SUBdirectory the agent cannot open is skipped,
as before. (tests/c/helpers/test_dir_listing.)
Deleting records: the delete-* commands¶
Five commands delete records of the agent’s treedb, and each one needs an
id=. Without it the filter is empty and selects every record of the
topic, so the command refuses (“delete-config needs an id: without one it
selects every configuration”). Up to 7.29.3 they ran: delete-binary force=1
with no id deleted every binary, those in use too.
| Command | Deletes | Also |
|---|---|---|
delete-binary | a binary record and its directory /yuneta/repos/<tags>/<role>/<version>, or, without version= or with the primary’s, every version of the id | version=, force=1, record_only=1 |
delete-config | a configuration, or, without version= or with the primary’s, every version of the id | version=, force=1 |
delete-yuno | a release of a yuno, or the yuno. It deletes the release of the primary, when there are others, only with whole=1 | yuno_release= or whole=1 (one of them, not both), force=1 |
delete-realm | a realm with no yunos | force=1 |
delete-public-service | a public service | force=1 |
ycommand -c 'delete-binary id=emailsender version=7.29.2'
ycommand -c 'delete-config id=emailsender version=3'
ycommand -c 'delete-yuno id=7601 whole=1'
ycommand -c 'delete-realm id=stress.example.com'
ycommand -c 'list-public-services' # the id of a public service is a number
ycommand -c 'delete-public-service id=3'
ycommand -c 'delete-config version=3' # refused: no iddelete-binary and delete-config without version= delete the record of
every version of the id, not only the primary’s: the delete of the primary
takes the whole key, and so does version= with the primary’s own version.
Then every version taken is checked by the guards, delete-binary removes the
directory of each, and the answer counts them all. Up to 7.29.3 the directories
of the versions that were not the primary stayed in /yuneta/repos. To remove
one version and keep the others, name a version that is not the primary
(list-binaries-instances, list-configs-instances).
The “in use” guard reads the yunos of every version taken. Each version
has its own list: a yuno is linked to the version it was created on
(create-yuno … role_version=1.0). The lists can overlap: a version installed
later starts with a copy of the list of the primary at its install (a new
version of a record takes the links of the primary), so it can name yunos that
use another version. A yuno that two lists name counts once. Up to 7.29.3 only
the list of the record given was read, so a yuno that used an older version
did not stop the delete of the primary, which took that version too:
ycommand -c 'delete-binary id=my_role'
# my_role 1.0 is used by a yuno, 2.0 (the primary) by none: refused
# "…: cannot delete binary 'my_role': the delete of its primary takes its 2 versions, and 1 yunos use it (use force=1 to override)"The delete of ONE version (not the primary) counts only the yunos that use
THAT version (role_version for a binary, name_version for a
configuration). So a version whose list it took from the primary, and that no
yuno uses, is deleted:
# my_role 1.0 is used by yuno y9; 2.0 was installed after y9 was created, so
# its list names y9 too; 3.0 is the primary
ycommand -c 'delete-binary id=my_role version=2.0' # deleted: y9 uses 1.0
ycommand -c 'delete-binary id=my_role version=1.0' # refused: y9 uses itdelete-yuno yuno_release= with the release of the primary is not one
release: the delete of the primary takes every release of the yuno. When the
yuno has other releases, the command refuses it and asks for whole=1. Up to
7.29.3 it deleted every release. yuno_release= and whole=1 together are
refused, whatever the release: the command does not guess which delete was
meant. Up to 7.29.3 whole=1 with a release other than the primary’s deleted
that release only:
ycommand -c 'delete-yuno id=7601 yuno_release=1.1.0-2' # a release behind the primary: deleted
ycommand -c 'delete-yuno id=7601 yuno_release=1.2.0-2' # the primary's, with others: refused
ycommand -c 'delete-yuno id=7601 whole=1' # the yuno and every release
ycommand -c 'delete-yuno id=7601 yuno_release=1.1.0-2 whole=1' # refused: one or the otherA delete that takes the whole yuno also removes the attributes the yuno saved
of its own. That is delete-yuno whole=1, and delete-yuno yuno_release=
with the yuno’s only release (since 7.30.24, and up to 7.30.23 only whole=1
removed them). The attributes are the file of the persistent attrs of its
C_YUNO, <domain_dir>/data/C_YUNO-<yuno_name>-persistent-attrs.json (its trace
levels, and what was written to its __yuno__ with persistence). An INFO
“Saved attrs of a yuno deleted whole removed” names the path. The rest of
its data stays. Up to 7.30.22 the file survived the delete, and a yuno created
again with the same id started with the old trace on and traced false:
ycommand -c 'trace-on-yuno id=7601 level=machine'
ycommand -c 'kill-yuno id=7601'
ycommand -c 'delete-yuno id=7601 whole=1'
# removed: /yuneta/realms/<owner>/<realm>/<role>^7601/data/C_YUNO-<name>-persistent-attrs.json
ycommand -c 'create-yuno id=7601 realm_id=<realm> yuno_role=<role> yuno_name=<name>'
ycommand -c 'run-yuno id=7601' # starts with no traceThe same with the yuno’s only release (list-yunos id=7601 shows one row):
ycommand -c 'kill-yuno id=7601'
ycommand -c 'delete-yuno id=7601 yuno_release=1.2.0-2' # its only release: the yuno is gone
# removed: /yuneta/realms/<owner>/<realm>/<role>^7601/data/C_YUNO-<name>-persistent-attrs.jsonThe agent knows the domain_dir it gives a yuno, not one fixed in the yuno’s
binary: logcenter and webstats save in realms/agent/<role> whatever
their id, so their file is not removed. Reset their trace with
trace-off-yuno while the yuno runs, before kill-yuno. delete-yuno
refuses a running yuno, and trace-off-yuno of a stopped yuno changes
nothing (it answers -1, “not connected to the agent”):
ycommand -c 'trace-off-yuno id=7602' # 0: the yuno runs, its saved trace is reset
ycommand -c 'kill-yuno id=7602'
ycommand -c 'delete-yuno id=7602 whole=1'The data of a delete-binary answer has one item per version taken, with
its files and whether the agent removed them:
[{"id": "emailsender", "version": "7.29.2", "files": "/yuneta/repos/yuneta/utils/emailsender/7.29.2", "removed": true}]A directory the agent cannot remove has "removed": false, and so has one it
cannot look at (it cannot tell whether the directory is there, for example
without permission on a parent directory). A directory that is not there is
"removed": true: its path does not exist, or a part of it is not a
directory (ENOTDIR: then no directory can be at that path). The error is in the log, the record is deleted all the same, and the answer is an error
(-1) that counts the records deleted and names the directories to remove by
hand: “…: 1 binaries deleted, 1 of them with files the agent could not remove
(see the log): remove them by hand: [”/yuneta/repos/yuneta/utils/emailsender/7.29.2"]".
Up to 7.29.3 a failed removal was not looked at, and the answer said only
“1 binaries deleted”. A directory that the agent failed to look at was not
removed and was not named.
A delete that the treedb refuses stops there, and the answer names it, with
its cause and what was deleted before it, which is in the data:
“…: binary ‘emailsender’ version ‘7.29.2’ NOT deleted: ; before it,
0 binaries deleted”. delete-config, delete-realm and
delete-public-service answer the same way, and their data lists only
what was deleted. Up to 7.29.3 the answer was the cause alone, the data of
delete-realm and delete-public-service named the record that failed as
if deleted, and delete-config lost its data (a leak in the agent).
The <cause> is what the delete logged as an ERROR. When it logged none,
the cause is “(see the log)”: the treedb refuses a record that still has
links with a WARNING (“has down links”, “has up links”), and the
WARNING is in the log. For example
“…: realm ‘r2’ NOT deleted: (see the log); before it, 0 realms deleted”.
Up to 7.29.3 that cause was empty, or the cause of an older, unrelated
failure. delete-yuno gives the same cause, and so do the creates and
updates that answer one: create-realm, update-realm,
update-public-service, install-binary, update-binary,
create-config, update-config and create-yuno (for example
“…: Cannot create realm: (see the log)”). Up to 7.29.3 those named an
empty cause, or the cause of an older failure, when the treedb refused
with a WARNING.
delete-binary record_only=1 deletes the record and leaves its files, and
says where they are, in the comment and in the data ("removed": false):
“… remove its files by hand: [”/yuneta/repos/yuneta/utils/emailsender/7.29.2"]". The guards of each
command (in use, tagged by a snap, running) are in
the yuno lifecycle.
Other commands act on EVERY record when they have no filter, by design:
kill-yuno, run-yuno, command-yuno and the rest of the list in
bulk when unfiltered.
A content64 that is not what it must be¶
A create-config or update-config whose content64 decodes to nothing,
or to text that is not json (its #^^ comments removed), answers -1
“…: Bad json in content64”. The log gets ONE WARNING with the position of
the error and the length, and nothing of the content: a config holds keys
under names that no mask knows.
create-config id=x content64=aGVsbG8=
-1 "yuneta_agent^node: Bad json in content64"
WARNING {"msgset": "Parameter", "msg": "content64 of a config is not json, refused",
"command": "create-config", "error": "'[' or '{' expected", "line": 1, "column": 5, "len": 5}Up to 7.30.26 these were ERRORs with a stack (“len is ZERO”, “json_loads() FAILED”), and a dump of the whole config.
The comments of a config (#^^ to the end of the line) are cut and the lines
joined before it is read. A config that is json as it is, but not once its
comments are cut, has a #^^ inside a string: the WARNING says so, with the
place of that mark (up to 7.30.26 it said “not json”, with an empty error
and no position).
create-config id=x content64=<base64 of {"__version__": "1", "pw": "ab#^^cd"}>
-1 "yuneta_agent^node: Bad json in content64"
WARNING {"msgset": "Parameter",
"msg": "content64 of a config is not json once its comments are removed, refused",
"command": "create-config", "comment_mark": "#^^", "line": 1, "column": 31, "len": 37}A config must be a json object, and its __version__ and __description__
strings. Another shape answers the same -1, with ONE WARNING (“content64 of
a config is not a json object, refused”, or “content64 of a config with a
key of its own that is not a string, refused” and the key). Up to 7.30.26
it was “path MUST BE a json str”, an ERROR with a stack, up to two per
order.
create-config id=x content64=<base64 of [1, 2]>
create-config id=x content64=<base64 of {"__version__": 5}>A gbuffer key (the name of the binary field of a kw) is dropped from the
config, with one WARNING, wherever it is, and also when the comment cut makes
it: "gbu and ffer" on two lines, or "gbu#^^ a comment and ffer".
Up to 7.30.26 only the key written whole was dropped, and those two were
stored.
A write-tty to a name that is no open console, or to a service that is
not a console (__yuno__, agent), logs one WARNING (“console not found”,
“not a console”) and answers EV_TTY_CLOSE with that name. One without
content64 logs one WARNING (“content64 required”) and is dropped. Up to
7.30.26 name=__yuno__ gave “Event NOT DEFINED in state” with a stack,
name=agent made the agent send the write to itself, and a missing
content64 was an ERROR.
Consoles¶
open-console opens a console (a pseudo terminal running process) and
routes it to who asked: a session of the agent, or the control center’s link.
Another open-console of the same name adds a route, and every route gets
the console’s EV_TTY_OPEN, its output (EV_TTY_DATA) and its
EV_TTY_CLOSE:
ycommand -c 'open-console name=c1 process=bash cwd=/yuneta' # this session gets c1
ycommand -c 'open-console name=c1' # another session joins it
ycommand -c 'write-tty name=c1 content64=bHMK' # both get the output of `ls`
ycommand -c 'close-console name=c1' # both get EV_TTY_CLOSEThe agent sends them as it sends its answers: an inter-event, with
EV_SEND_IEV, to the channel of the session or to the link, while it is
listening. Up to 7.30.26 a console opened by a session never reached it: the
agent sent the events to the session’s channel, which takes no such event (an
ERROR “Event NOT DEFINED in state” with a stack per frame).
Whose console it is¶
A console belongs to the route that opened it. The routes that join it come and go:
A session that only joined the console leaves: its route goes off the console, and the console goes on for the others.
The session that opened the console leaves: the console is closed (its process is killed), and every session still joined gets its
EV_TTY_CLOSE.Through the control center, the link is one route for all its operators, and it stays while the link comes and goes: a console opened through the control center lives until
close-console, or until its process ends.
# session A
ycommand -c 'open-console name=j1 process=bash cwd=/yuneta'
# session B joins, and leaves: j1 goes on for A
ycommand -c 'open-console name=j1'
# A leaves: B (if it is still joined) gets EV_TTY_CLOSE of j1A route is tied to the session, not to the name of its channel: the channels of the agent are a pool, and the next session of a channel never gets the console of the last one, whatever card that session presented (a session that presented the card of a yuno too). Up to 7.30.26 a session that only joined a console closed it for everybody when it left, without telling them, and the console of a session that presented the card of a yuno outlived it and wrote to the next session of its channel. A route that is not listening (the link to the control center out of session) is said once, an INFO “requester gone before its answer, answer dropped”, not once per chunk of output as up to 7.30.26.
A session that reads slowly, or not at all¶
A console has flow control. When a route of it (a session, or the link to
the control center) has console_pause_tx_queue messages or more waiting in
its transport (default 256, and a message carries up to 1 KB of output, about
2 KB on the wire), or console_pause_tx_bytes bytes or more (default
1048576, measured as the transport’s cur_tx_bytes), the console stops reading its
terminal: the process behind it waits on its write,
as behind an ssh that does not read, and nothing is lost. The console reads
again when that transport has sent everything (its EV_TX_READY). So a
session that reads slowly gets ALL the output, at its pace. While one route
holds the console paused, the other routes wait too.
A route that holds the console paused for console_pause_timeout (default
30000 ms) with its transport taking nothing in that period, while it
stops another route of the console, is taken off the console: it gets the
console’s EV_TTY_CLOSE after what it has waiting, the agent logs ONE
WARNING, and the console goes on for the other routes. When that route is the
one that opened the console, the console is closed for everybody. Who stops
whom:
A route that only joined the console always stops the one that opened it: a spectator that does not read is taken off at its deadline.
The route that opened the console stops the others only when another route of it holds no pause and takes its events (it is ready to read). Alone on its console, or with joined routes that hold a pause too, or that take nothing now (the link to the control center while it is down), it freezes only itself: the console stays paused and its process waits, for as long as the reader is away. A session that leaves takes its console with it. Through the control center the link (the route of all its operators) keeps its consoles while the control center is away or does not read, and they go on when it reads again.
A route is judged only for a whole period in which it stopped another route. When it starts to stop one (a session joins the console of a reader that waits alone, another route releases its pause, the link to the control center returns), its period starts again then. So a session that joins the console of a reader that is away gives that reader a whole
console_pause_timeoutfrom the join: if the reader still takes nothing, it is taken off then (and the console closed, as it opened it), never at the deadline it had before the join. Before the fix the join closed the console, and killed its process, at that deadline: anywhere from at once toconsole_pause_timeoutafter the join.
t=0 A opens `top` and stops reading: the console pauses (A waits alone)
t=28s B joins: A stops B from now on, its period starts again
t=58s A took nothing since the join: A is taken off, the console closed,
B gets EV_TTY_CLOSE
(before the fix: at t=30s, 2 s after the join)A transport that took something in the period gets another period, so a
reader that is merely slow keeps the console. What the agent measures is the
transport’s txBytes, the bytes its socket took, counted on every write in
clear and over TLS. A write ends as the socket’s send buffer drains, and the
kernel wakes it only when a good part of that buffer (it grows up to 4 MB) is
free again: a reader must take that much per period. With the default 30 s
that is some tens of KB/s or more. Raise console_pause_timeout for slower
links.
When the transport of a route drops its connection (the link to the
control center goes down), what it had waiting goes with it, and no drain of
it will come: the pause of that route is released at once (EV_DISCONNECTED
of the transport). The console runs again. Its output for the link is
dropped while the link is down (ONE INFO “requester gone before its answer,
answer dropped”), and it goes up the next connection.
Before the fix the progress was the transport’s txMsgs, which C_TCP did
not count over TLS: a reader over wss or the link to the control center
was taken off at its first deadline, and a console opened through the
control center was closed (its process killed) when the control center was
away some 30 s, or when its link stayed down that long.
"msg": "console output not taken by its session, console closed for it",
"console": "j1", "route": "__input_side__.input-2", "peername": "10.0.0.7:51234",
"opener": "no", "detail": "it held the console paused and took nothing",
"console_pause_timeout": 30000, "tx_queue": 257console_max_tx_queue (default 8192) and console_max_tx_bytes (default
33554432, 32 MB) stay as a hard bound, whatever paused the console: a route
over either is taken off the same way (same WARNING, with tx_queue and
tx_bytes). With flow control a route never gets near them. They are there
for a route with no flow control (a transport that is not a C_TCP). 0
turns any bound off. Set them in the agent’s config, under global:
{
"global": {
"agent.console_pause_tx_queue": 256,
"agent.console_pause_tx_bytes": 1048576,
"agent.console_pause_timeout": 30000,
"agent.console_max_tx_queue": 8192,
"agent.console_max_tx_bytes": 33554432
}
}A route keeps only what routes the console’s events back of the request
that opened or joined the console: the stack of its hops
(ievent_gate_stack, where the control center stamps its client’s
connection) and its __msg_type__. Any other key of the request’s
__md_iev__ (a marker of a client) does not return with the console’s
events. The answer of open-console itself still echoes it. Before the fix
the whole __md_iev__ was kept and copied into every chunk of output, and
both bounds counted messages only: a session whose request was padded with
1 MB made every chunk of 1 KB a message of 1 MB, and held 256 of them (the
agent grew 120 MB or more) while it did not read. A hop padded with 1 MB
still makes each message 1 MB: the bound in bytes pauses the console after
one of them.
Up to 7.30.26 there was neither: a session that flooded its console and did
not read grew the agent some 50 MB/s until it aborted (“REACHED
MAX_SYSTEM_MEMORY”), and so did a control center that did not read its link.
Tests: tests/c/c_agent_consoles (a session at 1 MB/s with a small receive
window gets all of 11 MB. A session alone on its console that does not read
keeps it, paused. A joined session that does not read is taken off, and so is
an opener that does not read while a joined session does. A session that
joins 2.5 s before the deadline of a reader away gets a whole period from the
join. A request padded with 1 MB keeps the agent under +25 MB),
tests/c/c_agent_controlcenter_link (the control center away 9 s
keeps its console. A slow TLS link at 30 KB/s keeps it for four deadlines. A
console paused when the link drops is released and lives. The console of a
session that does not read, joined by the control center just before its
link drops, lives the 10 s the link is down).
Watches¶
A watch-yuno-stats is tied to the session that asked it, as a console
route: it goes with the session whatever card it presented, and the next
session of its channel never gets its readings. Up to 7.30.26 the watch of a
session that presented the card of a yuno outlived it.
A yuno that runs but is not connected¶
command-yuno, stats-yuno and authzs-yuno go to every yuno that matches
and is running, through the channel the yuno opened to the agent. A yuno that
runs but has no channel -- starting, not yet connected, or going -- used to
get nothing and answer nothing, so the requester waited for ever (a control
center running a scenario, its step’s whole deadline). Since 7.25.16 the
command is answered at once when it reached none of them,
yuneta_agent^node-a: set-interval: yuno gen1 runs but is not connected to the agent (starting or stopping): nothing sentand when it reached only some, the others are named in a warning of the agent’s log (“yuno running but not connected to the agent, nothing sent to it”): the ones that got it answer on their own.
Answers that come to the agent¶
The agent sends orders on and takes their answers back: command-yuno,
stats-yuno and authzs-yuno to its yunos, command-agent and
stats-agent service=controlcenter up its link to the control center, and
its own readings of a watch (watch-yuno-stats) and publish-stats to the
yunos. An answer is an EV_MT_COMMAND_ANSWER or EV_MT_STATS_ANSWER that
any session of the agent can also send, so the agent takes one only from
where it sent the order:
To an operator through the link.
command-agentandstats-agenttoservice=controlcentergo up with the operator’s channel in__md_iev__.agent_requester, which the control center’s answer echoes. The agent takesagent_requesteronly from an answer that came from the link, and it names only a channel of the agent. Up to 7.30.26 a session with a role for the serviceagentonly was able to send an answer toagentnaming the link (agent_requester: controlcenter), and the agent sent it to the control center with its own identity.To the agent itself. A reading of a watch (
__md_iev__.agent_watch) and the answer to apublish-stats(__md_iev__.agent_publish) are taken only from the channel of the yuno they name: not from a session, and not from the link of another yuno. Up to 7.30.26 any session was able to send the watchers a reading of a yuno, or to make the agent take a yuno as refusing to publish its stats.The acks of play and pause. An
EV_PLAY_YUNO_ACKorEV_PAUSE_YUNO_ACKis taken only from the channel of a yuno: the yuno it acks is the one of that channel. Any session can send one, and so can the control center, whose link has no channel. Up to 7.30.26 the agent read such an ack as a yuno’s, with up to four ERRORs with a stack per ack (“path NOT FOUND”, “gobj NULL”, “hs_yuno NULL”).Back the way the order came. The answer goes back by the hop under the agent’s own in
__md_iev__.ievent_gate_stack, the one of the requester. An answer with no such hop (a session sends one with a single hop, to its own channel), or with a hop that is not a route (src_yuno,src_role,src_servicenot strings), is dropped. Up to 7.30.26 it was sent on with no route, after a WARNING and six ERRORs per answer.To the session that asked. The channels of the agent are a pool: a session takes the first one free, so the next session takes the one that the last one left, and its name (
input-2). Each session of a channel gets an id when it opens, and an order the agent sends on carries the id of its requester in__md_iev__.agent_session. An answer for a session that left is dropped, as one for a requester that closed: “requester gone before its answer, answer dropped” (INFO,"detail": "its channel is another session's now"). Up to 7.30.26 the next session on that channel got it.The play of a
run-yuno, once. Arun-yunothat plays (play=1, the default) keeps its requester, with its session and the launch it made, for the answer of the play of that launch. It is taken out at the first open of the yuno, whatever comes next: the play of that open answers it, if the session that asked still holds its channel. A yuno that does not play by itself (must_playfalse) just drops it. No later play answers it: aplay-yuno, then a relaunch by the watcher after a crash, answer nobody but theplay-yuno’s requester. Up to 7.30.26 a yuno withmust_playfalse kept it, and the next relaunch answered thatrun-yunoagain to whoever held the channel then: the same session, another one, or the yuno itself, whose link to the agent was cut by it. The answer needs no deadline: it cannot outlive the first open.ycommand -c 'run-yuno id=7601' # answered when it opens (must_play false: no play) ycommand -c 'play-yuno id=7601' # answered; must_play is true now # the yuno crashes, its watcher relaunches it and the agent plays it: # nobody is answered (up to 7.30.26 the session of the run-yuno, or # whoever had its channel, got that run-yuno's answer again)
What goes nowhere is a peer’s doing: a WARNING (MSGSET_PROTOCOL, no stack)
with a brake, ONE of each kind per 10 s, with dropped, the answers of that
kind since the last one:
WARNING {"msgset": "Protocol", "msg": "answer naming a requester of a link, not from a link: dropped",
"event": "EV_MT_COMMAND_ANSWER", "requester": "controlcenter", "channel": "C_CHANNEL^input-1", "dropped": 1}
WARNING {"msgset": "Protocol", "msg": "answer for the agent, not from the yuno it names: dropped",
"event": "EV_MT_STATS_ANSWER", "yuno_id": "1", "channel": "C_CHANNEL^input-3", "dropped": 1}
WARNING {"msgset": "Protocol", "msg": "requester of the answer not found: dropped",
"event": "EV_MT_COMMAND_ANSWER", "requester": "nosuch", "channel": "C_CHANNEL^input-1", "dropped": 1}
WARNING {"msgset": "Protocol", "msg": "answer with no route back to its requester: dropped",
"event": "EV_MT_COMMAND_ANSWER", "requester": "input-1", "channel": "C_CHANNEL^input-1", "dropped": 1}
WARNING {"msgset": "Protocol", "msg": "ack not from a yuno: dropped",
"event": "EV_PLAY_YUNO_ACK", "yuno_id": "", "channel": "C_CHANNEL^input-2", "dropped": 1}
WARNING {"msgset": "Protocol", "msg": "console event not from a console: dropped",
"event": "EV_TTY_DATA", "src": "__input_side__", "channel": "C_CHANNEL^input-2", "dropped": 20}
WARNING {"msgset": "Protocol", "msg": "request of the agent not by its command: dropped",
"event": "EV_READ_FILE", "src": "__input_side__", "channel": "C_CHANNEL^input-2", "dropped": 2}Two more kinds are events, not answers, under the same brake:
The events of a console (
EV_TTY_OPEN,EV_TTY_DATA,EV_TTY_CLOSE) are taken only from a console of the agent (aC_PTY). The names are public, so a session can send them too. Up to 7.30.26 each such frame was an ERROR “named dict not found”.The agent’s own requests (
EV_EDIT_CONFIG,EV_VIEW_CONFIG,EV_EDIT_YUNO_CONFIG,EV_VIEW_YUNO_CONFIG,EV_READ_JSON,EV_READ_FILE,EV_READ_BINARY_FILE,EV_READ_RUNNING_KEYS,EV_READ_RUNNING_BIN) come by their commands (edit-config,read-file, ...), which are not changed. Sent as events by a session, they are dropped. Up to 7.30.26 the agent answered them to the gate of its channels, which takes no such event: an ERROR “Event NOT DEFINED in state” with a stack per frame.
The “requester of the answer not found” is an answer whose requester is
no channel of the agent and no link (a dst_service or an
agent_requester that names nothing, an empty dst_service, or a service
of the agent that is not a link: authz). Up to 7.30.26 it was “child not
found”, an ERROR (MSGSET_INTERNAL) for each answer (“name NULL”, with
a stack, for an empty dst_service), and an answer to a service that is no
link was sent to it. An ack from the control center’s link names the
link as its channel: "channel": "C_IEVENT_CLI^controlcenter".
A frame cannot choose what the agent reads as its own: __temp__ (where
C_IOGATE writes the channel a message came in by, a pointer of the
process) is dropped from every inter-event from outside. Up to
7.30.26 a session or the control center that sent "__temp__": [1094795585]
in one of the answers or acks above made the agent read that number as a
gobj, and it died with SIGSEGV.
Orders while the agent stops¶
On a stop the agent pauses first: it closes its treedbs, and the loop goes
on running until it stops. The pause stops whatever brings an order before
it closes them: the operators’ side and the link to the control center (a
play after a pause starts the link again). Up to 7.30.26 the link stayed in
session, and an order of the control center in that window (list-yunos)
read the treedb just freed: the agent died with SIGSEGV instead of ending in
order.
Only a stop pauses the agent. The control center cannot play or pause it:
its link is a C_IEVENT_CLI configured to reach controlcenter, and only a
link configured to reach a yuneta_agent plays or pauses its yuno (see
C_IEVENT_CLI). An EV_PLAY_YUNO or
EV_PAUSE_YUNO that comes on that link is answered with result -1, and the
agent goes on as it was:
{"event": "EV_PAUSE_YUNO_ACK", "kw": {"result": -1,
"comment": "yuneta_agent^node-a: only the link to the yuno's agent plays or pauses the yuno"}}The link logs ONE WARNING per session, “play/pause of the yuno refused:
only the link to its agent plays or pauses it”. Up to 7.30.26 the pause
reached the agent and stopped that same link inside its own action: the
agent died with SIGSEGV when more bytes came in the same read, or it lived
with its 1991 and its link closed, and nobody was able to reach it until it was
restarted on the node.
Tracing a yuno (trace-on-yuno, trace-off-yuno)¶
trace-on-yuno sets GLOBAL trace levels in the yunos that match, and marks
them traced in list-yunos. trace-off-yuno resets every global level of
the yunos that match and marks them not traced. The levels are those of
set-global-trace, the same in every yuno (see
Debugging), and the agent sends
one set-global-trace level=<level> set=1 to the yuno per level asked.
# trace the FSM of yuno 3 and the kw of each of its events
ycommand -c 'trace-on-yuno id=3 level=machine,ev_kw'
# what the yuno traces now
ycommand -c 'command-yuno id=3 service=__yuno__ command=get-global-trace'
# done: every global level of yuno 3 off, `traced` false
ycommand -c 'trace-off-yuno id=3'trace-on-yunowith nolevel, or with a name that is not a global level, answers-1(“what global trace level? …”), sets nothing, and itsdatalists the global levels.A yuno already traced takes more levels:
trace-on-yuno id=3 level=commandsaddscommandstomachineandev_kw.trace-off-yunoresets ALL the global levels of the yuno, also ones set by hand withset-global-trace.The yuno saves its global levels (
__global_trace__), andtracedis a persistent column: both survive a restart of the yuno, untiltrace-off-yuno.With no filter (
id,yuno_role,realm_id, ...) they act on every yuno.They reach only a yuno connected to the agent. A yuno that is stopped, starting or stopping gets nothing: its saved levels and its
tracedstay as they are, and the answer names it. When no yuno is reached the answer is-1. When some are, it is0, with the rows of those reached. The agent logs a WARNING “yuno not connected to the agent, its trace not changed”.
ycommand -c 'kill-yuno id=3'
ycommand -c 'trace-off-yuno id=3'
# -1: "…: trace-off-yuno: yuno 3 not connected to the agent (stopped,
# starting or stopping): its trace not changed" (traced stays true)
ycommand -c 'run-yuno id=3' # it starts with its saved levels again
ycommand -c 'trace-off-yuno id=3' # 0: now they are reset, traced falseBREAKING in 7.30.23: up to 7.30.22 trace-off-yuno of a yuno not
connected answered 0 and set traced false, but nothing reached the yuno:
it kept its saved levels and had them again at its next start, with traced
false. trace-on-yuno set traced true for a yuno it did not reach.
BREAKING in 7.30.22: up to 7.30.21 trace-on-yuno took no level and set
the user levels of the yuno’s root gobj (C_YUNO), which has none: nothing
was traced, only traced changed. It also skipped a yuno already traced
(“Yuno not found or already tracing”), and trace-off-yuno one not traced.
Stats pushed to a watcher (watch-yuno-stats)¶
Since 7.25.13 a client can ask the agent to SEND it the stats of some yunos
every period, instead of asking stats-yuno again and again. It is what the
Monitor workspace of gui_agent uses when it talks to an agent directly.
# every 2 s: the state, the cpu and the stats of each yuno's service
watch-yuno-stats ids=gen1,7601,7501 period=2000
# `id:service` reads another service than the one named as the role
watch-yuno-stats ids=7501:db_events,2 period=5000
# end it (closing the connection ends it too)
watch-yuno-stats stop=1These lines show the parameters. A watch is accepted only from a client that
also says, in the kw of the command, that it takes the pushed event
("__relays__": ["EV_YUNO_STATS"], see below). stop=1 needs no marker. So
typed in ycommand, which cannot take EV_YUNO_STATS, a watch is refused, and
that is the point: ask stats-yuno there.
The answer says what is watched:
yuneta_agent^node-a: watching 3 yunos every 2000 msand from then on the agent sends EV_YUNO_STATS along the route the
request came from -- the way the Terminal’s PTY mirror sends EV_TTY_DATA
-- three kinds per yuno and period, the event’s data being:
{"yuno_id": "7601", "kind": "state", "missing": false,
"yuno_running": true, "yuno_playing": true, "yuno_disabled": false}
{"yuno_id": "7601", "kind": "cpu", "service": "", "result": 0, "comment": "",
"data": {"cpu": 15, "start_date": "...", "uptime": 86400, "mem_rss_kb": 5324,
"mem_node_available_percent": 35, "disk_min_free_percent": 73, "...": "..."}}
{"yuno_id": "7601", "kind": "app", "service": "", "result": 0, "comment": "",
"data": {"txMsgs": 3966, "rxMsgs": 3966, "rxMsgsec": 500, "...": "..."}}A yuno that does not run gets only its state. One watch per requester --
its connection AND the client at the far end of the route, because every web
client of a control center shares that control center’s connection: a new
call replaces the previous one. The client is told by the hop the agent can
trust: directly connected, the hop of the agent’s own input channel, and through
a control center, the hop stamped by the control center -- the channel the
client came in by there (input_channel, since 7.25.15: before, two tabs of
one browser were one requester and shared a watch) and its connection
(cc_connection). Hops deeper in the stack are written by the client as it
likes and are never read: up to 7.25.20 the agent took the LAST one, so a
client was able to add a hop naming another user’s watch, and to stop or replace it. One yuno can be named with several services
(ids=7501,7501:db_events), and an id that is not a yuno of this agent no
longer refuses the whole watch: it is watched, its state says missing, and
the answer names it (data.missing,
“watching 3 yunos every 2000 ms, 1 of them not found here”). A watch lives watch_ttl (60000 ms) unless it
is asked again: behind a control center the agent never sees a browser leave,
so the requester renews it (the answer carries the ttl, and gui_agent renews
every third of it), and one not renewed goes with “watch-yuno-stats not
renewed, expired” in the agent’s log. The readings come ONCE per yuno and
service however many requesters watch it, at the shortest period asked. Since
7.28.11 the agent asks each watched yuno to send them itself
(publish-stats,
one per service, with watch_ttl as its ttl, renewed at half of it, and
stopped when nobody watches that service any more), and only reads them on
loopback (stats-yuno to its own yunos) for the first readings of a new watch
and for a yuno that refuses it -- one built before 7.28.11 (“publish-stats
refused, the agent asks for these stats”, INFO, once per process). period is never
under the attribute watch_min_period (1000 ms), max_watches (30)
bounds the requesters, and max_watch_ids (256) the names in one ids
(“too many yuno ids: 300, max_watch_ids is 256”). A max_watch_ids under 1
is a configuration error: every watch is refused (“max_watch_ids is 0, it
must be 1 or more: no watch taken”) and the agent logs it, once per bad
value. The answer goes first:
the first readings of a new or renewed watch follow it, to that requester
only (up to 7.25.20 they went out before it, and every renewal read every
watch of every requester again). It is not a subscription on purpose: a subscription
travels only from a client to a server, and the agent is the server of its
yunos.
A client that asks for a watch must know EV_YUNO_STATS, and SAY it: a C
client that receives an event it does not know drops the connection, or logs
“Event NOT DEFINED in state” on every one (ycommand, until the watch
expired). So a watch is accepted only if its kw carries __relays__ with the
event -- written by a control center in between (see
the control center: it removes the web client’s own, and
writes it only when the web client’s request named the event), or by a client
connected directly:
{"ids": "7601,7501", "period": 2000, "__relays__": ["EV_YUNO_STATS"]}Otherwise it is refused (“this client does not say it takes EV_YUNO_STATS (relays), ask stats-yuno instead”, or through a control center “the client, or the control center in between, does not say it takes EV_YUNO_STATS (relays), ask stats-yuno instead”) and the requester polls.
When the agent stops, every watch ends with it. The pause of the stop ends
the watches first, so each yuno that publishes gets its publish-stats with
stop while its channel is still open:
{"service": "__yuno__", "stats_service": "__yuno__", "period": 0, "ttl": 60000, "stop": true}Up to 7.30.26 the stop ended the watches after the pause had closed the treedb: the yunos were told nothing, and the log held an ERROR “hgobj NULL or DESTROYED” with a stack.
Redundancy¶
Every node also runs yuneta_agent22, a minimal second
agent kept alive as an escape hatch so a node is never left unmanageable.
Deep dive¶
The agent is documented at length under Operating Yuneta: