iz
Clone
https://git.tahinli.com/Tahinli/iz.git
0 watching0 forksRustAGPL-3.0567.3 KiB3950aceTahinli27 days ago34 commits
| 1 | //! The operator command line: the words `iz` takes after its options, the lock that keeps two processes off |
| 2 | //! one data directory, and the helpers the commands share. |
| 3 | //! |
| 4 | //! Commands: `iz [--config <path>] [serve]` runs the server (a bare `iz` does the same), `export --out <dir>` |
| 5 | //! writes the board to a new directory, `restore --from <set dir>` replaces the database and attachments |
| 6 | //! with a verified backup set, and `fsck` checks the database and attachments without changing them. The |
| 7 | //! configuration file is the `--config` path, then `IZ_CONFIG`, then `config/iz.toml`. Exit status 0 is |
| 8 | //! success, 1 a failure, 2 a usage error. |
| 9 | //! |
| 10 | //! The lock: every command that touches the data directory takes an exclusive lock on `iz.lock` inside it, |
| 11 | //! held for the life of the process. A second process that finds the lock taken stops at once. What it is |
| 12 | //! not: the lock does not protect the files from other users; the data directory is mode 0700 for that. |
| 13 | |
| 14 | |
| 15 | |
| 16 | |
| 17 | |
| 18 | use ; |
| 19 | use OpenOptionsExt; |
| 20 | use ; |
| 21 | use ExitCode; |
| 22 | |
| 23 | use ; |
| 24 | use Config; |
| 25 | use secret; |
| 26 | |
| 27 | use crateKEY_FILE; |
| 28 | |
| 29 | /// The file inside the data directory that carries the process lock. |
| 30 | pub const LOCK_FILE: &str = "iz.lock"; |
| 31 | |
| 32 | /// The line printed when another process holds the lock. Operators search for it, so it is fixed. |
| 33 | pub const BUSY_MESSAGE: &str = "iz is already running on this data directory; stop it (systemctl stop iz) before running this command"; |
| 34 | |
| 35 | /// The configuration file when neither `--config` nor `IZ_CONFIG` names one. |
| 36 | pub const DEFAULT_CONFIG: &str = "config/iz.toml"; |
| 37 | |
| 38 | /// The environment variable that names the configuration file. |
| 39 | pub const CONFIG_ENV: &str = "IZ_CONFIG"; |
| 40 | |
| 41 | /// The parsed command line. `--config` is global, so it works before or after the command word. |
| 42 | |
| 43 | |
| 44 | |
| 45 | |
| 46 | |
| 47 | |
| 48 | |
| 49 | |
| 50 | |
| 51 | |
| 52 | |
| 53 | |
| 54 | |
| 55 | |
| 56 | /// The commands. `Serve` is the default. |
| 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 | /// The configuration path: the flag, else `IZ_CONFIG`, else the default. |
| 83 | |
| 84 | |
| 85 | |
| 86 | |
| 87 | |
| 88 | /// Takes the exclusive lock on `data_dir/iz.lock`. The returned file holds the lock until it is dropped, |
| 89 | /// so bind it to a variable that lives as long as the work does. A busy lock gives [`BUSY_MESSAGE`]; any |
| 90 | /// other failure names the lock file. |
| 91 | |
| 92 | |
| 93 | |
| 94 | |
| 95 | |
| 96 | |
| 97 | |
| 98 | |
| 99 | |
| 100 | |
| 101 | |
| 102 | |
| 103 | |
| 104 | |
| 105 | |
| 106 | |
| 107 | |
| 108 | |
| 109 | |
| 110 | |
| 111 | /// Prints the failure of [`lock_data_dir`] and gives the exit status 1. |
| 112 | |
| 113 | |
| 114 | |
| 115 | |
| 116 | |
| 117 | |
| 118 | |
| 119 | /// Prints `iz: <message>` to stderr and gives the exit status 1. |
| 120 | |
| 121 | |
| 122 | |
| 123 | |
| 124 | |
| 125 | /// The text of an iz-core error for the user. A refused set or an invalid value is shown as its text |
| 126 | /// alone; everything else keeps its prefix. |
| 127 | |
| 128 | |
| 129 | |
| 130 | |
| 131 | |
| 132 | |
| 133 | |
| 134 | /// The data directory as an absolute path. It must exist: the commands that call this never create it. |
| 135 | |
| 136 | |
| 137 | |
| 138 | |
| 139 | |
| 140 | |
| 141 | |
| 142 | |
| 143 | |
| 144 | /// The instance key read from the data directory. It must exist: the commands that call this check or write |
| 145 | /// manifests under it, and never create a key on the way. |
| 146 | |
| 147 | |
| 148 | |
| 149 | |
| 150 | |
| 151 | |
| 152 | |
| 153 | |
| 154 | |
| 155 | |
| 156 | |
| 157 | /// The database path, checked to be a regular file that is not a link. Nothing is created. |
| 158 | |
| 159 | |
| 160 | |
| 161 | |
| 162 | |
| 163 | |
| 164 | |
| 165 | |
| 166 | |
| 167 | |
| 168 | |
| 169 | |
| 170 | |
| 171 | |
| 172 | |
| 173 | |
| 174 | /// A UTC stamp that is safe in a file name: `20261028T093015Z`. |
| 175 | |
| 176 | |
| 177 | |
| 178 | |
| 179 | |
| 180 | |
| 181 | |
| 182 | |
| 183 | |
| 184 | |
| 185 | |
| 186 | |
| 187 | |
| 188 | |
| 189 | |
| 190 | |
| 191 | |
| 192 | |
| 193 | |
| 194 | |
| 195 | |
| 196 |