gogs: Fail to initialize ORM engine: migrate: sync

Hi! I’m using a MySQL database. I’m not sure what changed, but now it shuts down after some time. I get this error in gogs.log:

2016/02/04 13:35:11 [...s/routers/install.go:70 GlobalInit()] [E] Fail to initialize ORM engine: migrate: sync: dial tcp 127.0.0.1:3306: getsockopt: connection refused

This is my database configuration

[database]
DB_TYPE = mysql
HOST = 127.0.0.1:3306
NAME = gogs
USER = gogs
PASSWD = ******
SSL_MODE = disable
PATH = data/gogs.db

Any idea what could cause this error? And I’m also unsure about the PATH = data/gogs.db part since I’m using a MySQL server it shouldn’t need the path to a database file?

Thanks

About this issue

  • Original URL
  • State: closed
  • Created 8 years ago
  • Reactions: 2
  • Comments: 23 (9 by maintainers)

Commits related to this issue

Most upvoted comments

. I fixed this on Debian Jessie by adding After=mysql.service to gogs.service.

Hi, I had this problem when the server was rebooted. In my case the problem was Gogs starting before Mysql.

My server is running Debian 8 (Jessie) so modifying /etc/init.d/gogs Required-Start and adding mysql to it has fixed it: # Required-Start: $syslog $network mysql

and then run insserv -d

So for the op the problem might be with Mysql rather than Gogs.

@DanielGilbert The After= line alone should be adequate according to this systemd man page:

Type= […] Behavior of idle is very similar to simple; however, actual execution of the service binary is delayed until all active jobs are dispatched. This may be used to avoid interleaving of output of shell services with the status output on the console. Note that this type is useful only to improve console output, it is not useful as a general unit ordering tool, and the effect of this service type is subject to a 5s time-out, after which the service binary is invoked anyway.

(I also had this issue with Debian 8 – the resaon was that I had mysqld.service instead of mysql.service in the systemd unit. 😉)

Just to add a note for future reference.

I am running Gogs version 0.9.20.0404 on centos7 with exact same issue of gogs failed to connect to mysql. Following is my work around script.

#!/bin/bash
#  work around untils issue is fixed at https://github.com/gogits/gogs/issues/2553
PATH=$PATH:/sbin:/bin:/usr/sbin:/usr/bin
PIDS=$(pidof gogs)

if test -z "${PIDS}"
then
   echo  `date`  | mailx -s "gogs is dead, restarting... "  me@test.com
   /usr/bin/systemctl restart gogs
fi

$vim /etc/systemd/system/gogs.service Append mysql.service to Alfter= line.

Is it worth it to add a comment in gogs.service highlighting the mysqld/mysql mess? It’s a not so obvious source of errors.

My 2c, on Ubuntu 14.04 with packager.io Gogs both MySQL and Gogs are upstart services. So:

/etc/init/gogs.conf

and change:

start on runlevel [2345]
stop on runlevel [06]

into

start on started mysql
stop on runlevel [06]

else, Gogs will fail to start after server reboot.