# FreeBSD port: mysql-server-5.1.29, won't boot/start



## pascalvree (Apr 26, 2009)

Hello people,

I've been running a FreeBSD server for a while right now, and for 'bout a week the mysql-server startup script located at /usr/local/etc/rc.d/mysql-server won't start the MySQL Server...

After some digging through the processlist, configuration files and start up scripts I concluded that FreeBSD assembles the command 


```
su -m mysql -c sh -c "/usr/local/bin/mysqld_safe --defaults-extra-file=/var/db/mysql/my.cnf --user=mysql --datadir=/var/db/mysql --pid-file=/var/db/mysql/ervert.pid"
```

in order to start the MySQL server through the start up script.

When I strip the su -m mysql sh -c part and run it manually it's all working fine. So I've no clue where to look next.

/etc/rc.conf does have the mysql_enable = "yes" entrie. 

--
The official mysql-server script won't give me an error, when you run it by hand, or let the machine run it during boot up; it just opens up a new shell (it's an SH shell), running with the userid mysql; I just don't seem to get it...


Do you guys have any clues left for me? Having to start the MySQL Server by hand each time the server reboots, is slowly getting on my nerves...


----------



## DutchDaemon (Apr 26, 2009)

Does that command return with return code 0 when you run *sh -xv /usr/local/etc/rc.d/mysql-server start*?


```
Starting mysql.
+ [ -n  ]
+ _doit=/usr/local/bin/mysqld_safe  --defaults-extra-file=/var/db/mysql/my.cnf --user=mysql --datadir=/var/db/mysql --pid-file=/var/db/mysql/host.domain.com.pid  > /dev/null 2>&1 &
+ [ -n mysql ]
+ _doit=su -m mysql -c 'sh -c "/usr/local/bin/mysqld_safe  --defaults-extra-file=/var/db/mysql/my.cnf --user=mysql --datadir=/var/db/mysql --pid-file=/var/db/mysql/host.domain.com.pid  > /dev/null 2>&1 &"'
+ [ -n  ]
+ _run_rc_doit su -m mysql -c 'sh -c "/usr/local/bin/mysqld_safe  --defaults-extra-file=/var/db/mysql/my.cnf --user=mysql --datadir=/var/db/mysql --pid-file=/var/db/mysql/host.domain.com.pid  > /dev/null 2>&1 &"'
+ debug run_rc_command: doit: su -m mysql -c 'sh -c "/usr/local/bin/mysqld_safe  --defaults-extra-file=/var/db/mysql/my.cnf --user=mysql --datadir=/var/db/mysql --pid-file=/var/db/mysql/host.domain.com.pid  > /dev/null 2>&1 &"'
+ eval su -m mysql -c 'sh -c "/usr/local/bin/mysqld_safe  --defaults-extra-file=/var/db/mysql/my.cnf --user=mysql --datadir=/var/db/mysql --pid-file=/var/db/mysql/host.domain.com.pid  > /dev/null 2>&1 &"'
+ su -m mysql -c sh -c "/usr/local/bin/mysqld_safe  --defaults-extra-file=/var/db/mysql/my.cnf --user=mysql --datadir=/var/db/mysql --pid-file=/var/db/mysql/host.domain.com.pid  > /dev/null 2>&1 &"
[B]+ _return=0[/B]
```


----------



## pascalvree (Apr 27, 2009)

Tenx DutchDaemon,

When I try your command it says in the end; a return value off 0... I guess the main problem has something to do with the fact, it's starts a new shell environment with the mysql user running it.

Your command gave me a debug clue  I'll have a new try this afternoon; now I've to patch up something completly different 



			
				DutchDaemon said:
			
		

> Does that command return with return code 0 when you run *sh -xv /usr/local/etc/rc.d/mysql-server start*?
> 
> 
> ```
> ...


----------



## DutchDaemon (Apr 27, 2009)

You can use this for reference:


```
: ${mysql_enable="NO"}
+ : YES
: ${mysql_limits="NO"}
+ : NO
: ${mysql_dbdir="/var/db/mysql"}
+ : /var/db/mysql
: ${mysql_args=""}
+ :

mysql_user="mysql"
+ mysql_user=mysql
mysql_limits_args="-e -U ${mysql_user}"
+ mysql_limits_args=-e -U mysql
pidfile="${mysql_dbdir}/`/bin/hostname`.pid"
+ /bin/hostname
+ pidfile=/var/db/mysql/some.host.com.pid
command="/usr/local/bin/mysqld_safe"
+ command=/usr/local/bin/mysqld_safe
command_args="--defaults-extra-file=${mysql_dbdir}/my.cnf --user=${mysql_user} --datadir=${mysql_dbdir} --pid-file=${pidfile} ${mysql_args} > /dev/null 2>&1 &"
+ command_args=--defaults-extra-file=/var/db/mysql/my.cnf --user=mysql --datadir=/var/db/mysql --pid-file=/var/db/mysql/some.host.com.pid  > /dev/null 2>&1 &
procname="/usr/local/libexec/mysqld"
+ procname=/usr/local/libexec/mysqld
start_precmd="${name}_prestart"
+ start_precmd=mysql_prestart
start_postcmd="${name}_poststart"
+ start_postcmd=mysql_poststart
mysql_install_db="/usr/local/bin/mysql_install_db"
+ mysql_install_db=/usr/local/bin/mysql_install_db
mysql_install_db_args="--ldata=${mysql_dbdir}"
+ mysql_install_db_args=--ldata=/var/db/mysql

mysql_create_auth_tables()
{
	eval $mysql_install_db $mysql_install_db_args >/dev/null 2>/dev/null
        [ $? -eq 0 ] && chown -R ${mysql_user}:${mysql_user} ${mysql_dbdir}
}

mysql_prestart()
{
	if [ ! -d "${mysql_dbdir}/mysql/." ]; then
		mysql_create_auth_tables || return 1
	fi
	if checkyesno mysql_limits; then
		eval `/usr/bin/limits ${mysql_limits_args}` 2>/dev/null
	else
		return 0
	fi
}

mysql_poststart()
{
	local timeout=15
	while [ ! -f "${pidfile}" -a ${timeout} -gt 0 ]; do
		timeout=$(( timeout - 1 ))
		sleep 1
	done
	return 0
}

run_rc_command "$1"
+ run_rc_command start
+ _return=0
+ rc_arg=start
+ [ -z mysql ]
+ shift 1
+ rc_extra_args=
+ _rc_prefix=
+ eval _override_command=$mysql_program
+ _override_command=
+ command=/usr/local/bin/mysqld_safe
+ _keywords=start stop restart rcvar 
+ rc_pid=
+ _pidcmd=
+ _procname=/usr/local/libexec/mysqld
+ [ -n /usr/local/libexec/mysqld ]
+ [ -n /var/db/mysql/some.host.com.pid ]
+ _pidcmd=rc_pid=$(check_pidfile /var/db/mysql/some.host.com.pid /usr/local/libexec/mysqld )
+ [ -n rc_pid=$(check_pidfile /var/db/mysql/some.host.com.pid /usr/local/libexec/mysqld ) ]
+ _keywords=start stop restart rcvar  status poll
+ [ -z start ]
+ [ -n  ]
+ eval rc_flags=$mysql_flags
+ rc_flags=
+ eval _chdir=$mysql_chdir _chroot=$mysql_chroot _nice=$mysql_nice _user=$mysql_user _group=$mysql_group _groups=$mysql_groups
+ _chdir= _chroot= _nice= _user=mysql _group= _groups=
+ [ -n mysql ]
+ eval if [ -x /usr/bin/id ]; then /usr/bin/id -un; fi
+ [ -x /usr/bin/id ]
+ /usr/bin/id -un
+ [ mysql = root ]
+ [ -n mysql_enable -a start != rcvar ]
+ checkyesno mysql_enable
+ eval _value=$mysql_enable
+ _value=YES
+ debug checkyesno: mysql_enable is set to YES.
+ return 0
+ eval rc_pid=$(check_pidfile /var/db/mysql/some.host.com.pid /usr/local/libexec/mysqld )
+ check_pidfile /var/db/mysql/some.host.com.pid /usr/local/libexec/mysqld
+ _pidfile=/var/db/mysql/some.host.com.pid
+ _procname=/usr/local/libexec/mysqld
+ _interpreter=
+ [ -z /var/db/mysql/some.host.com.pid -o -z /usr/local/libexec/mysqld ]
+ [ ! -f /var/db/mysql/some.host.com.pid ]
+ debug pid file (/var/db/mysql/some.host.com.pid): not readable.
+ return
+ rc_pid=
+ [ start != start ]
+ eval _cmd=$start_cmd _precmd=$start_precmd _postcmd=$start_postcmd
+ _cmd= _precmd=mysql_prestart _postcmd=mysql_poststart
+ [ -n  ]
+ [ -z  -a -n  ]
+ [ ! -x /usr/local/bin/mysqld_safe ]
+ _run_rc_precmd
+ check_required_before start
+ local _f
+ return 0
+ [ -n mysql_prestart ]
+ debug run_rc_command: start_precmd: mysql_prestart 
+ eval mysql_prestart 
+ mysql_prestart
+ [ ! -d /var/db/mysql/mysql/. ]
+ checkyesno mysql_limits
+ eval _value=$mysql_limits
+ _value=NO
+ debug checkyesno: mysql_limits is set to NO.
+ return 1
+ return 0
+ _return=0
+ [ 0 -ne 0 ]
+ check_required_after start
+ local _f _args
+ return 0
+ return 0
+ echo Starting mysql.
Starting mysql.
+ [ -n  ]
+ _doit=/usr/local/bin/mysqld_safe  --defaults-extra-file=/var/db/mysql/my.cnf --user=mysql --datadir=/var/db/mysql --pid-file=/var/db/mysql/some.host.com.pid  > /dev/null 2>&1 &
+ [ -n mysql ]
+ _doit=su -m mysql -c 'sh -c "/usr/local/bin/mysqld_safe  --defaults-extra-file=/var/db/mysql/my.cnf --user=mysql --datadir=/var/db/mysql --pid-file=/var/db/mysql/some.host.com.pid  > /dev/null 2>&1 &"'
+ [ -n  ]
+ _run_rc_doit su -m mysql -c 'sh -c "/usr/local/bin/mysqld_safe  --defaults-extra-file=/var/db/mysql/my.cnf --user=mysql --datadir=/var/db/mysql --pid-file=/var/db/mysql/some.host.com.pid  > /dev/null 2>&1 &"'
+ debug run_rc_command: doit: su -m mysql -c 'sh -c "/usr/local/bin/mysqld_safe  --defaults-extra-file=/var/db/mysql/my.cnf --user=mysql --datadir=/var/db/mysql --pid-file=/var/db/mysql/some.host.com.pid  > /dev/null 2>&1 &"'
+ eval su -m mysql -c 'sh -c "/usr/local/bin/mysqld_safe  --defaults-extra-file=/var/db/mysql/my.cnf --user=mysql --datadir=/var/db/mysql --pid-file=/var/db/mysql/some.host.com.pid  > /dev/null 2>&1 &"'
+ su -m mysql -c sh -c "/usr/local/bin/mysqld_safe  --defaults-extra-file=/var/db/mysql/my.cnf --user=mysql --datadir=/var/db/mysql --pid-file=/var/db/mysql/some.host.com.pid  > /dev/null 2>&1 &"
+ _return=0
+ [ 0 -ne 0 ]
+ return 0
+ _run_rc_postcmd
+ [ -n mysql_poststart ]
+ debug run_rc_command: start_postcmd: mysql_poststart 
+ eval mysql_poststart 
+ mysql_poststart
+ local timeout=15
+ [ ! -f /var/db/mysql/some.host.com.pid -a 15 -gt 0 ]
+ timeout=14
+ sleep 1
+ [ ! -f /var/db/mysql/some.host.com.pid -a 14 -gt 0 ]
+ return 0
+ _return=0
+ return 0
+ return 0
```


----------



## pascalvree (May 6, 2009)

Tenx again Dutch Daemon!

After some more digging I've found out, that if I can solve the next riddle; my current startup problems will vanish into thin air 
(it all comes down to the 'su -m' part ... located within the first part o'the command)

When I run the next two commands on different FreeBSD machines

```
su -l svn -c 'echo foo' (works on all machines)
su -m svn -c 'echo foo' (won't work on my own machine, works on others)
```

Is there anybody out there, whom has the answer to my little riddle ... Right now I'm completly clueless ...


----------



## DutchDaemon (May 6, 2009)

Continued here: http://forums.freebsd.org/showthread.php?t=3783


----------



## pascalvree (May 7, 2009)

DutchDaemon said:
			
		

> Continued here: http://forums.freebsd.org/showthread.php?t=3783


Dutch Daemon, is there any way I can close this thread ? (it's solved ...)


----------



## DutchDaemon (May 7, 2009)

Set to [Solved]. We only close threads that go off the rails for some reason.


----------

