Server Error 500 on Admin / Dashboard

Hello,
Getting Server Error 500 on Admin / Dashboard.

here is the error in the /logs

Any ideas? I had this last week but an app rebuild fixed it. (I will do that but I wanted to see if anyone else saw this)

You should simply get latest and rebuild first.

2 Likes

I am still getting this error on my dashboard
{“status”:500,“error”:“Internal Server Error”}
Can anybody help?

Thanks in advance!!

From the SSH command line, get latest and rebuild.

cd /var/discourse
./launcher rebuild app
3 Likes

I have deployed without docker. so there is no ./ launcher. I simply deploy with capistrano 3. I am also using multisite.
Can you please help me out for this?

No, we only support the docker install here, as stated many places, many times.

I have solved the above problem. Can anyone help with this ?

I am getting this error for admin dashboard.

Thanks in advance !!

Hello @vaibhavclecotech :slight_smile:

I think, I can help you with this.

class AdminDashboardGeneralData < AdminDashboardData
  def get_json
    days_since_update = ((DateTime.now - Discourse.last_commit_date) / 1.day).to_i
    {
      updated_at: Time.zone.now.as_json,
      discourse_updated_at: Discourse.last_commit_date,
      release_notes_link: "https://meta.discourse.org/c/feature/announcements?tags=release-notes&before=#{days_since_update}"
    }
  end
  ...
end

As per my understanding on Discourse,
you should be getting error because of this line

Discourse.last_commit_date

If you will run this command in your production rails console. you will see the error mentioned below.

irb(main):002:0> Discourse.last_commit_date
fatal: not a git repository (or any of the parent directories): .git

I think, you are just using the Cap deployment script for you deployment purpose. Obviously, it never stores the git commits etc. at the server so you will always get error while accessing /admin/dashboard/general.json

You are using Discourse.last_commit_date and it is looking for the date of the last commit but it’s not possible with cap deployment.

Don’t worry, I can even help you fixing this problem:
FYI: It’s just to solve your issue :slight_smile: Frankly speaking, I don’t like overriding main features.

  • There is a method calls as self.last_commit_date with in the lib/discourse.rb file.
  • You should also know that Cap deployment always stores releases folders with in the releases folder. i.e 20190529092722
  • So, you just need to override the self.last_commit_date method simply and need to extract the time string from the latest release folder ( You can just read the name of all the folders of releases directory and you can sort it easily to find out the latest time string )
  • You can now use this latest release time string as a return with in your self.last_commit_date method.

You can also use Rails.root.to_s, it will give you the path of latest release folder :smiley: [Tricky :stuck_out_tongue: ] and you can follow the way I am showing you below

irb(main):041:0> Rails.root.to_s
=> "/home/deploy/projectname/releases/20190529092722"
irb(main):042:0> latest_deployment=Rails.root.to_s.split("/").last
=> "20190529092722"
irb(main):043:0> DateTime.parse(latest_deployment)
=> Wed, 29 May 2019 09:27:22 +0000

/lib/discourse.rb

  def self.last_commit_date
    ensure_version_file_loaded
    $last_commit_date ||=
      begin
        git_cmd = 'git log -1 --format="%ct"'
        seconds = self.try_git(git_cmd, nil)
        seconds.nil? ? nil : DateTime.strptime(seconds, '%s')
      end
  end

You can fix it by creating one file within initializers folder and writing the below mentioned code [:smiley: ]:

Discourse.instance_eval{
  def last_commit_date
    ensure_version_file_loaded
    $last_commit_date ||=
      begin
        latest_deployment=Rails.root.to_s.split("/").last
        DateTime.parse(latest_deployment)
      end
  end
}

Thanks :slight_smile:

5 Likes

Thank you very much @ashishprajapati,

I checked and its working very smoothly :slight_smile:
You saved my day.

1 Like