Skip to content

Commit 0d434ea

Browse files
authored
DPE-2183 operator disable (#409)
* pause operator support * message tweak * s/pause/disable
1 parent e93dcca commit 0d434ea

File tree

1 file changed

+16
-1
lines changed

1 file changed

+16
-1
lines changed

lib/charms/mysql/v0/mysql.py

+16-1
Original file line numberDiff line numberDiff line change
@@ -71,10 +71,13 @@ def wait_until_mysql_connection(self) -> None:
7171
import io
7272
import json
7373
import logging
74+
import os
7475
import re
7576
import socket
77+
import sys
7678
import time
7779
from abc import ABC, abstractmethod
80+
from pathlib import Path
7881
from typing import Any, Dict, Iterable, List, Optional, Tuple, Union, get_args
7982

8083
import ops
@@ -111,7 +114,7 @@ def wait_until_mysql_connection(self) -> None:
111114

112115
# Increment this PATCH version before using `charmcraft publish-lib` or reset
113116
# to 0 if you are raising the major API version
114-
LIBPATCH = 55
117+
LIBPATCH = 56
115118

116119
UNIT_TEARDOWN_LOCKNAME = "unit-teardown"
117120
UNIT_ADD_LOCKNAME = "unit-add"
@@ -376,6 +379,18 @@ class MySQLCharmBase(CharmBase, ABC):
376379
def __init__(self, *args):
377380
super().__init__(*args)
378381

382+
# disable support
383+
disable_file = Path(
384+
f"{os.environ.get('CHARM_DIR')}/disable"
385+
) # pyright: ignore [reportArgumentType]
386+
if disable_file.exists():
387+
logger.warning(
388+
f"\n\tDisable file `{disable_file.resolve()}` found, the charm will skip all events."
389+
"\n\tTo resume normal operations, please remove the file."
390+
)
391+
self.unit.status = ops.BlockedStatus("Disabled")
392+
sys.exit(0)
393+
379394
self.secrets = SecretCache(self)
380395
self.peer_relation_app = DataPeer(
381396
self,

0 commit comments

Comments
 (0)