startService function

Future<void> startService()

The main service thread that runs within the docker container.

Implementation

Future<void> startService() async {
  print(red('*' * 80));
  print('Nginx-LE starting Version: $packageVersion');
  print(red('*' * 80));

  /// These environment variables are set when the container is
  /// created via nginx-le config or by docker-compose.
  ///
  /// NOTE: you can NOT change these by setting an environment var before you
  /// call nginx-le start
  /// They can only be changed by re-running nginx-le config and recreating
  ///  the container.
  ///
  ///

  final startPaused = Environment().startPaused;

  if (startPaused) {
    print(
        orange('Nginx-LE is paused. Run "nginx-le cli" to attached and explore '
            'the Nginx-LE container'));
    while (true) {
      sleep(10);
    }
  } else {
    try {
      await _start();
      // ignore: avoid_catches_without_on_clauses
    } catch (e, s) {
      print('Nginx-LE encounted an unexpected problem and is shutting down.');
      print('Exception: ${e.runtimeType} $e');
      print('Stacktrace: $s');
    } finally {
      print(orange('Nginx-le has shutdown'));
    }
  }
}