5

When I installed Redmine I had a problem in the middle of the database configuration. I think I ctrl C'ed in the middle of it because I tried to switch to Mysql after starting with sqlite3. Since then I can't remove it, install it, configure it, or reinstall it. The other question about fixing half installed package is returning an error 123.

sudo apt-get install redmine

 Do you want to continue? [Y/n] y
 dpkg: error processing package redmine (--configure):
 package redmine is not ready for configuration
 cannot configure (current status 'half-installed')
 Errors were encountered while processing:
 redmine
 E: Sub-process /usr/bin/dpkg returned an error code (1)

sudo apt-get remove redmine

Do you want to continue? [Y/n] y
dpkg: error processing package redmine (--remove):
 package is in a very bad inconsistent state; you should
 reinstall it before attempting a removal
Errors were encountered while processing:
 redmine
E: Sub-process /usr/bin/dpkg returned an error code (1)

sudo apt-get install --reinstall redmine

Preparing to unpack .../redmine_3.2.1-2_all.deb ...
Unpacking redmine (3.2.1-2) over (3.2.1-2) ...
ls: cannot access '/etc/redmine/*/database.yml': No such file or directory
dirname: missing operand
Try 'dirname --help' for more information.
basename: missing operand
Try 'basename --help' for more information.
dpkg: warning: subprocess old post-removal script returned error exit     status 123
dpkg: trying script from the new package instead ...
ls: cannot access '/etc/redmine/*/database.yml': No such file or directory
dirname: missing operand
Try 'dirname --help' for more information.
basename: missing operand
Try 'basename --help' for more information.
dpkg: error processing archive /var/cache/apt/archives    /redmine_3.2.1-2_all.deb (--unpack):
 subprocess new post-removal script returned error exit status 123
ls: cannot access '/etc/redmine/*/database.yml': No such file or directory
dirname: missing operand
Try 'dirname --help' for more information.
basename: missing operand
Try 'basename --help' for more information.
dpkg: error while cleaning up:
 subprocess new post-removal script returned error exit status 123
Errors were encountered while processing:
 /var/cache/apt/archives/redmine_3.2.1-2_all.deb
E: Sub-process /usr/bin/dpkg returned an error code (1)

Redmine seem to have specific reinstallation procedure that I tried, but it fail at the step where you call Redmine because it's not installed.

I've tried the solution in this question about half installed package and its still not working :

sudo dpkg --remove --force-remove-reinstreq redmine

dpkg: warning: overriding problem because --force enabled:
dpkg: warning: package is in a very bad inconsistent state; you should
 reinstall it before attempting a removal
(Reading database ... 409396 files and directories currently installed.)
Removing redmine (3.2.1-2) ...
ls: cannot access '/etc/redmine/*/database.yml': No such file or directory
dirname: missing operand
Try 'dirname --help' for more information.
basename: missing operand
Try 'basename --help' for more information.
dpkg: error processing package redmine (--remove):
 subprocess installed post-removal script returned error exit status 123
Errors were encountered while processing:
 redmine

Is there a way to fix this mess ? I don't care at all about what is in the mysql database or about the redmine configuration. I just want to start from scratch and be able to use redmine again.

Edit : I thougth I solved the problem with :

sudo rm /var/lib/dpkg/info/redmine*

sudo dpkg --force-remove-reinstreq --remove redmine

 dpkg: warning: overriding problem because --force enabled:
 dpkg: warning: package is in a very bad inconsistent state; you should
  reinstall it before attempting a removal
 dpkg: warning: files list file for package 'redmine-sqlite' missing; assuming package has no files currently installed
 dpkg: warning: files list file for package 'redmine-mysql' missing; assuming package has no files currently installed
 (Reading database ... 409382 files and directories currently installed.)
 Removing redmine (3.2.1-2) ...

After an "apt-get purge --auto-remove redmine" to clean all the related packages, and to get rid of the configuration file, I was able to install redmine again... in theory. Because Rake is now failing (because of the ghost database configuration ?).

rake aborted!
Cannot load `Rails.application.database_configuration`:
Could not load database configuration. No such file - ["/usr/share/redmine/instances/default/config/database.yml"]

Then I still have the removal problem with apt-get remove :

ls: cannot access '/etc/redmine/*/database.yml': No such file or directory
4

I'm running 16.04 LTS and I had the exact same problem, but I proceeded in a different way.

Remove Redmine

I didn't remove the dpkg scripts, but instead what I did was open the redmine.postrm script and comment the lines that caused the post removal script to crash, so my file was left like:

$ cat /var/lib/dpkg/info/redmine.postrm
#!/bin/sh

set -e

. /usr/share/debconf/confmodule
if [ -f /usr/share/dbconfig-common/dpkg/postrm ]; then
  . /usr/share/dbconfig-common/dpkg/postrm

  # remove both current and old instances
# START OF THE COMMENTED SECTION TO AVOID CRASHES 
#  instances=$(ls -1 /etc/redmine/*/database.yml | xargs dirname | xargs -n 1 basename)
#  for inst in $instances; do
#    dbc_go redmine/instances/$inst "$@"
#  done
# END OF THE COMMENTED SECTION TO AVOID CRASHES
fi

if [ "$1" = purge ]; then
  rm -rf /var/log/redmine
  rm -rf /var/cache/redmine
  rm -rf /var/lib/redmine
  rm -rf /etc/redmine
fi

## Automatically added by dh_installdebconf
if [ "$1" = purge ] && [ -e /usr/share/debconf/confmodule ]; then
    . /usr/share/debconf/confmodule
    db_purge
fi
# End automatically added section
#

Which allowed me to simply remove it with:

sudo apt-get remove redmine --purge

It will prompt you asking you if you want to delete the database redmine_default; I answered yes, but you should choose carefully.

After that it will purge all your installation with no warnings, so your first question is answered.

(To have more information about how dpkg scripts works, please have a look at: https://www.debian.org/doc/debian-policy/ch-maintainerscripts.html)

Reinstall Redmine

Now, how to install redmine and getting it running?

We'll start by doing

sudo apt-get update && sudo apt-get install redmine redmine-mysql

Probably it will crash again saying something like:

Configurando redmine (3.2.1-2) ...
Determining localhost credentials from /etc/mysql/debian.cnf: succeeded.
dbconfig-common: writing config to /etc/dbconfig-common/redmine/instances/default.conf
Not replacing deleted config file /etc/redmine/default/database.yml
granting access to database redmine_default for redmine/instance@localhost: already exists.
creating database redmine_default: already exists.
dbconfig-common: flushing administrative password
rake aborted!
Cannot load 'Rails.application.database_configuration':
Could not load database configuration. No such file - ["/usr/share/redmine/instances/default/config/database.yml"]
/usr/share/redmine/lib/plugins/acts_as_activity_provider/init.rb:2:in 'block in <top (required)>'
/usr/share/redmine/config/initializers/00-core_plugins.rb:12:in 'eval'
/usr/share/redmine/config/initializers/00-core_plugins.rb:12:in 'block in <top (required)>'
/usr/share/redmine/config/initializers/00-core_plugins.rb:2:in 'each'
/usr/share/redmine/config/initializers/00-core_plugins.rb:2:in '<top (required)>'
/usr/share/redmine/config/environment.rb:14:in '<top (required)>'
/var/lib/gems/2.3.0/gems/rake-11.3.0/exe/rake:27:in '<top (required)>'
/var/lib/gems/2.3.0/gems/bundler-1.13.1/lib/bundler/cli/exec.rb:74:in 'load'
/var/lib/gems/2.3.0/gems/bundler-1.13.1/lib/bundler/cli/exec.rb:74:in 'kernel_load'
/var/lib/gems/2.3.0/gems/bundler-1.13.1/lib/bundler/cli/exec.rb:27:in 'run'
/var/lib/gems/2.3.0/gems/bundler-1.13.1/lib/bundler/cli.rb:332:in 'exec'
/var/lib/gems/2.3.0/gems/bundler-1.13.1/lib/bundler/vendor/thor/lib/thor/command.rb:27:in 'run'
/var/lib/gems/2.3.0/gems/bundler-1.13.1/lib/bundler/vendor/thor/lib/thor/invocation.rb:126:in 'invoke_command'
/var/lib/gems/2.3.0/gems/bundler-1.13.1/lib/bundler/vendor/thor/lib/thor.rb:359:in 'dispatch'
/var/lib/gems/2.3.0/gems/bundler-1.13.1/lib/bundler/cli.rb:20:in 'dispatch'
/var/lib/gems/2.3.0/gems/bundler-1.13.1/lib/bundler/vendor/thor/lib/thor/base.rb:440:in `start'
/var/lib/gems/2.3.0/gems/bundler-1.13.1/lib/bundler/cli.rb:11:in 'start'
/var/lib/gems/2.3.0/gems/bundler-1.13.1/exe/bundle:34:in 'block in <top (required)>'
/var/lib/gems/2.3.0/gems/bundler-1.13.1/lib/bundler/friendly_errors.rb:100:in 'with_friendly_errors'
/var/lib/gems/2.3.0/gems/bundler-1.13.1/exe/bundle:26:in '<top (required)>'

Recreate database.yml

Where it clearly states that it

Could not load database configuration. No such file - ["/usr/share/redmine/instances/default/config/database.yml"]

Now we have 2 options:

Create one

For the 3.2 version you can find an example here: http://www.redmine.org/projects/redmine/repository/entry/branches/3.2-stable/config/database.yml.example. After a minor changes we can have something like:

cat /usr/share/redmine/instances/default/config/database.yml
# Setup is given for MySQL with ruby1.9.    
# Examples for PostgreSQL, SQLite3 and SQL Server can be found at the end.    
# Line indentation must be 2 spaces (no tabs).

production:    
  adapter: mysql2
  database: redmine_default
  host: localhost    
  username: root    
  password: "MySQLRootPassword"    
  encoding: utf8    
development:    
  adapter: mysql2    
  database: redmine_default
  host: localhost    
  username: root    
  password: ""
  encoding: utf8    
# Warning: The database defined as "test" will be erased and
# re-generated from your development database when you run "rake".    
# Do not set this db to the same as development or production.    
test:    
  adapter: mysql2    
  database: redmine_test    
  host: localhost    
  username: root    
  password: ""    
  encoding: utf8

Be careful as the production database HAS TO BE redmine_default or at least is the one that is left created after installation. I didn't check whether it will work with another value.

Copy the one that was created during installation

You could move it where the configuration script is trying to find it:

sudo cp /usr/share/redmine/config/database.yml /usr/share/redmine/instances/default/config/database.yml

Now that we have all that you need, we can finish the install with:

sudo apt-get -f install 

Further information about installing redmine on Ubuntu is in this wiki in redmine.com.

  • 1
    Very nice and thorough answer, this is what I was looking for. Let's hope a lot of redmine user in need find this. – Pierre.Sassoulas Sep 24 '16 at 18:02
2

This is actually a known bug in Redmine 3.2.3-1 : There is a discussion about this problem in this google group.

Don't fail to create '/etc/redmine/*/database.yml' during your configuration. Creating it later does not seem to fix the problem either.

  • Do you feel your question is answered. If so, you can accept it – Anwar Sep 20 '16 at 13:13
  • I still hope for a better answer. Maybe there is a way to fix it after the fact. – Pierre.Sassoulas Sep 20 '16 at 14:07
1

I finally did it after around 8 hours, my Redmine runs again. Thanks to Manuel and dozens of other StackExchange questions and answers.

If the accepted answer does not quite work to remove the old package and get an error that the package is in a really bad state (dpkg: warning: package is in a very bad inconsistent state; you should reinstall it before attempting a removal) and cannot be removed with sudo apt-get remove redmine --purge as written by Manuel, do the following. Still update the redmine.postrm script as Manuel wrote in his answer. Maybe it works for you but it did not for me. Download the redmine package manually at packages.ubuntu.com and run sudo dpkg -i WHERE/THE/DOWNLOADED/PACKAGE/IS as suggested by this comment.

Solution that worked for me

If that did not work then try the next thing that worked for me as found here: sudo dpkg --remove --force-remove-reinstreq redmine. I did also sudo dpkg --purge --force-remove-reinstreq redmine to remove the config files. And after that also sudo apt-get remove redmine and sudo apt-get autoremove && sudo apt-get autoclean

If you get a further error while installing redmine with sudo apt-get install redmine redmine-mysql about

/usr/local/bin/bundle:23:in 'load': cannot load such file -- /usr/share/rubygems-integration/all/gems/bundler-1.11.2/exe/bundle (LoadError)
        from /usr/local/bin/bundle:23:in '<main>'

Then try and see if you have the gem command available (if not, dunno from where it comes, but most likely the ruby package, so just install that) and type gem install bundler. If you already had it then good. It will be installed to the INSTALLATION DIRECTORY that you can see when you run gem environment, in my case /var/lib/gems/2.3.0. I don’t know why but I still haven’t had the bundler-1.11.2 in the directory that was mentioned above but whatever, it kept going.

The next error I got:

dbconfig-common: flushing administrative password
Could not find gem 'mysql2 (~> 0.4.0)' in any of the gem sources listed in your Gemfile or available on this machine.
Run `bundle install` to install missing gems.

Install msyql2 gem

Before I could install with gem install mysql2 I had to install sudo apt-get install libmysqlclient-dev (if this doesn’t work, remove the redmine package again first as shown above, I had to do that). This should be installed automatically with the redminepackage but yeah…

If you get an error like

Fetching: mysql2-0.4.4.gem (100%)
Building native extensions.  This could take a while...
ERROR:  Error installing mysql2:
        ERROR: Failed to build gem native extension.̀

And have something in the given error log file like gcc: error: unrecognized command line option then run sudo apt-get install gcc make. Try it again with gem install mysql2̀.

Continue with installation

After that continue with Manuel’s answer. And if you get an error when you created the database.yml file (I did not have one created during the installation btw and could not copy it, had to copy Manuel’s example so don’t worry) and continued with the installation and get something like this

[!] There was an error parsing 'Gemfile': undefined method 'values' for "Setup is given for MySQL with ruby1.9.":String. Bundler cannot continue.
 #  from /usr/share/redmine/Gemfile:67
 #  -------------------------------------------
 #    database_config = YAML::load(ERB.new(IO.read(database_file)).result)
 >    adapters = database_config.values.map {|c| c['adapter']}.compact.uniq
 #    if adapters.any?
 #  -------------------------------------------

Then don’t worry, you were just too stupid to copy the database.yml file correctly like I was :D In my case, I forgot the beginning comment sign #. If you may have other problems, check your database.yml file with http://www.yamllint.com/ for errors. Maybe if you have a password that contains an @ you have to escape that char (don’t know how) because it’s a reserved yaml character.

0

Try this:

Find and comment the remove line on this file: /var/lib/dpkg/info/redmine.postinst

Look like this:

#rm -f /var/lib/redmine/Gemfile.lock

Make a symbolic link to /var/lib/redmine/Gemfile.lock on /usr/share/redmine

Try upgrade ;-)

Your Answer

By clicking "Post Your Answer", you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.