• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

evolvedbinary / elemental / 982

29 Apr 2025 08:34PM UTC coverage: 56.409% (+0.007%) from 56.402%
982

push

circleci

adamretter
[feature] Improve README.md badges

28451 of 55847 branches covered (50.94%)

Branch coverage included in aggregate %.

77468 of 131924 relevant lines covered (58.72%)

0.59 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/exist-core/src/main/java/org/exist/jetty/ServerShutdown.java
1
/*
2
 * Elemental
3
 * Copyright (C) 2024, Evolved Binary Ltd
4
 *
5
 * admin@evolvedbinary.com
6
 * https://www.evolvedbinary.com | https://www.elemental.xyz
7
 *
8
 * Use of this software is governed by the Business Source License 1.1
9
 * included in the LICENSE file and at www.mariadb.com/bsl11.
10
 *
11
 * Change Date: 2028-04-27
12
 *
13
 * On the date above, in accordance with the Business Source License, use
14
 * of this software will be governed by the Apache License, Version 2.0.
15
 *
16
 * Additional Use Grant: Production use of the Licensed Work for a permitted
17
 * purpose. A Permitted Purpose is any purpose other than a Competing Use.
18
 * A Competing Use means making the Software available to others in a commercial
19
 * product or service that: substitutes for the Software; substitutes for any
20
 * other product or service we offer using the Software that exists as of the
21
 * date we make the Software available; or offers the same or substantially
22
 * similar functionality as the Software.
23
 *
24
 * NOTE: Parts of this file contain code from 'The eXist-db Authors'.
25
 *       The original license header is included below.
26
 *
27
 * =====================================================================
28
 *
29
 * eXist-db Open Source Native XML Database
30
 * Copyright (C) 2001 The eXist-db Authors
31
 *
32
 * info@exist-db.org
33
 * http://www.exist-db.org
34
 *
35
 * This library is free software; you can redistribute it and/or
36
 * modify it under the terms of the GNU Lesser General Public
37
 * License as published by the Free Software Foundation; either
38
 * version 2.1 of the License, or (at your option) any later version.
39
 *
40
 * This library is distributed in the hope that it will be useful,
41
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
42
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
43
 * Lesser General Public License for more details.
44
 *
45
 * You should have received a copy of the GNU Lesser General Public
46
 * License along with this library; if not, write to the Free Software
47
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
48
 */
49
package org.exist.jetty;
50

51
import org.apache.xmlrpc.XmlRpcException;
52
import org.exist.client.InteractiveClient;
53
import org.exist.start.CompatibleJavaVersionCheck;
54
import org.exist.start.StartException;
55
import org.exist.util.ConfigurationHelper;
56
import org.exist.util.OSUtil;
57
import org.exist.util.SystemExitCodes;
58
import org.exist.xmldb.DatabaseInstanceManager;
59
import org.exist.xmldb.XmldbURI;
60

61
import org.xmldb.api.DatabaseManager;
62
import org.xmldb.api.base.Collection;
63
import org.xmldb.api.base.Database;
64
import org.xmldb.api.base.XMLDBException;
65
import se.softhouse.jargo.Argument;
66
import se.softhouse.jargo.ArgumentException;
67
import se.softhouse.jargo.CommandLineParser;
68
import se.softhouse.jargo.ParsedArguments;
69

70
import java.io.IOException;
71
import java.util.Properties;
72

73
import static org.exist.util.ArgumentUtil.getOpt;
74
import static se.softhouse.jargo.Arguments.helpArgument;
75
import static se.softhouse.jargo.Arguments.stringArgument;
76

77
/**
78
 * Call the main method of this class to shut down a running database instance.
79
 * 
80
 * @author wolf
81
 */
82
public class ServerShutdown {
×
83

84
    /* general arguments */
85
    private static final Argument<?> helpArg = helpArgument("-h", "--help");
×
86

87
    /* database connection arguments */
88
    private static final Argument<String> userArg = stringArgument("-u", "--user")
×
89
            .description("specify username (has to be a member of group dba).")
×
90
            .defaultValue("admin")
×
91
            .build();
×
92
    private static final Argument<String> passwordArg = stringArgument("-p", "--password")
×
93
            .description("specify password for the user.")
×
94
            .defaultValue("")
×
95
            .build();
×
96
    private static final Argument<String> uriArg = stringArgument("-l", "--uri")
×
97
            .description("the XML:DB URI of the database instance to be shut down.")
×
98
            .build();
×
99

100
    @SuppressWarnings("unchecked")
101
        public static void main(final String[] args) {
102
        try {
103
            CompatibleJavaVersionCheck.checkForCompatibleJavaVersion();
×
104

105
            final ParsedArguments arguments = CommandLineParser
×
106
                    .withArguments(userArg, passwordArg, uriArg)
×
107
                    .andArguments(helpArg)
×
108
                    .programName("shutdown" + (OSUtil.IS_WINDOWS ? ".bat" : ".sh"))
×
109
                    .parse(args);
×
110

111
            process(arguments);
×
112
        } catch (final StartException e) {
×
113
            if (e.getMessage() != null && !e.getMessage().isEmpty()) {
×
114
                System.err.println(e.getMessage());
×
115
            }
116
            System.exit(e.getErrorCode());
×
117
        } catch (final ArgumentException e) {
×
118
            System.out.println(e.getMessageAndUsage());
×
119
            System.exit(SystemExitCodes.INVALID_ARGUMENT_EXIT_CODE);
×
120

121
        }
122
    }
×
123

124
    private static void process(final ParsedArguments arguments) {
125
        final Properties properties = loadProperties();
×
126

127
        final String user = arguments.get(userArg);
×
128
        final String passwd = arguments.get(passwordArg);
×
129

130
        String uri = getOpt(arguments, uriArg)
×
131
                .orElseGet(() -> properties.getProperty("uri", "xmldb:exist://localhost:8080/exist/xmlrpc"));
×
132

133
        try {
134
            // initialize database drivers
135
            final Class<?> cl = Class.forName("org.exist.xmldb.DatabaseImpl");
×
136
            // create the default database
137
            final Database database = (Database) cl.newInstance();
×
138
            DatabaseManager.registerDatabase(database);
×
139
            if (!uri.endsWith(XmldbURI.ROOT_COLLECTION)) {
×
140
                uri = uri + XmldbURI.ROOT_COLLECTION;
×
141
            }
142
            final Collection root = DatabaseManager.getCollection(uri, user, passwd);
×
143
            final DatabaseInstanceManager manager = root.getService(DatabaseInstanceManager.class);
×
144
            System.out.println("Shutting down database instance at ");
×
145
            System.out.println('\t' + uri);
×
146
            manager.shutdown();
×
147

148
        } catch (final XMLDBException e) {
×
149
            System.err.println("ERROR: " + e.getMessage());
×
150

151
            final Throwable t = e.getCause();
×
152
            if(t!=null && t instanceof XmlRpcException){
×
153
                System.err.println("CAUSE: "+t.getMessage());
×
154
            } else {
×
155
                e.printStackTrace();
×
156
            }
157
            
158
        } catch (final Exception e) {
×
159
            e.printStackTrace();
×
160
        }
161
    }
×
162

163
    private static Properties loadProperties() {
164
        try {
165
            final Properties properties = ConfigurationHelper.loadProperties("client.properties", InteractiveClient.class);
×
166
            if (properties != null) {
×
167
                return properties;
×
168
            }
169

170
            System.err.println("WARN - Unable to find client.properties");
×
171

172
        } catch (final IOException e) {
×
173
            System.err.println("WARN - Unable to load client.properties: " + e.getMessage());
×
174
        }
175

176
        // return new empty properties
177
        return new Properties();
×
178
    }
179
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc