New pki-server commands have been added to provide a consistent
way to start, stop, and restart PKI instances using different
types of Tomcat installations.

https://fedorahosted.org/pki/ticket/2560

--
Endi S. Dewata
>From 69805bcc5b6fcedb3f4114e2f02b50d8a5931e09 Mon Sep 17 00:00:00 2001
From: "Endi S. Dewata" <edew...@redhat.com>
Date: Wed, 14 Dec 2016 13:44:46 +0100
Subject: [PATCH] Added startup CLI for generic Tomcat.

New pki-server commands have been added to provide a consistent
way to start, stop, and restart PKI instances using different
types of Tomcat installations.

https://fedorahosted.org/pki/ticket/2560
---
 base/server/python/pki/server/cli/__init__.py | 210 ++++++++++++++++++++++++++
 base/server/sbin/pki-server                   |   5 +
 2 files changed, 215 insertions(+)

diff --git a/base/server/python/pki/server/cli/__init__.py b/base/server/python/pki/server/cli/__init__.py
index e69de29bb2d1d6434b8b29ae775ad8c2e48c5391..7029ebbb76c85abf5a09db03e0173f52fdb941df 100644
--- a/base/server/python/pki/server/cli/__init__.py
+++ b/base/server/python/pki/server/cli/__init__.py
@@ -0,0 +1,210 @@
+# Authors:
+#     Endi S. Dewata <edew...@redhat.com>
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; version 2 of the License.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License along
+# with this program; if not, write to the Free Software Foundation, Inc.,
+# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+#
+# Copyright (C) 2016 Red Hat, Inc.
+# All rights reserved.
+#
+
+from __future__ import absolute_import
+from __future__ import print_function
+import getopt
+import sys
+
+import pki.cli
+import pki.server
+
+
+class StartCLI(pki.cli.CLI):
+
+    def __init__(self):
+        super(StartCLI, self).__init__('start', 'Start PKI server')
+
+    def print_help(self):
+        print('Usage: pki-server start [OPTIONS]')
+        print()
+        print('  -i, --instance <instance ID>    Instance ID (default: pki-tomcat).')
+        print('  -v, --verbose                   Run in verbose mode.')
+        print('      --debug                     Show debug messages.')
+        print('      --help                      Show help message.')
+        print()
+
+    def execute(self, argv):
+        try:
+            opts, _ = getopt.gnu_getopt(argv, 'i:v', [
+                'instance=',
+                'verbose', 'debug', 'help'])
+
+        except getopt.GetoptError as e:
+            print('ERROR: ' + str(e))
+            self.print_help()
+            sys.exit(1)
+
+        instance_name = 'pki-tomcat'
+
+        for o, a in opts:
+            if o in ('-i', '--instance'):
+                instance_name = a
+
+            elif o in ('-v', '--verbose'):
+                self.set_verbose(True)
+
+            elif o == '--debug':
+                self.set_verbose(True)
+                self.set_debug(True)
+
+            elif o == '--help':
+                self.print_help()
+                sys.exit()
+
+            else:
+                print('ERROR: unknown option ' + o)
+                self.print_help()
+                sys.exit(1)
+
+        if self.verbose:
+            print('Starting PKI server %s' % instance_name)
+
+        instance = pki.server.PKIInstance(instance_name)
+
+        if not instance.is_valid():
+            print('ERROR: Invalid instance %s.' % instance_name)
+            sys.exit(1)
+
+        instance.start()
+
+        self.print_message('PKI server started')
+
+
+class StopCLI(pki.cli.CLI):
+
+    def __init__(self):
+        super(StopCLI, self).__init__('stop', 'Stop PKI server')
+
+    def print_help(self):
+        print('Usage: pki-server stop [OPTIONS]')
+        print()
+        print('  -i, --instance <instance ID>    Instance ID (default: pki-tomcat).')
+        print('  -v, --verbose                   Run in verbose mode.')
+        print('      --debug                     Show debug messages.')
+        print('      --help                      Show help message.')
+        print()
+
+    def execute(self, argv):
+        try:
+            opts, _ = getopt.gnu_getopt(argv, 'i:v', [
+                'instance=',
+                'verbose', 'debug', 'help'])
+
+        except getopt.GetoptError as e:
+            print('ERROR: ' + str(e))
+            self.print_help()
+            sys.exit(1)
+
+        instance_name = 'pki-tomcat'
+
+        for o, a in opts:
+            if o in ('-i', '--instance'):
+                instance_name = a
+
+            elif o in ('-v', '--verbose'):
+                self.set_verbose(True)
+
+            elif o == '--debug':
+                self.set_verbose(True)
+                self.set_debug(True)
+
+            elif o == '--help':
+                self.print_help()
+                sys.exit()
+
+            else:
+                print('ERROR: unknown option ' + o)
+                self.print_help()
+                sys.exit(1)
+
+        if self.verbose:
+            print('Stopping PKI server %s' % instance_name)
+
+        instance = pki.server.PKIInstance(instance_name)
+
+        if not instance.is_valid():
+            print('ERROR: Invalid instance %s.' % instance_name)
+            sys.exit(1)
+
+        instance.stop()
+
+        self.print_message('PKI server stopped')
+
+
+class RestartCLI(pki.cli.CLI):
+
+    def __init__(self):
+        super(RestartCLI, self).__init__('restart', 'Restart PKI server')
+
+    def print_help(self):
+        print('Usage: pki-server restart [OPTIONS]')
+        print()
+        print('  -i, --instance <instance ID>    Instance ID (default: pki-tomcat).')
+        print('  -v, --verbose                   Run in verbose mode.')
+        print('      --debug                     Show debug messages.')
+        print('      --help                      Show help message.')
+        print()
+
+    def execute(self, argv):
+        try:
+            opts, _ = getopt.gnu_getopt(argv, 'i:v', [
+                'instance=',
+                'verbose', 'debug', 'help'])
+
+        except getopt.GetoptError as e:
+            print('ERROR: ' + str(e))
+            self.print_help()
+            sys.exit(1)
+
+        instance_name = 'pki-tomcat'
+
+        for o, a in opts:
+            if o in ('-i', '--instance'):
+                instance_name = a
+
+            elif o in ('-v', '--verbose'):
+                self.set_verbose(True)
+
+            elif o == '--debug':
+                self.set_verbose(True)
+                self.set_debug(True)
+
+            elif o == '--help':
+                self.print_help()
+                sys.exit()
+
+            else:
+                print('ERROR: unknown option ' + o)
+                self.print_help()
+                sys.exit(1)
+
+        if self.verbose:
+            print('Restarting PKI server %s' % instance_name)
+
+        instance = pki.server.PKIInstance(instance_name)
+
+        if not instance.is_valid():
+            print('ERROR: Invalid instance %s.' % instance_name)
+            sys.exit(1)
+
+        instance.restart()
+
+        self.print_message('PKI server restarted')
diff --git a/base/server/sbin/pki-server b/base/server/sbin/pki-server
index 6df70dc848680aef2f54b93e0d8bc0a776a4a292..7ad3d0f517c525fb37f599231122784698d6ae6b 100644
--- a/base/server/sbin/pki-server
+++ b/base/server/sbin/pki-server
@@ -27,6 +27,7 @@ import sys
 import traceback
 
 import pki.cli
+import pki.server.cli
 import pki.server.cli.ca
 import pki.server.cli.kra
 import pki.server.cli.ocsp
@@ -46,6 +47,10 @@ class PKIServerCLI(pki.cli.CLI):
             'pki-server',
             'PKI server command-line interface')
 
+        self.add_module(pki.server.cli.StartCLI())
+        self.add_module(pki.server.cli.StopCLI())
+        self.add_module(pki.server.cli.RestartCLI())
+
         self.add_module(pki.server.cli.ca.CACLI())
         self.add_module(pki.server.cli.kra.KRACLI())
         self.add_module(pki.server.cli.ocsp.OCSPCLI())
-- 
2.5.5

_______________________________________________
Pki-devel mailing list
Pki-devel@redhat.com
https://www.redhat.com/mailman/listinfo/pki-devel

Reply via email to