Use BOT_STATE_DIR for matrix state storage
This commit is contained in:
parent
b4fd06ef51
commit
145a3e70c3
4 changed files with 12 additions and 9 deletions
|
|
@ -14,7 +14,6 @@
|
||||||
"user_id": "@my-bot-name:matrix.org",
|
"user_id": "@my-bot-name:matrix.org",
|
||||||
"password": "hunter2",
|
"password": "hunter2",
|
||||||
"device_name": "bot.mydomain.com",
|
"device_name": "bot.mydomain.com",
|
||||||
"store_path": "dev.data/",
|
|
||||||
"verify_ssl": true
|
"verify_ssl": true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -78,6 +78,10 @@ in
|
||||||
wantedBy = [ "multi-user.target" ];
|
wantedBy = [ "multi-user.target" ];
|
||||||
wants = [ "network-online.target" ];
|
wants = [ "network-online.target" ];
|
||||||
after = [ "network-online.target" ];
|
after = [ "network-online.target" ];
|
||||||
|
script = ''
|
||||||
|
export BOT_STATE_DIR="''${STATE_DIRECTORY}"
|
||||||
|
exec ${cfg.package}/bin/matrix-ops-bot
|
||||||
|
'';
|
||||||
environment = {
|
environment = {
|
||||||
BOT_CONFIG_FILE = "%d/config.json";
|
BOT_CONFIG_FILE = "%d/config.json";
|
||||||
BOT_LISTEN_HOST = cfg.listenAddress;
|
BOT_LISTEN_HOST = cfg.listenAddress;
|
||||||
|
|
@ -94,7 +98,6 @@ in
|
||||||
// cfg.extraEnvironment;
|
// cfg.extraEnvironment;
|
||||||
serviceConfig = {
|
serviceConfig = {
|
||||||
Type = "simple";
|
Type = "simple";
|
||||||
ExecStart = "${cfg.package}/bin/matrix-ops-bot";
|
|
||||||
DynamicUser = true;
|
DynamicUser = true;
|
||||||
StateDirectory = cfg.stateDirectory;
|
StateDirectory = cfg.stateDirectory;
|
||||||
WorkingDirectory = "/var/lib/${cfg.stateDirectory}";
|
WorkingDirectory = "/var/lib/${cfg.stateDirectory}";
|
||||||
|
|
|
||||||
|
|
@ -16,7 +16,6 @@ self: {
|
||||||
user_id = "@ops-bot:example.invalid";
|
user_id = "@ops-bot:example.invalid";
|
||||||
password = "not-a-real-password";
|
password = "not-a-real-password";
|
||||||
device_name = "nixos-test";
|
device_name = "nixos-test";
|
||||||
store_path = "/var/lib/matrix-ops-bot/matrix";
|
|
||||||
verify_ssl = false;
|
verify_ssl = false;
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -49,7 +49,7 @@ class MatrixClientSettings(BaseSettings):
|
||||||
user_id: str
|
user_id: str
|
||||||
password: str
|
password: str
|
||||||
device_name: str
|
device_name: str
|
||||||
store_path: str
|
store_path: Optional[str] = None
|
||||||
verify_ssl: Optional[bool] = True
|
verify_ssl: Optional[bool] = True
|
||||||
|
|
||||||
class Config:
|
class Config:
|
||||||
|
|
@ -60,7 +60,10 @@ class MatrixClientSettings(BaseSettings):
|
||||||
class MatrixClient:
|
class MatrixClient:
|
||||||
def __init__(self, settings: MatrixClientSettings, join_rooms: List[str]):
|
def __init__(self, settings: MatrixClientSettings, join_rooms: List[str]):
|
||||||
self.settings = settings
|
self.settings = settings
|
||||||
self.store_path = pathlib.Path(settings.store_path)
|
bot_state_dir = os.environ.get("BOT_STATE_DIR")
|
||||||
|
if bot_state_dir is None:
|
||||||
|
raise ValueError("BOT_STATE_DIR env var is required")
|
||||||
|
self.store_path = pathlib.Path(bot_state_dir).joinpath("matrix")
|
||||||
self.join_rooms = join_rooms
|
self.join_rooms = join_rooms
|
||||||
self.credential_store = LocalCredentialStore(
|
self.credential_store = LocalCredentialStore(
|
||||||
self.store_path.joinpath("credentials.json")
|
self.store_path.joinpath("credentials.json")
|
||||||
|
|
@ -76,8 +79,7 @@ class MatrixClient:
|
||||||
|
|
||||||
self.greeting_sent = False
|
self.greeting_sent = False
|
||||||
|
|
||||||
if self.store_path and not os.path.isdir(self.store_path):
|
self.store_path.mkdir(parents=True, exist_ok=True)
|
||||||
os.mkdir(self.store_path)
|
|
||||||
|
|
||||||
async def start(self) -> None:
|
async def start(self) -> None:
|
||||||
await self.login()
|
await self.login()
|
||||||
|
|
@ -108,7 +110,7 @@ class MatrixClient:
|
||||||
self.client = AsyncClient(
|
self.client = AsyncClient(
|
||||||
homeserver=self.settings.homeserver,
|
homeserver=self.settings.homeserver,
|
||||||
user=self.settings.user_id,
|
user=self.settings.user_id,
|
||||||
store_path=str(self.settings.store_path),
|
store_path=str(self.store_path),
|
||||||
config=self.client_config,
|
config=self.client_config,
|
||||||
ssl=self.settings.verify_ssl,
|
ssl=self.settings.verify_ssl,
|
||||||
)
|
)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue