当我安装 Redmine 时,我在数据库配置过程中遇到了问题。我想我在中间按了 ctrl C,因为我在启动 sqlite3 后尝试切换到 Mysql。从那时起,我无法删除它、安装它、配置它或重新安装它。另一个关于修复安装到一半的软件包的问题返回错误 123。
sudo apt-get 安装 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 删除 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 似乎有具体的重新安装程序我尝试过,但是在调用 Redmine 的步骤中失败,因为它尚未安装。
我已经尝试过解决方案关于半安装包的这个问题但它仍然不起作用:
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
有办法解决这个烂摊子吗?我根本不关心 mysql 数据库中有什么,也不关心 redmine 配置。我只想从头开始,然后能够再次使用 redmine。
编辑:我想我已经解决了这个问题:
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) ...
在执行“apt-get purge --auto-remove redmine”清理所有相关包并删除配置文件后,我能够再次安装 redmine... 理论上如此。因为 Rake 现在失败了(因为 ghost 数据库配置?)。
rake aborted!
Cannot load `Rails.application.database_configuration`:
Could not load database configuration. No such file - ["/usr/share/redmine/instances/default/config/database.yml"]
然后我仍然有 apt-get remove 的删除问题:
ls: cannot access '/etc/redmine/*/database.yml': No such file or directory
答案1
我正在运行 16.04 LTS,遇到了完全相同的问题,但我采用了不同的方法。
删除Redmine
我没有删除dpkg
脚本,而是打开脚本redmine.postrm
并注释掉导致删除后脚本崩溃的行,所以我的文件变成如下形式:
$ 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
#
这让我可以简单地用以下方法删除它:
sudo apt-get remove redmine --purge
它会提示您是否要删除数据库redmine_default
;我回答是的,但您应该谨慎选择。
此后,它将在没有任何警告的情况下清除您的所有安装,因此您的第一个问题已经得到回答。
(要了解有关dpkg
脚本如何工作的更多信息,请查看:https://www.debian.org/doc/debian-policy/ch-maintainerscripts.html)
重新安装Redmine
现在,如何安装 redmine 并使其运行?
我们首先要做的是
sudo apt-get update && sudo apt-get install redmine redmine-mysql
它可能会再次崩溃,并出现类似以下的情况:
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)>'
重新创建 database.yml
其中明确指出
Could not load database configuration. No such file - ["/usr/share/redmine/instances/default/config/database.yml"]
现在我们有两个选择:
创建一个
对于 3.2 版本,您可以在此处找到示例:http://www.redmine.org/projects/redmine/repository/entry/branches/3.2-stable/config/database.yml.example经过一些小的修改后,我们可以得到如下内容:
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
生产数据库必须是 redmine_default或者至少是安装后留下的。我没有检查它是否适用于其他值。
复制安装过程中创建的
您可以将其移动到配置脚本尝试找到它的位置:
sudo cp /usr/share/redmine/config/database.yml /usr/share/redmine/instances/default/config/database.yml
现在我们已经拥有了您需要的一切,我们可以完成安装:
sudo apt-get -f install
有关在 Ubuntu 上安装 redmine 的更多信息位于 redmine.com 的此 wiki 中。
答案2
这实际上是 Redmine 3.2.3-1 中的一个已知错误:这个谷歌小组中有关于这个问题的讨论。
在配置过程中不要忘记创建“/etc/redmine/*/database.yml”。稍后创建它似乎也无法解决问题。
答案3
大约 8 小时后,我终于完成了,我的 Redmine 再次运行。感谢 Manuel 和数十个其他 StackExchange 问题和答案。
如果接受的答案无法完全删除旧包,并收到错误,指出包处于非常糟糕的状态(dpkg: warning: package is in a very bad inconsistent state; you should reinstall it before attempting a removal
)并且无法删除,sudo apt-get remove redmine --purge
如 Manuel 所写,请执行以下操作。仍然更新 redmine.postrm 脚本,如 Manuel 在他的答案中所写。也许它对你有用,但对我没用。在 packages.ubuntu.com 手动下载 redmine 包,并sudo dpkg -i WHERE/THE/DOWNLOADED/PACKAGE/IS
按照建议运行此评论。
对我有用的解决方案
如果这不起作用,那么尝试下一个对我有用的方法这里:sudo dpkg --remove --force-remove-reinstreq redmine
我也sudo dpkg --purge --force-remove-reinstreq redmine
删除了配置文件。之后sudo apt-get remove redmine
也sudo apt-get autoremove && sudo apt-get autoclean
sudo apt-get install redmine redmine-mysql
如果你在安装redmine时遇到以下错误
/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>'
然后尝试查看是否有gem
可用的命令(如果没有,不知道它来自哪里,但很可能是 ruby 包,所以只需安装它)并输入gem install bundler
。如果你已经有了它,那就好了。它将被安装到INSTALLATION DIRECTORY
你运行时可以看到的gem environment
,在我的情况下/var/lib/gems/2.3.0
。我不知道为什么,但我仍然没有bundler-1.11.2
在上面提到的目录中,但无论如何,它继续运行。
我收到的下一个错误:
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.
安装 msyql2 gem
在安装之前,gem install mysql2
我必须先安装sudo apt-get install libmysqlclient-dev
(如果这不起作用,请先redmine
再次删除该包,如上所示,我必须这样做)。这应该会自动随redmine
包一起安装,但是是的……
如果你收到如下错误
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.̀
并在给定的错误日志文件中包含类似以下内容的内容,gcc: error: unrecognized command line option
然后运行sudo apt-get install gcc make
。使用 重试gem install mysql2̀
。
继续安装
之后继续 Manuel 的回答。如果你在创建 database.yml 文件时遇到错误(顺便说一句,我在安装过程中没有创建该文件,因此无法复制,只能复制 Manuel 的示例,所以不用担心),然后继续安装,并得到类似这样的结果
[!] 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?
# -------------------------------------------
那么不用担心,你只是太笨了,没有像我一样正确复制 database.yml 文件 :D 就我而言,我忘记了开头的注释符号#
。如果你有其他问题,请使用以下命令检查你的 database.yml 文件http://www.yamllint.com/错误。也许如果你的密码包含一个,那么@
你必须转义该字符(不知道如何),因为它是一个保留的 yaml 字符。
答案4
尝试这个:
找到并注释掉此文件的删除行:
/var/lib/dpkg/info/redmine.postinst
看起来像这样:
\#rm -f /var/lib/redmine/Gemfile.lock
创建符号链接/var/lib/redmine/Gemfile.lock
至/usr/share/redmine
尝试升级;-)