diff --git a/docs/ENVIRONMENT.rst b/docs/ENVIRONMENT.rst index 00a555f..b70dc43 100644 --- a/docs/ENVIRONMENT.rst +++ b/docs/ENVIRONMENT.rst @@ -64,6 +64,10 @@ Miscellaneous These environment variables are optional: +* **ALLOW_ROOT** + + Set this environment variable to anything non-empty to allow running ElectrumX as root. + * **NET** Must be a *NET* from one of the **Coin** classes in `lib/coins.py`_. diff --git a/server/controller.py b/server/controller.py index 5d504d8..59ae4d5 100644 --- a/server/controller.py +++ b/server/controller.py @@ -51,9 +51,12 @@ class Controller(util.LoggedClass): if sys.version_info < (3, 5, 3): raise RuntimeError('Python >= 3.5.3 is required to run ElectrumX') - if os.geteuid() == 0: - raise RuntimeError('DO NOT RUN AS ROOT! Create an unprivileged ' - 'user account and use that') + if os.geteuid() == 0 and not env.allow_root: + raise RuntimeError('RUNNING AS ROOT IS STRONGLY DISCOURAGED!\n' + 'You shoud create an unprivileged user account ' + 'and use that.\n' + 'To continue as root anyway, restart with ' + 'environment variable ALLOW_ROOT non-empty') # Set the event loop policy before doing anything asyncio self.logger.info('event loop policy: {}'.format(env.loop_policy)) diff --git a/server/env.py b/server/env.py index 3d6427d..4210da9 100644 --- a/server/env.py +++ b/server/env.py @@ -29,6 +29,7 @@ class Env(lib_util.LoggedClass): def __init__(self): super().__init__() self.obsolete(['UTXO_MB', 'HIST_MB', 'NETWORK']) + self.allow_root = self.boolean('ALLOW_ROOT', False) self.db_dir = self.required('DB_DIRECTORY') self.daemon_url = self.required('DAEMON_URL') coin_name = self.required('COIN').strip()