Beginners Guide to Install Discourse on Windows 10 for Development

dev-install
(Vinoth Kannan) #1

So you want to set up development environment for Discourse on Windows 10? You can do it easily using Windows Subsystem for Linux feature. It is faster too :star_struck:.

This setup needs Windows 10 Anniversary Update. We’ll assume that you already installed Windows Subsystem for Linux (Ubuntu) on your Windows 10 system. Let’s begin!

  1. Initially follow the steps from the topic Beginners Guide to Install Discourse on Ubuntu for Development until the step Clone Discourse.

    Before setting up the database you have to start PostgreSQL service & Redis server manually using following commands

    sudo service postgresql start
    redis-server --daemonize yes
    
  2. Then go through all the remaining steps of the Ubuntu guide.

Now your development environment is almost ready. The only problem is every time when you open Ubuntu on Windows you have to start PostgreSQL service & Redis server manually. Don’t worry we can have a work around for this by creating a custom command :wink:.

cd ~

Create a new file using the command nano start-discourse and paste the content below then save and exit.

#!/bin/bash

# to start PostgreSQL
sudo service postgresql start

# to start redis server
redis-server --daemonize yes

Now modify the CHMOD using below command

chmod +x start-discourse

And copy the file to your bin folder

sudo cp start-discourse /usr/bin/

It’s done. Now whenever you open the Ubuntu bash just run the command below and start developing :+1:

start-discourse

To launch web server use bundle exec puma instead of rails server.

29 Likes
How to install Discourse on windows
Help installing Discourse for Developer
Database connection error when setting up Discourse development environment using Linux Bash Shell on Windows 10
Beginners Guide to Install Discourse on Ubuntu for Development
Restoring backup fails in Win10/Ubuntu development environment
Restoring backup fails in Win10/Ubuntu development environment
How to add a new language
Can't set up dev environment due to cppjieba_rb failing to install
Beginners Guide to Install Discourse on Ubuntu for Development
Discourse installation end to end on Windows Server 2016
Beginners Guide to Install Discourse on Ubuntu for Development
Discourse Development Contribution Guidelines
Dev Category sidebar
Beginners Guide to Install Discourse on Ubuntu for Development
Restoring backup fails in Win10/Ubuntu development environment
No connection to db issue
»vagrant up« hangs
Discourse-webpack: A boilerplate for developing JS-heavy Discourse components
Dev Category sidebar
(Subasa) #4

thanks you, very very helpful for me!

1 Like
#5

Great stuff here.

Having just completed an installation using this guide, here are two important notes you need to take into account:

  1. These instructions install Postgres 9.5, not Postgres 10 (which is in the official Docker image). You will need to upgrade your Postgres installation to be fully compatible with a Docker installation (backing up & restoring, for instance, will NOT work unless you update).

  2. I would alter the start-discourse command thusly, to ensure Sidekiq processes queues:

    #!/bin/bash
    
     # to start PostgreSQL
     sudo service postgresql start
    
     # to start redis server
     redis-server --daemonize yes
    
     # start Sidekiq (daemonized) with proper config or queues will not be processed!
     bundle exec sidekiq -d -C ./config/sidekiq.yml
5 Likes
(Vinoth Kannan) #6

It should be updated in original Ubuntu guide. cc @techAPJ

3 Likes
(Lê Trần Đạt) #7

For people who get this error

PG::Error: ERROR:  new encoding (UTF8) is incompatible with the encoding of the template database (SQL_ASCII)

Follow the answer here:

5 Likes
(Thang Nguyen) #8

I am trying to set up the environment on Windows 10 (with Ubuntu as like above). Anyone has Unicorn error while trying to start the server ? The Unicorn errors keep looping and looping.

I, [2018-09-25T22:46:25.156669 #20007]  INFO -- : Refreshing Gem list
Starting CSS change watcher
  SiteSetting Load (0.5ms)  SELECT  "site_settings".* FROM "site_settings" WHERE "site_settings"."name" = 'vapid_public_key_bytes' LIMIT 1
E, [2018-09-25T22:46:30.068875 #20007] ERROR -- : 0.0.0.0:3000 {:tcp_defer_accept=>1, :accept_filter=>"httpready", :backlog=>1024, :tcp_nopush=>nil, :tcp_nodelay=>true}: Protocol not available - setsockopt(2) (Errno::ENOPROTOOPT)
E, [2018-09-25T22:46:30.070322 #20007] ERROR -- : /home/hongthang152/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/unicorn-5.4.0/lib/unicorn/socket_helper.rb:74:in `setsockopt'
E, [2018-09-25T22:46:30.070588 #20007] ERROR -- : /home/hongthang152/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/unicorn-5.4.0/lib/unicorn/socket_helper.rb:74:in `set_tcp_sockopt'
E, [2018-09-25T22:46:30.070858 #20007] ERROR -- : /home/hongthang152/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/unicorn-5.4.0/lib/unicorn/socket_helper.rb:93:in `set_server_sockopt'
E, [2018-09-25T22:46:30.071134 #20007] ERROR -- : /home/hongthang152/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/unicorn-5.4.0/lib/unicorn/socket_helper.rb:148:in `bind_listen'
E, [2018-09-25T22:46:30.071253 #20007] ERROR -- : /home/hongthang152/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/unicorn-5.4.0/lib/unicorn/http_server.rb:241:in `listen'
E, [2018-09-25T22:46:30.071537 #20007] ERROR -- : /home/hongthang152/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/unicorn-5.4.0/lib/unicorn/http_server.rb:851:in `block in bind_new_listeners!'
E, [2018-09-25T22:46:30.071809 #20007] ERROR -- : /home/hongthang152/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/unicorn-5.4.0/lib/unicorn/http_server.rb:851:in `each'
E, [2018-09-25T22:46:30.072045 #20007] ERROR -- : /home/hongthang152/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/unicorn-5.4.0/lib/unicorn/http_server.rb:851:in `bind_new_listeners!'
E, [2018-09-25T22:46:30.072755 #20007] ERROR -- : /home/hongthang152/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/unicorn-5.4.0/lib/unicorn/http_server.rb:140:in `start'
E, [2018-09-25T22:46:30.073488 #20007] ERROR -- : /home/hongthang152/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/unicorn-5.4.0/bin/unicorn:126:in `<top (required)>'
E, [2018-09-25T22:46:30.074071 #20007] ERROR -- : /home/hongthang152/discourse/bin/unicorn:48:in `load'
E, [2018-09-25T22:46:30.074857 #20007] ERROR -- : /home/hongthang152/discourse/bin/unicorn:48:in `<main>'
I, [2018-09-25T22:46:30.075617 #20007]  INFO -- : listening on addr=0.0.0.0:3000 fd=13
(Thang Nguyen) #9

Nevermind. Ruby unicorn server seems to be broken on WSL. For those who encountered the above problem, starts the server with Puma server instead.

Run this script
bundle exec puma

8 Likes
Beginners Guide to Install Discourse on Ubuntu for Development
#21

Hi,

Does it mean buncle exec puma creates automatically the database (and others things like you would see on the Ubuntu guide)?

Because it doesn’t seem the case. If I don’t follow the other guide steps, at least:

sudo -u postgres createuser -s techapj
cd ~/discourse
source ~/.bashrc
bundle install
bundle exec rake db:create db:migrate
RAILS_ENV=test bundle exec rake db:create db:migrate

It doesn’t work.
Without creating the DB, It says that discourse_development database (or whatever the name) doesn’t exist after executing bundle exec puma.

Even if I’ve somehow succeeded to launch the web server after following the extra steps, there are a few things I’m not sure.

How to run properly Sidekiq? I tried the third post, but it throws an error:

bundle exec sidekiq -d -C config/sidekiq.yml
You really should set a logfile if you're going to daemonize
/home/arkshine/.rbenv/versions/2.5.3/lib/ruby/gems/2.5.0/gems/sidekiq-5.1.3/lib/sidekiq/cli.rb:193:in `daemonize'
/home/arkshine/.rbenv/versions/2.5.3/lib/ruby/gems/2.5.0/gems/sidekiq-5.1.3/lib/sidekiq/cli.rb:41:in `parse'
/home/arkshine/.rbenv/versions/2.5.3/lib/ruby/gems/2.5.0/gems/sidekiq-5.1.3/bin/sidekiq:11:in `<top (required)>'
/home/arkshine/.rbenv/versions/2.5.3/bin/sidekiq:23:in `load'
/home/arkshine/.rbenv/versions/2.5.3/bin/sidekiq:23:in `<top (required)>'
/home/arkshine/.rbenv/versions/2.5.3/lib/ruby/site_ruby/2.5.0/bundler/cli/exec.rb:74:in `load'
/home/arkshine/.rbenv/versions/2.5.3/lib/ruby/site_ruby/2.5.0/bundler/cli/exec.rb:74:in `kernel_load'
/home/arkshine/.rbenv/versions/2.5.3/lib/ruby/site_ruby/2.5.0/bundler/cli/exec.rb:28:in `run'
/home/arkshine/.rbenv/versions/2.5.3/lib/ruby/site_ruby/2.5.0/bundler/cli.rb:463:in `exec'
/home/arkshine/.rbenv/versions/2.5.3/lib/ruby/site_ruby/2.5.0/bundler/vendor/thor/lib/thor/command.rb:27:in `run'
/home/arkshine/.rbenv/versions/2.5.3/lib/ruby/site_ruby/2.5.0/bundler/vendor/thor/lib/thor/invocation.rb:126:in `invoke_command'
/home/arkshine/.rbenv/versions/2.5.3/lib/ruby/site_ruby/2.5.0/bundler/vendor/thor/lib/thor.rb:387:in `dispatch'
/home/arkshine/.rbenv/versions/2.5.3/lib/ruby/site_ruby/2.5.0/bundler/cli.rb:27:in `dispatch'
/home/arkshine/.rbenv/versions/2.5.3/lib/ruby/site_ruby/2.5.0/bundler/vendor/thor/lib/thor/base.rb:466:in `start'
/home/arkshine/.rbenv/versions/2.5.3/lib/ruby/site_ruby/2.5.0/bundler/cli.rb:18:in `start'
/home/arkshine/.rbenv/versions/2.5.3/lib/ruby/gems/2.5.0/gems/bundler-1.17.3/exe/bundle:30:in `block in <top (required)>'
/home/arkshine/.rbenv/versions/2.5.3/lib/ruby/site_ruby/2.5.0/bundler/friendly_errors.rb:124:in `with_friendly_errors'
/home/arkshine/.rbenv/versions/2.5.3/lib/ruby/gems/2.5.0/gems/bundler-1.17.3/exe/bundle:22:in `<top (required)>'
/home/arkshine/.rbenv/versions/2.5.3/bin/bundle:23:in `load'
/home/arkshine/.rbenv/versions/2.5.3/bin/bundle:23:in `<main>'

In the web server, I have àlso /message-bus failing (Rack app error handling request { POST /message-bus/c6be067fffe44ee5bc1e902ecd83d9ea/poll } #<Errno::EPIPE: Broken pipe>, is it realted to sidekiq?).

Did I miss something? It’s really confusing. Thanks.

1 Like
(Vinoth Kannan) #22

You’ve to follow those steps.

You can run sidekiq by the command bundle exec sidekiq. No need to specify the config file.

4 Likes
(Rishabh Nambiar) #24

I’ve updated the guide to clearly mention that the remaining steps have to be carried out, thanks!

4 Likes
#25

Thanks for updating. It makes more sense now. :ok_hand:

Though you are telling to not use rails server only at the very bottom of this page and then before the “go through all the remaining steps of the Ubuntu guide” includes executing that command. I would suggest leaving a note about it because the way you follow logically this guide, you can be sure people will try it and it won’t work as expected. :thinking:


Is there a reason sidekiq is not part of this guide?
Personally, I added this in start-discourse:

cd ~/discourse
bundle exec sidekiq --daemon --logfile "log/sidekiq.log"

Maybe adding also:

bundle exec puma --daemon --redirect-stdout "log/puma.log" --redirect-stderr "log/puma_error.log"

For now, it seems to work.

I have one immediate issue is the images with localhost in the URL are broken due to the missing port, example:


I did not find any port settings. Is something can be done for that?


Another issue is it seems I can’t upgrade in this environment. Is it expected?


image

1 Like
(Danny Goodall) #26

Am I ever having fun!!

Hi, I am trying to get WSL working as I stupidly (so amazingly stupidly) decided to upgrade my development Ubuntu machine from 16.04 to 18.04 and now I can’t configure the display adapter…

…anyway, so I’m trying to install Discourse dev under Windows Subsystem for Linux and I’ve followed the instructions here and in the Ubuntu Dev thread but am running into problems running the rake db:create db:migrate command.

$ bundle exec rake db:create db:migrate
No connection to db, unable to retrieve site settings! (normal when running db:create)
No connection to db, unable to retrieve site settings! (normal when running db:create)
No connection to db, unable to retrieve site settings! (normal when running db:create)
No connection to db, unable to retrieve site settings! (normal when running db:create)
No connection to db, unable to retrieve site settings! (normal when running db:create)
No connection to db, unable to retrieve site settings! (normal when running db:create)
No connection to db, unable to retrieve site settings! (normal when running db:create)
No connection to db, unable to retrieve site settings! (normal when running db:create)
could not connect to server: No such file or directory
        Is the server running locally and accepting
        connections on Unix domain socket "/var/run/postgresql/.s.PGSQL.5432"?
Couldn't create 'discourse_development' database. Please check your configuration.
rake aborted!
PG::ConnectionBad: could not connect to server: No such file or directory
        Is the server running locally and accepting
        connections on Unix domain socket "/var/run/postgresql/.s.PGSQL.5432"?

This looks like the same problem reported in the Ubuntu dev thread.

What have I tried?

I’ve checked that Postgres is running. Which it appears to be:

ps -fe | grep "postg"
postgres    71     1  0 16:58 ?        00:00:01 /usr/lib/postgresql/10/bin/postgres -D /var/lib/postgresql/10/main -c config_file=/etc/postgresql/10/main/postgresql.conf
postgres    73    71  0 16:58 ?        00:00:00 postgres: 10/main: checkpointer process
postgres    74    71  0 16:58 ?        00:00:00 postgres: 10/main: writer process
postgres    75    71  0 16:58 ?        00:00:00 postgres: 10/main: wal writer process
postgres    76    71  0 16:58 ?        00:00:00 postgres: 10/main: autovacuum launcher process
postgres    77    71  0 16:58 ?        00:00:01 postgres: 10/main: stats collector process
postgres    78    71  0 16:58 ?        00:00:00 postgres: 10/main: bgworker: logical replication launcher
$ sudo service postgresql status
10/main (port 5433): online

I’ve checked that my user Postgres user was created and that it is the same name as my Ubuntu username (danny).

sudo -u postgres psql postgres
psql (10.6 (Ubuntu 10.6-0ubuntu0.18.04.1))
Type "help" for help.

postgres=# \du
                                   List of roles
 Role name |                         Attributes                         | Member of
-----------+------------------------------------------------------------+-----------
 danny     | Superuser, Create role, Create DB                          | {}
 postgres  | Superuser, Create role, Create DB, Replication, Bypass RLS | {}

postgres=#

I’ve started Redis, and it seems to be running.

$ redis-cli ping
PONG

Because I’m on a host Windows system which had its own Postgres (on Windows) installation, I’ve stopped the service and then subsequently removed the Windows Postgres installation, but still the same result.

I’ve restarted the Linux subsystem as well as Windows.

I’ve turned off the Windows Firewall but still to no avail.

Here is the rake command with --trace in case it sheds any more light.

bundle exec rake db:create db:migrate --trace
** Invoke db:create (first_time)
** Invoke db:load_config (first_time)
** Invoke environment (first_time)
** Execute environment
No connection to db, unable to retrieve site settings! (normal when running db:create)
No connection to db, unable to retrieve site settings! (normal when running db:create)
No connection to db, unable to retrieve site settings! (normal when running db:create)
No connection to db, unable to retrieve site settings! (normal when running db:create)
No connection to db, unable to retrieve site settings! (normal when running db:create)
No connection to db, unable to retrieve site settings! (normal when running db:create)
No connection to db, unable to retrieve site settings! (normal when running db:create)
No connection to db, unable to retrieve site settings! (normal when running db:create)
** Execute db:load_config
** Execute db:create
could not connect to server: No such file or directory
        Is the server running locally and accepting
        connections on Unix domain socket "/var/run/postgresql/.s.PGSQL.5432"?
Couldn't create 'discourse_development' database. Please check your configuration.
rake aborted!
PG::ConnectionBad: could not connect to server: No such file or directory
        Is the server running locally and accepting
        connections on Unix domain socket "/var/run/postgresql/.s.PGSQL.5432"?
/home/danny/.rbenv/versions/2.5.3/lib/ruby/gems/2.5.0/gems/pg-1.1.3/lib/pg.rb:56:in `initialize'
/home/danny/.rbenv/versions/2.5.3/lib/ruby/gems/2.5.0/gems/pg-1.1.3/lib/pg.rb:56:in `new'
/home/danny/.rbenv/versions/2.5.3/lib/ruby/gems/2.5.0/gems/pg-1.1.3/lib/pg.rb:56:in `connect'
/home/danny/.rbenv/versions/2.5.3/lib/ruby/gems/2.5.0/gems/activerecord-5.2.2/lib/active_record/connection_adapters/postgresql_adapter.rb:692:in `connect'
/home/danny/.rbenv/versions/2.5.3/lib/ruby/gems/2.5.0/gems/activerecord-5.2.2/lib/active_record/connection_adapters/postgresql_adapter.rb:223:in `initialize'
/home/danny/.rbenv/versions/2.5.3/lib/ruby/gems/2.5.0/gems/activerecord-5.2.2/lib/active_record/connection_adapters/postgresql_adapter.rb:48:in `new'
/home/danny/.rbenv/versions/2.5.3/lib/ruby/gems/2.5.0/gems/activerecord-5.2.2/lib/active_record/connection_adapters/postgresql_adapter.rb:48:in `postgresql_connection'
/home/danny/.rbenv/versions/2.5.3/lib/ruby/gems/2.5.0/gems/activerecord-5.2.2/lib/active_record/connection_adapters/abstract/connection_pool.rb:811:in `new_connection'
/home/danny/.rbenv/versions/2.5.3/lib/ruby/gems/2.5.0/gems/activerecord-5.2.2/lib/active_record/connection_adapters/abstract/connection_pool.rb:855:in `checkout_new_connection'
/home/danny/.rbenv/versions/2.5.3/lib/ruby/gems/2.5.0/gems/activerecord-5.2.2/lib/active_record/connection_adapters/abstract/connection_pool.rb:834:in `try_to_checkout_new_connection'
/home/danny/.rbenv/versions/2.5.3/lib/ruby/gems/2.5.0/gems/activerecord-5.2.2/lib/active_record/connection_adapters/abstract/connection_pool.rb:795:in `acquire_connection'
/home/danny/.rbenv/versions/2.5.3/lib/ruby/gems/2.5.0/gems/activerecord-5.2.2/lib/active_record/connection_adapters/abstract/connection_pool.rb:523:in `checkout'
/home/danny/.rbenv/versions/2.5.3/lib/ruby/gems/2.5.0/gems/activerecord-5.2.2/lib/active_record/connection_adapters/abstract/connection_pool.rb:382:in `connection'
/home/danny/.rbenv/versions/2.5.3/lib/ruby/gems/2.5.0/gems/activerecord-5.2.2/lib/active_record/connection_adapters/abstract/connection_pool.rb:1010:in `retrieve_connection'
/home/danny/.rbenv/versions/2.5.3/lib/ruby/gems/2.5.0/gems/activerecord-5.2.2/lib/active_record/connection_handling.rb:118:in `retrieve_connection'
/home/danny/.rbenv/versions/2.5.3/lib/ruby/gems/2.5.0/gems/activerecord-5.2.2/lib/active_record/connection_handling.rb:90:in `connection'
/home/danny/.rbenv/versions/2.5.3/lib/ruby/gems/2.5.0/gems/activerecord-5.2.2/lib/active_record/tasks/postgresql_database_tasks.rb:12:in `connection'
/home/danny/.rbenv/versions/2.5.3/lib/ruby/gems/2.5.0/gems/activerecord-5.2.2/lib/active_record/tasks/postgresql_database_tasks.rb:21:in `create'
/home/danny/.rbenv/versions/2.5.3/lib/ruby/gems/2.5.0/gems/activerecord-5.2.2/lib/active_record/tasks/database_tasks.rb:119:in `create'
/home/danny/.rbenv/versions/2.5.3/lib/ruby/gems/2.5.0/gems/activerecord-5.2.2/lib/active_record/tasks/database_tasks.rb:139:in `block in create_current'
/home/danny/.rbenv/versions/2.5.3/lib/ruby/gems/2.5.0/gems/activerecord-5.2.2/lib/active_record/tasks/database_tasks.rb:316:in `block in each_current_configuration'
/home/danny/.rbenv/versions/2.5.3/lib/ruby/gems/2.5.0/gems/activerecord-5.2.2/lib/active_record/tasks/database_tasks.rb:313:in `each'
/home/danny/.rbenv/versions/2.5.3/lib/ruby/gems/2.5.0/gems/activerecord-5.2.2/lib/active_record/tasks/database_tasks.rb:313:in `each_current_configuration'
/home/danny/.rbenv/versions/2.5.3/lib/ruby/gems/2.5.0/gems/activerecord-5.2.2/lib/active_record/tasks/database_tasks.rb:138:in `create_current'
/home/danny/.rbenv/versions/2.5.3/lib/ruby/gems/2.5.0/gems/activerecord-5.2.2/lib/active_record/railties/databases.rake:29:in `block (2 levels) in <main>'
/home/danny/.rbenv/versions/2.5.3/lib/ruby/gems/2.5.0/gems/rake-12.3.2/lib/rake/task.rb:273:in `block in execute'
/home/danny/.rbenv/versions/2.5.3/lib/ruby/gems/2.5.0/gems/rake-12.3.2/lib/rake/task.rb:273:in `each'
/home/danny/.rbenv/versions/2.5.3/lib/ruby/gems/2.5.0/gems/rake-12.3.2/lib/rake/task.rb:273:in `execute'
/home/danny/.rbenv/versions/2.5.3/lib/ruby/gems/2.5.0/gems/rake-12.3.2/lib/rake/task.rb:214:in `block in invoke_with_call_chain'
/home/danny/.rbenv/versions/2.5.3/lib/ruby/2.5.0/monitor.rb:226:in `mon_synchronize'
/home/danny/.rbenv/versions/2.5.3/lib/ruby/gems/2.5.0/gems/rake-12.3.2/lib/rake/task.rb:194:in `invoke_with_call_chain'
/home/danny/.rbenv/versions/2.5.3/lib/ruby/gems/2.5.0/gems/rake-12.3.2/lib/rake/task.rb:183:in `invoke'
/home/danny/.rbenv/versions/2.5.3/lib/ruby/gems/2.5.0/gems/rake-12.3.2/lib/rake/application.rb:160:in `invoke_task'
/home/danny/.rbenv/versions/2.5.3/lib/ruby/gems/2.5.0/gems/rake-12.3.2/lib/rake/application.rb:116:in `block (2 levels) in top_level'
/home/danny/.rbenv/versions/2.5.3/lib/ruby/gems/2.5.0/gems/rake-12.3.2/lib/rake/application.rb:116:in `each'
/home/danny/.rbenv/versions/2.5.3/lib/ruby/gems/2.5.0/gems/rake-12.3.2/lib/rake/application.rb:116:in `block in top_level'
/home/danny/.rbenv/versions/2.5.3/lib/ruby/gems/2.5.0/gems/rake-12.3.2/lib/rake/application.rb:125:in `run_with_threads'
/home/danny/.rbenv/versions/2.5.3/lib/ruby/gems/2.5.0/gems/rake-12.3.2/lib/rake/application.rb:110:in `top_level'
/home/danny/.rbenv/versions/2.5.3/lib/ruby/gems/2.5.0/gems/rake-12.3.2/lib/rake/application.rb:83:in `block in run'
/home/danny/.rbenv/versions/2.5.3/lib/ruby/gems/2.5.0/gems/rake-12.3.2/lib/rake/application.rb:186:in `standard_exception_handling'
/home/danny/.rbenv/versions/2.5.3/lib/ruby/gems/2.5.0/gems/rake-12.3.2/lib/rake/application.rb:80:in `run'
/home/danny/.rbenv/versions/2.5.3/lib/ruby/gems/2.5.0/gems/rake-12.3.2/exe/rake:27:in `<top (required)>'
/home/danny/.rbenv/versions/2.5.3/bin/rake:23:in `load'
/home/danny/.rbenv/versions/2.5.3/bin/rake:23:in `<top (required)>'
/home/danny/.rbenv/versions/2.5.3/lib/ruby/site_ruby/2.5.0/bundler/cli/exec.rb:74:in `load'
/home/danny/.rbenv/versions/2.5.3/lib/ruby/site_ruby/2.5.0/bundler/cli/exec.rb:74:in `kernel_load'
/home/danny/.rbenv/versions/2.5.3/lib/ruby/site_ruby/2.5.0/bundler/cli/exec.rb:28:in `run'
/home/danny/.rbenv/versions/2.5.3/lib/ruby/site_ruby/2.5.0/bundler/cli.rb:463:in `exec'
/home/danny/.rbenv/versions/2.5.3/lib/ruby/site_ruby/2.5.0/bundler/vendor/thor/lib/thor/command.rb:27:in `run'
/home/danny/.rbenv/versions/2.5.3/lib/ruby/site_ruby/2.5.0/bundler/vendor/thor/lib/thor/invocation.rb:126:in `invoke_command'
/home/danny/.rbenv/versions/2.5.3/lib/ruby/site_ruby/2.5.0/bundler/vendor/thor/lib/thor.rb:387:in `dispatch'
/home/danny/.rbenv/versions/2.5.3/lib/ruby/site_ruby/2.5.0/bundler/cli.rb:27:in `dispatch'
/home/danny/.rbenv/versions/2.5.3/lib/ruby/site_ruby/2.5.0/bundler/vendor/thor/lib/thor/base.rb:466:in `start'
/home/danny/.rbenv/versions/2.5.3/lib/ruby/site_ruby/2.5.0/bundler/cli.rb:18:in `start'
/home/danny/.rbenv/versions/2.5.3/lib/ruby/gems/2.5.0/gems/bundler-1.17.3/exe/bundle:30:in `block in <top (required)>'
/home/danny/.rbenv/versions/2.5.3/lib/ruby/site_ruby/2.5.0/bundler/friendly_errors.rb:124:in `with_friendly_errors'
/home/danny/.rbenv/versions/2.5.3/lib/ruby/gems/2.5.0/gems/bundler-1.17.3/exe/bundle:22:in `<top (required)>'
/home/danny/.rbenv/versions/2.5.3/bin/bundle:23:in `load'
/home/danny/.rbenv/versions/2.5.3/bin/bundle:23:in `<main>'
Tasks: TOP => db:create

Any ideas?

(Danny Goodall) #27

EDIT: my two posts are minutes apart because I forgot to press Reply to the first one. I’ve since done some more digging.

EDIT2: So here is what I think is going on.

There seems to be a problem with ident identification on WSL. i.e. the operating system username, on its own, doesn’t seem to allow clients to connect to Postgres.

So two problems here - one Postgres installed on the wrong port and user identification seems not to work on WSL.

Port problem

The Postgres server is running on 5433 and rake is expecting it on 5432.

I installed Postgres (using the Discourse dev setup script) into the Windows Subsystem for Linux but I already had a Postgres server running on port 5432 in the native Windows system.

I assume that as a result the WSL Postgres server got bumped to 5433. So, after uninstalling the Postgres windows server, I changed the postgresql.conf file to start on port 5432. This then allowed me to connect to Postgres - by using su - postgres.

Validation of User

By trying to connect to the server, now running on the correct port, using psql it would ask me for a password for the user with my username danny.

Now I created the danny Postrges user, using @techAPJ’s instructions here…

I obviously changed techapj to danny but at no time in the creation process was I asked for a password.

My assumption here is that the Postgres createuser command creates a Postgres user linked to a local user and that it relies on the operating system to identify and validate the user - hence no password?

So why was I being asked for a password when I was logged in as the user danny?

When I looked in the 'pg_hba.conf` (which controls how users gain access for different types of connection - local, tcp, etc.) file…

# DO NOT DISABLE!
# If you change this first entry you will need to make sure that the
# database superuser can access the database using some other method.
# Noninteractive access to all databases is required during automatic
# maintenance (custom daily cronjobs, replication, and similar tasks).
#
# Database administrative login by Unix domain socket
local   all             postgres                                peer

# TYPE  DATABASE        USER            ADDRESS                 METHOD

# "local" is for Unix domain socket connections only
local   all             all                                     peer
# IPv4 local connections:
host    all             all             127.0.0.1/32            ident
# IPv6 local connections:
host    all             all             ::1/128                 ident
# Allow replication connections from localhost, by a user with the
# replication privilege.
local   replication     all                                     peer
host    replication     all             127.0.0.1/32            md5
host    replication     all             ::1/128                 md5

…the method of connection for the danny user was set to ident - i.e let the operating system handle identification. But again, I was logged in as danny and was still challenged for my password. So I don’t know why that wasn’t working.

To test if this was causing the problem, and because this is my dev system with no crucial data, I changed the ident setting to trust which it seems allows a connection with no challenge at all.

Et voila, I was connected and it worked - the rake command executed and I’ve started the server and got the party time splash screen.

I note that the instructions for creating the database user on the Beginners Guide to Install Discourse on Ubuntu for Development thread changed in the not so distant past.

The instructions used to be (revision 45).

Setup Database

Open psql prompt as postgres user

sudo -u postgres psql postgres

Create role with the same name as your ubuntu system username with discourse as password:

CREATE ROLE techapj WITH LOGIN ENCRYPTED PASSWORD 'discourse' CREATEDB SUPERUSER;

I wonder if these instruction might still need to be followed for WSL? i.e. explicitly specify a password.

IF I get time I will try a reinstallation and test at each stage because the trust solution does feel like a solution, TBH.

(Oz Ramos) #28

Should we be mounting into Windows from the Linux Subsystem (eg: $ cd /mnt/c) if we plan to use our Windows code editor to develop?

In the Beginners Guide to Install Discourse on Ubuntu for Development, we clone the Discourse repo into ~/discourse, which is actually physically saving it onto your harddrive under: C:\Users\{USER}\AppData\Local\Packages\CanonicalGroupLimited.UbuntuonWindows_79rhkp1fndgsc

However, I’ve been reading that we shouldn’t actually edit any files in this path using Windows tools because it can corrupt the Linux environment (https://askubuntu.com/a/759885). So should we actually be cloning into /mnt/c/... and doing everything from there or does it not matter? Basically I just want to develop a simple component and it would be easier to do with my current setup

Edit: Never mind, I’m using the Discourse Theme CLI now!

(SteveM) #29

If anyone runs into this error while trying to start pg on WSL:

PANIC: could not flush dirty data: Function not implemented

The solution is to set fsync = off in /etc/postgresql.conf (see here)
Just note that this puts you at risk of data corruption on system crash. (see here)

(Sam Saffron) #30

Looks like PG are going to workaround this WSL limitation shortly.

https://www.postgresql.org/message-id/flat/CA%2BmCpegfOUph2U4ZADtQT16dfbkjjYNJL1bSTWErsazaFjQW9A%40mail.gmail.com

2 Likes