How to restore a broken Confluence Setup
Asked by Michael Ilewicz:

Yesterday, Confluence worked perfectly without any issues.

This morning I tried to open a page only to find the following error message

```
java.lang.IllegalArgumentException: Negative position
    at java.base/sun.nio.ch.FileChannelImpl.read(Unknown Source)
```

With a long error trace that I, unfortunately, did not save.  
I thought that maybe restarting the confluence instance would help that so I restarted the server and when it came back online it just showed the very first initial confluence setup screen where it asks me whether I want to install a trial version or the full version.

I went into the server application files and looked at the atlassian-confluence.log file but it only has data since the restart

```

2022-06-05 08:03:57,716 INFO [Catalina-utility-2] [com.atlassian.confluence.lifecycle] contextInitialized Starting Confluence 7.13.0 [build 8703 based on commit hash 791df1c41ad1e432a490f9fc6f60e3ea49358bee] - synchrony version 4.0.0-ma$2022-06-05 08:04:22,353 INFO [Catalina-utility-2] [atlassian.confluence.cluster.DefaultClusterConfigurationHelper] lambda$saveSetupConfigIntoSharedHome$9 Writing setup configuration into shared home...
2022-06-05 08:04:22,892 INFO [Catalina-utility-2] [atlassian.confluence.cluster.DefaultClusterConfigurationHelper] lambda$saveSetupConfigIntoSharedHome$9 Finished writing setup configuration into shared home
2022-06-05 08:04:35,347 INFO [Catalina-utility-2] [atlassian.plugin.manager.DefaultPluginManager] lambda$earlyStartup$3 Plugin system earlyStartup begun
2022-06-05 08:04:45,301 WARN [FelixStartLevel] [extender.internal.support.ExtenderConfiguration] addDefaultDependencyFactories Gemini Blueprint extensions bundle not present, annotation processing disabled.
2022-06-05 08:04:54,422 INFO [Catalina-utility-2] [atlassian.plugin.manager.DefaultPluginManager] logTime Plugin system earlyStartup ended
2022-06-05 08:04:54,431 INFO [Catalina-utility-2] [atlassian.plugin.manager.DefaultPluginManager] lambda$lateStartup$4 Plugin system lateStartup begun
2022-06-05 08:04:59,829 INFO [Catalina-utility-2] [atlassian.plugin.manager.DefaultPluginManager] logTime Plugin system lateStartup ended
2022-06-05 08:05:01,043 INFO [Catalina-utility-2] [com.atlassian.confluence.lifecycle] init Confluence is ready to serve
2022-06-05 08:42:33,996 WARN [http-nio-8090-exec-8] [atlassian.confluence.xwork.SetupIncompleteInterceptor] intercept Redirecting request to current setup step: /login.action
-- url: /login.action | traceId: 000922355672bf19 | userName: anonymous
```

There are more log files (atlassian-confluence.log.1.locked enumerating up until 5) but when I open them I just see garbage... Does anybody know how I can open them? I suspect that would be where the original error trace could be found.

I also looked at the confluence.config.xml and that has the following content

```
<?xml version="1.0" encoding="UTF-8"?>

<confluence-configuration>
<setupStep>setupstart</setupStep>
<setupType>initial</setupType>
<buildNumber>0</buildNumber>
<properties>
<property name="access.mode">READ_WRITE</property>
<property name="confluence.setup.server.id">BQKY-3X1C-C81M-QLK5</property>
<property name="confluence.webapp.context.path"></property>
<property name="jwt.private.key">XYZ <property name="synchrony.encryption.disabled">true</property>
<property name="synchrony.proxy.enabled">true</property>
</properties>
</confluence-configuration>
```

Edit: I tried running the setup sequence and connecting to the existing database and I am able to connect to the DB but then it asks me whether I want to overwrite existing tables or restart the configuration, there seems to be no way to reuse the filled database.

How can this happen and how could I restore my old instance again?


Answers:
author: Fabio Racobaldo _Herzum_
body: Hi [@Michael Ilewicz](/t5/user/viewprofilepage/user-id/4075231) ,

please could you check the database configuration (file `<home-directory>/confluence.cfg.xml`) ? It seems that your instance lost db link so, at the application level, it seems a fresh installation.

Fabio

comments: author: Michael Ilewicz
body: Hi [@Fabio Racobaldo _Herzum_](/t5/user/viewprofilepage/user-id/781528) , thanks for the quick response, yes, sorry the confluence.config.xml is the confluence.cfg.xml, I misspelled the filename. So the content of that file is

```
<?xml version="1.0" encoding="UTF-8"?>

<confluence-configuration>
<setupStep>setupstart</setupStep>
<setupType>initial</setupType>
<buildNumber>0</buildNumber>
<properties>
<property name="access.mode">READ_WRITE</property>
<property name="confluence.setup.server.id">BQKY-3X1C-C81M-QLK5</property>
<property name="confluence.webapp.context.path"></property>
<property name="jwt.private.key">XYZ <property name="synchrony.encryption.disabled">true</property>
<property name="synchrony.proxy.enabled">true</property>
</properties>
</confluence-configuration>
```

Should I execute the setup via the browser to recreate the link or should I do it manually by editing that file?


author: Fabio Racobaldo _Herzum_
body: Hi [@Michael Ilewicz](/t5/user/viewprofilepage/user-id/4075231) ,

please could you share \<installation-directory\>/conf/server.xml file?

What is the DBMS associated to your Confluence?


author: Michael Ilewicz
body: --deleted duplicate


author: Michael Ilewicz
body: --deleted duplicate


author: Michael Ilewicz
body: Hi [@Fabio Racobaldo _Herzum_](/t5/user/viewprofilepage/user-id/781528) , somehow my response keeps getting deleted... I hope this will work now. I am using Azure SQL Server for my DB and the server.xml content is  

```
<Server port="8000" shutdown="SHUTDOWN" debug="0">
    <Service name="Tomcat-Standalone">

        <!-- ==============================================================================================================
HTTPS - Proxying Confluence via Apache or Nginx over HTTPS
If you're proxying traffic to Confluence over HTTPS, uncomment the connector below and comment out the others.
Make sure you provide the right information for proxyName and proxyPort.
For more information see:
Apache - https://confluence.atlassian.com/x/PTT3MQ
nginx - https://confluence.atlassian.com/x/cNIvMw ==============================================================================================================
-->

        <Connector port="8090" connectionTimeout="20000" redirectPort="8443" maxThreads="48" minSpareThreads="10" enableLookups="false" acceptCount="10" debug="0" URIEncoding="UTF-8" protocol="org.apache.coyote.http11.Http11NioProtocol" scheme="https" secure="true" proxyName="confluence.ardenmed.com" proxyPort="443"/>
        <Engine name="Standalone" defaultHost="localhost" debug="0">
            <Host name="localhost" debug="0" appBase="webapps" unpackWARs="true" autoDeploy="false" startStopThreads="4">
                <Context path="" docBase="../confluence" debug="0" reloadable="false" useHttpOnly="true">
                    <!-- Logging configuration for Confluence is specified in confluence/WEB-INF/classes/log4j.properties -->
                    <Manager pathname=""/>
                    <Valve className="org.apache.catalina.valves.StuckThreadDetectionValve" threshold="60"/>
                    <!-- http://tomcat.apache.org/tomcat-9.0-doc/config/valve.html#Access_Log_Valve -->
                    <Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs" maxDays="30" pattern="%t %{X-AUSERNAME}o %I %h %r %s %Dms %b %{Referer}i %{User-Agent}i" prefix="conf_access_log" requestAttributesEnabled="true" rotatable="true" suffix=".log" />
                    <!-- http://tomcat.apache.org/tomcat-9.0-doc/config/valve.html#Remote_IP_Valve -->
                    <Valve className="org.apache.catalina.valves.RemoteIpValve" />
                </Context>
                <Context path="${confluence.context.path}/synchrony-proxy" docBase="../synchrony-proxy" debug="0" reloadable="false" useHttpOnly="true">
                    <Valve className="org.apache.catalina.valves.StuckThreadDetectionValve" threshold="60"/>
                </Context>
            </Host>
        </Engine>
    </Service>
</Server> 
```


author: Fabio Racobaldo _Herzum_
body: Well, it is strange because Confluence setup to DB should be on confluence.cfg.xml or on server.xml but it seems that it is not in your case.

Please could you check if something changed on that file?

Fabio


author: Michael Ilewicz
body: I gave you the latest content of these files as they are right now. How can I check if anything changed? I'm sure that the server.xml never had database configuration as i had configured it manually when setting up the server to enable nginx. Unfortunately I don't have a backup of the configuration form before this incident anymore.


author: Michael Ilewicz
body: I tried running the setup sequence and connecting to the existing database and I am able to connect to the DB but then it asks me whether I want to overwrite existing tables or restart the configuration, there seems to be no way to reuse the filled database from the browser setup sequence...


author: Fabio Racobaldo _Herzum_
body: Try to add your existing database in confluence.cfg.xml

Take a look to the following article for more infromation <https://confluence.atlassian.com/confkb/how-to-find-confluence-s-database-connection-parameters-779172320.html>

Hope this helps,

Fabio


author: Michael Ilewicz
body: Hi [@Fabio Racobaldo _Herzum_](/t5/user/viewprofilepage/user-id/781528) thank you so much for your help, I don't know what I would do without you. I tried following [this guide](https://confluence.atlassian.com/confkb/how-to-generate-a-new-confluence-cfg-xml-425461512.html) but after the step where it starts creating the database, I get the error as in this [GitHub file](https://github.com/michox/server-debug/blob/main/error.log) (trace is too long for the community)... Is something wrong with my installation?


author: Fabio Racobaldo _Herzum_
body: Hi [@Michael Ilewicz](/t5/user/viewprofilepage/user-id/4075231) ,

you need just to add db information to your old confluence.cfg.xml using the correct parameters :

    <property name="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property>    <property name="hibernate.connection.password">confluencepass</property>    <property name="hibernate.connection.url">jdbc:mysql://<servername>/<databasename>?autoReconnect=true</property>    <property name="hibernate.connection.username">confluencedbuser</property>    <property name="hibernate.database.lower_non_ascii_supported">true</property>    <property name="hibernate.dialect">com.atlassian.hibernate.dialect.MySQ


author: Michael Ilewicz
body: what do I add for setupStep, setupType, buildNumber properties etc? Also how do I know i have the right config for Microsoft SQL Server? Is that documented somewhere? i could not find anything thus I tried to recreate the file in an alternative home with an empty database


author: Fabio Racobaldo _Herzum_
body: Here some parameters help for SQL Server <https://confluence.atlassian.com/conf59/database-setup-for-sql-server-792499576.html>


author: Michael Ilewicz
body: I did that but without the setupStep it just asks me to setup the database again when I start confluence. So I set the setupStep property to complete and restarted confluence. Now however, when I open the page I get the following error

```
java.lang.IllegalStateException: Spring Application context has not been set
    at com.atlassian.spring.container.SpringContainerContext.getComponent(SpringContainerContext.java:48)
```

and a long trace log I don't think would be helpful. [Apparently,](https://confluence.atlassian.com/confkb/confluence-does-not-start-due-to-spring-application-context-has-not-been-set-218278311.html) this can occur because of a number of reasons related to this config file. My config file currently is as follows. My password contains an \& which I escaped with \&amp; as I would get a read error without that escape.

```
<?xml version="1.0" encoding="UTF-8"?>

<confluence-configuration>
<setupStep>complete</setupStep>
<setupType>custom</setupType>
<buildNumber>8703</buildNumber>
<properties>
<property name="atlassian.license.message">MyLicense</property>
<property name="confluence.setup.server.id">OriginalServerId</property>
<property name="confluence.webapp.context.path"></property>
<property name="hibernate.connection.driver_class">net.sourceforge.jtds.jdbc.Driver</property>
<property name="hibernate.connection.password">passwordWithEscaped-&-likeThis-&amp;</property>
<property name="hibernate.connection.url">jdbc:jtds:sqlserver://mycompany.database.windows.net:1433/myDatabaseName?autoReconnect=true</property>
<property name="hibernate.connection.username">AVConfluenceUser</property>
<property name="hibernate.database.lower_non_ascii_supported">true</property>
<property name="jwt.private.key">key</property>
<property name="jwt.public.key">key</property>
<property name="lucene.index.dir">${localHome}/index</property>
<property name="synchrony.encryption.disabled">true</property>
<property name="synchrony.proxy.enabled">true</property>
<property name="webwork.multipart.saveDir">${localHome}/temp</property>
</properties>
</confluence-configuration>
```


Tags: confluence-server

server