Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Connection refused when sshd doesn't listen on default port #569

Closed
alchris opened this issue Jan 31, 2016 · 22 comments
Closed

Connection refused when sshd doesn't listen on default port #569

alchris opened this issue Jan 31, 2016 · 22 comments
Assignees
Labels
Milestone

Comments

@alchris
Copy link

alchris commented Jan 31, 2016

Hi,

our ssh server doesn't listen on the default port 22, which results in the following error:

$ RAILS_ENV=production rake --trace redmine_git_hosting:update_repositories

* Performing manual update_repositories operation from command line :
rake aborted!
Rugged::OSError: Failed to connect to localhost: Connection refused
/home/user/.gem/ruby/2.1.0/bundler/gems/gitolite-rugged-551741d1df06/lib/gitolite/gitolite_admin.rb:210:in `clone_at'
/home/user/.gem/ruby/2.1.0/bundler/gems/gitolite-rugged-551741d1df06/lib/gitolite/gitolite_admin.rb:210:in `clone'
/home/user/.gem/ruby/2.1.0/bundler/gems/gitolite-rugged-551741d1df06/lib/gitolite/gitolite_admin.rb:317:in `set_repo'
/home/user/.gem/ruby/2.1.0/bundler/gems/gitolite-rugged-551741d1df06/lib/gitolite/gitolite_admin.rb:64:in `initialize'
/home/user/redmine/plugins/redmine_git_hosting/lib/redmine_git_hosting/gitolite_wrapper.rb:65:in `new'
/home/user/redmine/plugins/redmine_git_hosting/lib/redmine_git_hosting/gitolite_wrapper.rb:65:in `gitolite_admin'
/home/user/redmine/plugins/redmine_git_hosting/lib/redmine_git_hosting/gitolite_wrapper.rb:45:in `execute_action'
/home/user/redmine/plugins/redmine_git_hosting/lib/redmine_git_hosting/gitolite_wrapper.rb:24:in `resync_gitolite'
/home/user/redmine/plugins/redmine_git_hosting/lib/redmine_git_hosting/gitolite_accessor.rb:145:in `resync_gitolite'
/home/user/redmine/plugins/redmine_git_hosting/lib/redmine_git_hosting/gitolite_accessor.rb:77:in `update_projects'
/home/user/redmine/plugins/redmine_git_hosting/lib/tasks/redmine_git_hosting.rake:23:in `block (3 levels) in <top (required)>'
/home/user/redmine/plugins/redmine_git_hosting/lib/redmine_git_hosting/console_logger.rb:7:in `title'
/home/user/redmine/plugins/redmine_git_hosting/lib/tasks/redmine_git_hosting.rake:22:in `block (2 levels) in <top (required)>'
/home/user/.gem/ruby/2.1.0/gems/rake-10.5.0/lib/rake/task.rb:240:in `call'
/home/user/.gem/ruby/2.1.0/gems/rake-10.5.0/lib/rake/task.rb:240:in `block in execute'
/home/user/.gem/ruby/2.1.0/gems/rake-10.5.0/lib/rake/task.rb:235:in `each'
/home/user/.gem/ruby/2.1.0/gems/rake-10.5.0/lib/rake/task.rb:235:in `execute'
/home/user/.gem/ruby/2.1.0/gems/rake-10.5.0/lib/rake/task.rb:179:in `block in invoke_with_call_chain'
/usr/lib/ruby/2.1.0/monitor.rb:211:in `mon_synchronize'
/home/user/.gem/ruby/2.1.0/gems/rake-10.5.0/lib/rake/task.rb:172:in `invoke_with_call_chain'
/home/user/.gem/ruby/2.1.0/gems/rake-10.5.0/lib/rake/task.rb:165:in `invoke'
/home/user/.gem/ruby/2.1.0/gems/rake-10.5.0/lib/rake/application.rb:150:in `invoke_task'
/home/user/.gem/ruby/2.1.0/gems/rake-10.5.0/lib/rake/application.rb:106:in `block (2 levels) in top_level'
/home/user/.gem/ruby/2.1.0/gems/rake-10.5.0/lib/rake/application.rb:106:in `each'
/home/user/.gem/ruby/2.1.0/gems/rake-10.5.0/lib/rake/application.rb:106:in `block in top_level'
/home/user/.gem/ruby/2.1.0/gems/rake-10.5.0/lib/rake/application.rb:115:in `run_with_threads'
/home/user/.gem/ruby/2.1.0/gems/rake-10.5.0/lib/rake/application.rb:100:in `top_level'
/home/user/.gem/ruby/2.1.0/gems/rake-10.5.0/lib/rake/application.rb:78:in `block in run'
/home/user/.gem/ruby/2.1.0/gems/rake-10.5.0/lib/rake/application.rb:176:in `standard_exception_handling'
/home/user/.gem/ruby/2.1.0/gems/rake-10.5.0/lib/rake/application.rb:75:in `run'
/home/user/.gem/ruby/1.9.1/gems/rake-10.1.1/bin/rake:33:in `<main>'
Tasks: TOP => redmine_git_hosting:update_repositories

It works when I change the config of the sshd so that it runs on port 22 .

The :gitolite_server_port variable is set to the port on which the sshd listens.

Redmine Git Hosting 1.2
Gitolite3 3.6.1-2 (Debian)

Environment:
  Redmine version                3.2.0.stable
  Ruby version                      2.1.5-p273 (2014-11-13) [x86_64-linux-gnu]
  Rails version                      4.2.5
  Environment                      production
  Database adapter              Mysql2
SCM:
  Subversion                         1.8.10
  Git                                      2.1.4
  Filesystem                     
  Xitolite                                2.1.
@n-rodriguez
Copy link
Contributor

This is configurable.

@alchris
Copy link
Author

alchris commented Jan 31, 2016

This is configurable.

Ok, how? I already changed the :gitolite_server_port variable in the webinterface.

@n-rodriguez
Copy link
Contributor

Well you might need to remove gitolite-admin.git dir from temp directory.
It will recloned with the right settings.

@alchris
Copy link
Author

alchris commented Jan 31, 2016

Well you might need to remove gitolite-admin.git dir from temp directory.

This doesn't change anything:

 * Performing manual update_repositories operation from command line :
rake aborted!
Rugged::OSError: Failed to connect to localhost: Connection refused
/home/user/.gem/ruby/2.1.0/bundler/gems/gitolite-rugged-551741d1df06/lib/gitolite/gitolite_admin.rb:210:in `clone_at'
/home/user/.gem/ruby/2.1.0/bundler/gems/gitolite-rugged-551741d1df06/lib/gitolite/gitolite_admin.rb:210:in `clone'
/home/user/.gem/ruby/2.1.0/bundler/gems/gitolite-rugged-551741d1df06/lib/gitolite/gitolite_admin.rb:317:in `set_repo'
/home/user/.gem/ruby/2.1.0/bundler/gems/gitolite-rugged-551741d1df06/lib/gitolite/gitolite_admin.rb:64:in `initialize'
/home/user/redmine/plugins/redmine_git_hosting/lib/redmine_git_hosting/gitolite_wrapper.rb:65:in `new'
/home/user/redmine/plugins/redmine_git_hosting/lib/redmine_git_hosting/gitolite_wrapper.rb:65:in `gitolite_admin'
/home/user/redmine/plugins/redmine_git_hosting/lib/redmine_git_hosting/gitolite_wrapper.rb:45:in `execute_action'
/home/user/redmine/plugins/redmine_git_hosting/lib/redmine_git_hosting/gitolite_wrapper.rb:24:in `resync_gitolite'
/home/user/redmine/plugins/redmine_git_hosting/lib/redmine_git_hosting/gitolite_accessor.rb:145:in `resync_gitolite'
/home/user/redmine/plugins/redmine_git_hosting/lib/redmine_git_hosting/gitolite_accessor.rb:77:in `update_projects'
/home/user/redmine/plugins/redmine_git_hosting/lib/tasks/redmine_git_hosting.rake:23:in `block (3 levels) in <top (required)>'
/home/user/redmine/plugins/redmine_git_hosting/lib/redmine_git_hosting/console_logger.rb:7:in `title'
/home/user/redmine/plugins/redmine_git_hosting/lib/tasks/redmine_git_hosting.rake:22:in `block (2 levels) in <top (required)>'
/home/user/.gem/ruby/2.1.0/gems/rake-10.5.0/lib/rake/task.rb:240:in `call'
/home/user/.gem/ruby/2.1.0/gems/rake-10.5.0/lib/rake/task.rb:240:in `block in execute'
/home/user/.gem/ruby/2.1.0/gems/rake-10.5.0/lib/rake/task.rb:235:in `each'
/home/user/.gem/ruby/2.1.0/gems/rake-10.5.0/lib/rake/task.rb:235:in `execute'
/home/user/.gem/ruby/2.1.0/gems/rake-10.5.0/lib/rake/task.rb:179:in `block in invoke_with_call_chain'
/usr/lib/ruby/2.1.0/monitor.rb:211:in `mon_synchronize'
/home/user/.gem/ruby/2.1.0/gems/rake-10.5.0/lib/rake/task.rb:172:in `invoke_with_call_chain'
/home/user/.gem/ruby/2.1.0/gems/rake-10.5.0/lib/rake/task.rb:165:in `invoke'
/home/user/.gem/ruby/2.1.0/gems/rake-10.5.0/lib/rake/application.rb:150:in `invoke_task'
/home/user/.gem/ruby/2.1.0/gems/rake-10.5.0/lib/rake/application.rb:106:in `block (2 levels) in top_level'
/home/user/.gem/ruby/2.1.0/gems/rake-10.5.0/lib/rake/application.rb:106:in `each'
/home/user/.gem/ruby/2.1.0/gems/rake-10.5.0/lib/rake/application.rb:106:in `block in top_level'
/home/user/.gem/ruby/2.1.0/gems/rake-10.5.0/lib/rake/application.rb:115:in `run_with_threads'
/home/user/.gem/ruby/2.1.0/gems/rake-10.5.0/lib/rake/application.rb:100:in `top_level'
/home/user/.gem/ruby/2.1.0/gems/rake-10.5.0/lib/rake/application.rb:78:in `block in run'
/home/user/.gem/ruby/2.1.0/gems/rake-10.5.0/lib/rake/application.rb:176:in `standard_exception_handling'
/home/user/.gem/ruby/2.1.0/gems/rake-10.5.0/lib/rake/application.rb:75:in `run'
/home/user/.gem/ruby/1.9.1/gems/rake-10.1.1/bin/rake:33:in `<main>'
Tasks: TOP => redmine_git_hosting:update_repositories

I add puts admin_url before the clone_at function in the "/lib/gitolite/gitolite_admin.rb:211" file to see which url is used. The content of the url variable is ssh://gitolite@localhost/gitolite-admin.git. There is no port definition in it.

The documentation of the clone function form the "/lib/gitolite/gitolite_admin.rb:211" file:

    # Clone the gitolite-admin repo
    # to the given path.
    #
    # The repo is cloned from the url
    # +(:git_user)@(:hostname)/gitolite-admin.git+
    #
    # The hostname may use an optional :port to allow for custom SSH ports.
    # E.g., +git@localhost:2222/gitolite-admin.git+
    #

So, there must be a port definition in the provided url.

@jblobb
Copy link

jblobb commented Feb 5, 2016

I've had problems with changing settings via the webpage.

You can edit /redmine_install_dir/plugins/redmine_git_hosting/lib/default_settings.yml

Then manually update using the following CLI commands:

bundle install --without development test postgresql sqlite
RAILS_ENV=production rake redmine:plugins:migrate
RAILS_ENV=production rake redmine_git_hosting:update_repositories
RAILS_ENV=production rake redmine_git_hosting:fetch_changesets
RAILS_ENV=production rake redmine_git_hosting:restore_default_settings
RAILS_ENV=production rake redmine_git_hosting:install_hook_files
RAILS_ENV=production rake redmine_git_hosting:install_hook_parameters
RAILS_ENV=production rake redmine_git_hosting:install_gitolite_hooks

Then restart the server and it should be set, just don't use the gui to change any settings as it breaks the config.

@n-rodriguez
Copy link
Contributor

Hi! Actually you could create this file : /redmine_install_dir/plugins/redmine_git_hosting/settings.yml to override any settings present in default_settings.yml. (you don't need to copy the whole file).

RAILS_ENV=production rake redmine:plugins:migrate : useless in this case

RAILS_ENV=production rake redmine_git_hosting:install_hook_files : this one calls the 2 others :

RAILS_ENV=production rake redmine_git_hosting:install_hook_parameters
RAILS_ENV=production rake redmine_git_hosting:install_gitolite_hooks

RAILS_ENV=production rake redmine_git_hosting:restore_default_settings : the task to run to update settings after any change in settings.ymlfile.

@n-rodriguez n-rodriguez self-assigned this Feb 9, 2016
@alchris
Copy link
Author

alchris commented Feb 10, 2016

I have tried your suggestions, but it doesn't appear to work.

@jblobb
Copy link

jblobb commented Feb 11, 2016

@alchris can you ssh to the box when it's on the different port?

What Git server are you running? Have you change the port number within that config file?

Then changed the /redmine_install_dir/plugins/redmine_git_hosting/lib/default_settings.yml, then manually ran the hooks update via CLI, & Rebooted?

I always reboot after every setting change, a) to test b) to make sure all files have been loaded with the new config.

@alchris
Copy link
Author

alchris commented Feb 14, 2016

Hello jblobb, here what I did:

$ ssh -i .ssh/gitolite_admin_id_rsa -p 1122 gitolite@localhost info

hello admin, this is gitolite@localhost running gitolite3 3.6.1-2 (Debian) on git 2.1.4

 R W    gitolite-admin
 R W    testing

Change settings:

$cat settings.yml:
---
# Gitolite SSH Config
gitolite_server_port:           '1122'
gitolite_ssh_private_key:       '/home/user/.ssh/gitolite_admin_id_rsa'
gitolite_ssh_public_key:        '/home/user/.ssh/gitolite_admin_id_rsa.pub'

$cat lib/default_settings.yml:
---
# Gitolite SSH Config
gitolite_user:                  'gitolite'
gitolite_server_host:           '127.0.0.1'
gitolite_server_port:           '1122'
gitolite_ssh_private_key:       '/home/user/.ssh/gitolite_admin_id_rsa'
gitolite_ssh_public_key:        '/home/user/.ssh/gitolite_admin_id_rsa.pub'
...

Run Commands:

$ RAILS_ENV=production rake redmine_git_hosting:restore_default_settings

(in /home/user/redmine)

 * Reloading defaults from init.rb from command line :
No changes necessary.
   Done !

--> restart apache

$ RAILS_ENV=production rake redmine_git_hosting:install_hook_files

(in /home/user/redmine)

 * Installing/updating Gitolite hooks :
---
:hook_files:
  redmine_gitolite.rb: 0
  mail_notifications.py: 0
  git_hosting_config.rb: 0
  git_hosting_custom_hook.rb: 0
  git_hosting_http_helper.rb: 0
  git_hosting_hook_logger.rb: 0
  git_hosting_post_receive.rb: 0
  git_multimail.py: 0
:global_params:
  redmineurl: true
  debugmode: true
  asyncmode: true
:mailer_params:
  mailer: true
  environment: true
  smtpauth: true
  smtpserver: true
  smtpport: true
   Done !

--> restart apache

$ RAILS_ENV=production rake --trace redmine_git_hosting:update_repositories

(in /home/user/redmine)
** Invoke redmine_git_hosting:update_repositories (first_time)
** Invoke environment (first_time)
** Execute environment
** Execute redmine_git_hosting:update_repositories

 * Performing manual update_repositories operation from command line :
rake aborted!
Rugged::OSError: Failed to connect to localhost: Connection refused

@jblobb
Copy link

jblobb commented Feb 14, 2016

@alchris Ok,

I don't have settings.yml, but I can see an error in your config...

$cat lib/default_settings.yml: gitolite_user: 'gitolite' gitolite_server_host: '127.0.0.1'

127.0.0.1 should be the IP address of the box / VM.

gitolite_server_host
gitolite_hooks_url
ssh_server_domain
http_server_domain
https_server_domain
http_server_subdir

They should be the IP of the Redmine box as well, then I would restart the box, to confirm that the changes have been applied to everything. Then run the Rake commands.

@alchris
Copy link
Author

alchris commented Feb 15, 2016

@jblobb:

The IP address is correct.
I will not restart our whole server to change settings of this plugin. This is not a suitable solution for us.

Today we decided to use gogs in the future, instead of this plugin.
Thanks for your help!

@jblobb
Copy link

jblobb commented Feb 15, 2016

@alchris I restart the server. BUT you can just restart redmine, which will still work.

When you pasted the config gitolite_server_host: '127.0.0.1' did you change this to mask your IP?

Have you tired
RAILS_ENV=production rake redmine_git_hosting:install_hook_parameters RAILS_ENV=production rake redmine_git_hosting:install_gitolite_hooks?

As far as I can see gogs, doesn't integrate to Redmine.

Can you post a copy of lib/default_settings.yml if you need to mask your IP please replace with xxx.xxx.xxx.xxx.

@alchris
Copy link
Author

alchris commented Feb 15, 2016

@jblobb
gitolite and redmine run on the same host, so 127.0.0.1 is the right IP address.

As far as I can see gogs, doesn't integrate to Redmine.

Yes I know, that's ok for us. Thanks!

@jblobb
Copy link

jblobb commented Feb 15, 2016

@alchris Yes, I understand that they are on the same host.

It's not suppose to be 127.0.0.1. When you ssh to that box you don't use 127.0.0.1 it's the IP address.

I was having issues with this plugin on the standard port 22. I think that you have changed all the other values, you just need to change that IP.

I'm 95% sure it will work just by changing that IP, in the the cli, then updating the hooks.

I've had 2 other people follow this guide I've made and it works.

#567 (comment)

@alchris
Copy link
Author

alchris commented Feb 15, 2016

ssh works with this IP:

$ ssh -i .ssh/gitolite_admin_id_rsa -p 1122 gitolite@127.0.0.1 info

hello admin, this is gitolite@localhost running gitolite3 3.6.1-2 (Debian) on git 2.1.4

 R W    gitolite-admin
 R W    testing

@jblobb
Copy link

jblobb commented Feb 16, 2016

Yes, that's because you're on the localhost, which means your forcing it to bind it to the localhost. So you get an Rugged::OSError: Failed to connect to localhost: Connection refused when you're trying to connect from another source.

I don't know what to tell you. I didn't write this plugin, I've just found the work around. I know setting 127.0.0.1 in the settings.yml won't allow you to connect, but using the IP address will.

@alchris
Copy link
Author

alchris commented Feb 16, 2016

@jblobb
Ok, I tried it with the external IP of the server. As expect, the problem still exists.

@seberoth
Copy link

Just had the same problem. After hours of debugging, I found the problem. See b43ffb4

@hallux4
Copy link

hallux4 commented Mar 19, 2016

@seberoth
OMG, I LOVE YOU !

I loose my mind since yesterday beacause of this.

@PowerKiKi
Copy link
Collaborator

@n-rodriguez, it seems that a few of us got bitten by this bug, even though there is a known fix committed on devel. Would it be possible to cut a release including that fix please ?

@n-rodriguez
Copy link
Contributor

Would it be possible to cut a release including that fix please ?

Yes

@n-rodriguez n-rodriguez added this to the v1.2.1 milestone Jul 23, 2016
@n-rodriguez
Copy link
Contributor

Fixed : b43ffb4

A new release is coming ;)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

6 participants