Skip to content

Commit 2838f3e

Browse files
committed
docs: add ODOO_DATABASE docs and installer support for multi-database Odoo
- README: document ODOO_DATABASE flag and multi-database workflow - docs/installation.md: document optional database prompt - install.sh: add Odoo database prompt - install.ps1: add ConvertToDotenvValue, Write-DotenvFile, and database prompt - .env.example: add ODOO_DATABASE with documentation comment
1 parent 9436baf commit 2838f3e

5 files changed

Lines changed: 57 additions & 15 deletions

File tree

.env.example

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
# Odoo Agent Runtime Configuration
22
ODOO_URL=http://localhost:8069
3+
# Optional multi-database Odoo: set database name; blank preserves single-database behavior (runtime follows /web/login?db=<URL-encoded database> and retains its session cookie before API calls; never put API keys in URLs).
4+
ODOO_DATABASE=
35
API_KEY=your-runtime-api-key-here
46
RUNTIME_NAME=my-machine
57
POLL_INTERVAL=10

README.md

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ It supports Linux, macOS, and Windows.
1919

2020
1. Create a runtime in Odoo and generate its API key.
2121
2. Install this runtime on the machine that will execute agent CLIs.
22-
3. Enter Odoo URL, API key, runtime name, and poll interval.
22+
3. Enter Odoo URL, optional database name, API key, runtime name, and poll interval.
2323
4. Choose manual mode or background service mode.
2424
5. Confirm the runtime appears online in Odoo.
2525
6. Assign agents to this runtime and send Project tasks to them.
@@ -40,6 +40,7 @@ curl -fsSL https://raw.githubusercontent.com/nicolasramos-es/odoo-agent-runtime/
4040
The installer asks for:
4141

4242
- Odoo URL;
43+
- optional Odoo database name for multi-database instances;
4344
- runtime API key;
4445
- runtime display name;
4546
- polling interval;
@@ -71,6 +72,7 @@ The runtime reads `.env` and accepts CLI flags.
7172
| Variable | Flag | Required | Default | Description |
7273
| --- | --- | --- | --- | --- |
7374
| `ODOO_URL` | `--odoo-url` | No | `http://localhost:8069` | Odoo base URL. |
75+
| `ODOO_DATABASE` | `--odoo-database` | No | empty | Database name for a multi-database Odoo instance. When set, the runtime follows `/web/login?db=<URL-encoded database>` before runtime API calls and retains the selected database's session cookie. Omit or leave blank to preserve single-database behavior. |
7476
| `API_KEY` | `--api-key` | Yes | empty | Runtime API key generated in Odoo. |
7577
| `RUNTIME_NAME` | `--name` | No | host name | Display name shown in Odoo. |
7678
| `POLL_INTERVAL` | `--poll-interval` | No | `10` | Seconds between polling cycles. |
@@ -80,11 +82,14 @@ Example:
8082
```bash
8183
python3 daemon.py \
8284
--odoo-url https://odoo.example.com \
85+
--odoo-database "customer-production" \
8386
--api-key "YOUR_RUNTIME_KEY" \
8487
--name "agent-worker-01" \
8588
--poll-interval 5
8689
```
8790

91+
`ODOO_DATABASE` is optional. Use it only when the Odoo server hosts multiple databases. The database selection request follows redirects and keeps the resulting session cookie for subsequent runtime API calls. Do not put API keys in URLs; configure `API_KEY` through `.env` or `--api-key`.
92+
8893
## Command placeholders
8994

9095
Odoo sends each agent's `cli_command`. The runtime replaces these placeholders:
@@ -129,6 +134,7 @@ See [`docs/engine-examples.md`](docs/engine-examples.md) for Codex, Hermes, Open
129134
| --- | --- |
130135
| `API key is required` | Set `API_KEY` in `.env` or pass `--api-key`. |
131136
| Runtime does not appear online | Check `ODOO_URL`, API key, firewall, and Odoo logs. |
137+
| Runtime stops before API calls on a multi-database server | Verify `ODOO_DATABASE` matches the database name and that `ODOO_URL` can reach its login page. Leave `ODOO_DATABASE` blank for a single-database server. |
132138
| Execution remains queued | Confirm the agent is assigned to this runtime and the daemon is running. |
133139
| Execution fails with CLI not found | Install the CLI on this host or fix the agent `cli_command` in Odoo. |
134140
| Service does not start | Run the daemon manually first, then inspect system logs. |

docs/installation.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,12 @@ Scheduled Task mode is available from the installer when selected.
5757
| Runtime name | `agent-worker-01` |
5858
| Poll interval | `10` |
5959

60+
### Optional Odoo database
61+
62+
`ODOO_DATABASE` is optional for a single-database Odoo deployment. Provide it when the Odoo URL serves multiple databases, or when your runtime must always target one specific database. On Linux and macOS, enter it at the `install.sh` prompt; on Windows, enter it at the `install.ps1` prompt. Each installer writes an empty value when it is not needed.
63+
64+
Keep the runtime API key separate from the Odoo URL. Enter it only at the **Runtime API key** prompt; never append it to a URL, query string, bookmark, or command history.
65+
6066
## Existing `.env`
6167

6268
The installer does not silently overwrite `.env`. If `.env` exists, it asks before replacing it. If you decline, it writes `.env.new` and does not install/start a background service with stale settings.

install.ps1

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,24 @@ function AskYesNo($Prompt, $Default = "no") {
1616
if (-not $value) { $value = $Default }
1717
return $value.ToLower() -in @("y", "yes")
1818
}
19+
function ConvertToDotenvValue($Value) {
20+
if ($Value -match "[\r\n]") {
21+
throw "Configuration values cannot contain line breaks."
22+
}
23+
# python-dotenv decodes backslash and double-quote escapes in double quotes.
24+
# Dollar signs and backticks are already literal, so escaping them corrupts values.
25+
return $Value.Replace('\', '\\').Replace('"', '\"')
26+
}
27+
function Write-DotenvFile($Path) {
28+
@(
29+
"# Odoo Agent Runtime Configuration"
30+
('ODOO_URL="{0}"' -f (ConvertToDotenvValue $OdooUrl))
31+
('ODOO_DATABASE="{0}"' -f (ConvertToDotenvValue $OdooDatabase))
32+
('API_KEY="{0}"' -f (ConvertToDotenvValue $ApiKey))
33+
('RUNTIME_NAME="{0}"' -f (ConvertToDotenvValue $RuntimeName))
34+
('POLL_INTERVAL="{0}"' -f (ConvertToDotenvValue $PollInterval))
35+
) | Out-File -FilePath $Path -Encoding ASCII
36+
}
1937

2038
Write-Host ""
2139
Write-Host "Odoo Agent Runtime Installer (Windows)"
@@ -38,6 +56,7 @@ if (-not $python) {
3856
Log "Python found"
3957

4058
$OdooUrl = Ask "Odoo URL" "http://localhost:8069"
59+
$OdooDatabase = Ask "Odoo database (optional; required for multi-database Odoo)"
4160
$ApiKey = Ask "Runtime API key"
4261
while ([string]::IsNullOrWhiteSpace($ApiKey)) {
4362
Err "Runtime API key cannot be empty."
@@ -69,13 +88,7 @@ if ((Test-Path $envFile) -and -not (AskYesNo "Existing .env found. Overwrite it?
6988
Warn "Keeping existing .env. Writing new configuration to .env.new."
7089
}
7190

72-
@"
73-
# Odoo Agent Runtime Configuration
74-
ODOO_URL=$OdooUrl
75-
API_KEY=$ApiKey
76-
RUNTIME_NAME=$RuntimeName
77-
POLL_INTERVAL=$PollInterval
78-
"@ | Out-File -FilePath $envFile -Encoding ASCII
91+
Write-DotenvFile $envFile
7992
Log "$(Split-Path -Leaf $envFile) written"
8093
if ((Split-Path -Leaf $envFile) -ne ".env") {
8194
Warn "Scheduled Task creation skipped because the active .env was not overwritten."

install.sh

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,26 @@ ask_yes_no() {
2929
*) return 1 ;;
3030
esac
3131
}
32+
dotenv_value() {
33+
local value="$1"
34+
if [[ "$value" == *$'\n'* || "$value" == *$'\r'* ]]; then
35+
error "Configuration values cannot contain line breaks."
36+
exit 1
37+
fi
38+
# python-dotenv decodes backslash and double-quote escapes in double quotes.
39+
# Dollar signs and backticks are already literal, so escaping them corrupts values.
40+
printf '%s' "$value" | sed -e 's/\\/\\\\/g' -e 's/"/\\"/g'
41+
}
42+
write_env_file() {
43+
{
44+
printf '%s\n' '# Odoo Agent Runtime Configuration'
45+
printf 'ODOO_URL="%s"\n' "$(dotenv_value "$ODOO_URL")"
46+
printf 'ODOO_DATABASE="%s"\n' "$(dotenv_value "$ODOO_DATABASE")"
47+
printf 'API_KEY="%s"\n' "$(dotenv_value "$API_KEY")"
48+
printf 'RUNTIME_NAME="%s"\n' "$(dotenv_value "$RUNTIME_NAME")"
49+
printf 'POLL_INTERVAL="%s"\n' "$(dotenv_value "$POLL_INTERVAL")"
50+
} > "$ENV_FILE"
51+
}
3252

3353
OS="$(uname -s | tr '[:upper:]' '[:lower:]')"
3454
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
@@ -58,6 +78,7 @@ log "Python found: $($PYTHON --version)"
5878
printf '\n'
5979
info "Configuration"
6080
ODOO_URL="$(ask 'Odoo URL' 'http://localhost:8069')"
81+
ODOO_DATABASE="$(ask 'Odoo database (optional; required for multi-database Odoo)')"
6182
API_KEY="$(ask 'Runtime API key')"
6283
while [ -z "$API_KEY" ]; do
6384
error "Runtime API key cannot be empty."
@@ -98,13 +119,7 @@ if [ -f "$ENV_FILE" ] && ! ask_yes_no "Existing .env found. Overwrite it?" "no";
98119
warn "Keeping existing .env. Writing new configuration to .env.new."
99120
fi
100121

101-
cat > "$ENV_FILE" <<EOF
102-
# Odoo Agent Runtime Configuration
103-
ODOO_URL=$ODOO_URL
104-
API_KEY=$API_KEY
105-
RUNTIME_NAME=$RUNTIME_NAME
106-
POLL_INTERVAL=$POLL_INTERVAL
107-
EOF
122+
write_env_file
108123
log "$(basename "$ENV_FILE") written"
109124
if [ "$(basename "$ENV_FILE")" != ".env" ]; then
110125
warn "Background service install skipped because the active .env was not overwritten."

0 commit comments

Comments
 (0)