Guide/Howto for adding new service?

Status
Not open for further replies.

agehring

Dabbler
Joined
Sep 11, 2011
Messages
10
I've been using FreeNAS for quite some time now, and I have a "hacked" install of 7.X running a MySQL DB for XBMC.

I would like to look into adding MySQL as a service to 8.X, and I'm looking for some kind of guide or howto on adding to the new interface.

Does something such as this exist?

Thanks!
 

ProtoSD

MVP
Joined
Jul 1, 2011
Messages
3,348
There's sqlite3 installed already. I don't know enough about them to know if they're compatible.
 
J

Joshua Parker Ruehlig

Guest
Want to get mysql running on FreeNAS 8 as well, I'll look a bit into it.
 
J

Joshua Parker Ruehlig

Guest
Got it working =] XBMC sync works, still a bit buggy with thumbnail syncing (only working in pre-eden for a few weeks)

Assumes
*create user "mysql" in gui
*create mount point "/mnt/RAID"

Code:
mkdir /mnt/RAID/Packages /mnt/RAID/Packages/mysql /mnt/RAID/Packages/db /mnt/RAID/Packages/db/mysql
chown -R mysql:mysql /mnt/RAID/Packages/db/mysql

cd /mnt/RAID/Packages/mysql
fetch ftp://ftp.freebsd.org/pub/FreeBSD/ports/amd64/packages-8.2-release/All/mysql-client-5.5.9.tbz ftp://ftp.freebsd.org/pub/FreeBSD/ports/amd64/packages-8.2-release/All/mysql-server-5.5.9.tbz
foreach fn ( *.tbz )
tar -xjf $fn bin lib libexec share include libdata
end
rm *.tbz


Everything after this needs to be reapplied everytime you upgrade FreeNAS
Code:
mount -uw /

ln -s /mnt/RAID/Packages/mysql/bin/* /usr/local/bin
ln -s /mnt/RAID/Packages/mysql/include/* /usr/local/include
ln -s /mnt/RAID/Packages/mysql/lib/* /usr/local/lib
ln -s /mnt/RAID/Packages/mysql/libdata/ldconfig/* /usr/local/libdata/ldconfig
ln -s /mnt/RAID/Packages/mysql/libexec/* /usr/local/libexec
ln -s /mnt/RAID/Packages/mysql/share/mysql /usr/local/share/mysql
ln -s /mnt/RAID/Packages/mysql/share/aclocal/* /usr/local/share/aclocal

nano /conf/base/etc/rc.d/mysql-server

Paste in..
Code:
#!/bin/sh
# PROVIDE: mysql
# REQUIRE: LOGIN
# KEYWORD: shutdown

mysql_dbdir="/mnt/RAID/Packages/db/mysql"
. /etc/rc.subr
name="mysql"
rcvar=`set_rcvar`
load_rc_config $name

mysql_user="mysql"
mysql_limits_args="-e -U ${mysql_user}"
pidfile=${mysql_pidfile:-"${mysql_dbdir}/`/bin/hostname`.pid"}
command="/usr/sbin/daemon"
command_args="-c -f /usr/local/bin/mysqld_safe --defaults-extra-file=${mysql_dbdir}/my.cnf --user=${mysql_user} --datadir=${mysql_dbdir} --pid-file=${pidfile} ${mysql_args}"
procname="/usr/local/libexec/mysqld"
start_precmd="${name}_prestart"
start_postcmd="${name}_poststart"
mysql_install_db="/usr/local/bin/mysql_install_db"
mysql_install_db_args="--basedir=/usr/local --datadir=${mysql_dbdir} --force"

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"


Code:
chmod +x /conf/base/etc/rc.d/mysql-server
nano /conf/base/etc/rc.conf

Add to the bottom of the file
Code:
mysql_enable="YES"
 

agehring

Dabbler
Joined
Sep 11, 2011
Messages
10
Thanks Joshua for that information.

I've been successful in getting MySQL installed onto the image as well, by adding the ports to build process. I run my instances in a "appliance" mode.

What I am more interested in; Is how to integrate MySQL controls into the FreeNAS UI.

I've been digging around the gui tree from the source and have identified quite a few items, but was hoping the developers would provide some insight...

Thanks!
 

agehring

Dabbler
Joined
Sep 11, 2011
Messages
10
I'm getting closer, but haven't figured out how to get the service to show up under the 'services' tab:

Scratch that - I thought that is was going to be generated off of the list, but it is not. Just simple html...
 

OctaneZ

Dabbler
Joined
Aug 6, 2011
Messages
24
Scratch that - I thought that is was going to be generated off of the list, but it is not. Just simple html...



Can you share how you did this, I have a couple ports that I would like to maintain from the GUI.
 

ProtoSD

MVP
Joined
Jul 1, 2011
Messages
3,348
I'd be interested to know as well, but start a new thread if you do or make a HowTo.
 

agehring

Dabbler
Joined
Sep 11, 2011
Messages
10
I'll post my notes on what files I modified.

Note: this is source edit/compile process, not modifying a running instance...
 
J

Joshua Parker Ruehlig

Guest
Hi Joshua,
I followed your instruction, but i had my mount point set to something else. I change all instance of RAID to my mount point and restarted.
I can see the process running, but if I try to run mysqladmin I get an error
Code:

 ./mysql-server start
./mysql-server: WARNING: $mysql_limits is not set properly - see rc.conf(5).
Starting mysql.
Unmatched ".
Unmatched ".
./mysql-server: WARNING: failed to start mysql

Code:
mysql
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)

I could not find what needs to be changed.

If you followed my instructions mysql server should already be running, you can enter mysql with
Code:
mysql -u root


Once you get it up and running, I also recommend you
Code:
mount -uw /
mysql_secure_installation

This way you can add a root password.

BTW, I actually noticed that
Code:
./mysql-server: WARNING: $mysql_limits is not set properly - see rc.conf(5).

But everything seems to still work for me
 
L

lrusak

Guest
Hi Joshua,
I followed your instruction, but i had my mount point set to something else. I change all instance of RAID to my mount point and restarted.
I can see the process running, but if I try to run mysqladmin I get an error
Code:

 ./mysql-server start
./mysql-server: WARNING: $mysql_limits is not set properly - see rc.conf(5).
Starting mysql.
Unmatched ".
Unmatched ".
./mysql-server: WARNING: failed to start mysql

Code:
mysql
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)

I could not find what needs to be changed.


I get this exact same error, I don't know what's wrong. I followed the guide perfectly.

Any help here?
 

lrusak

Explorer
Joined
Dec 20, 2011
Messages
56
did anyone ever find a solution for this? I'd like to know how to get mysql running properly

Thanks
 

ProtoSD

MVP
Joined
Jul 1, 2011
Messages
3,348
I'm just taking a guess here, but it looks like a syntax problem. Double check the /conf/base/etc/rc.d/mysql-server file for unmatched quotation marks etc. If you copied and pasted it, it looks like it should be ok, but that error is definitely syntax related. The type of quotation marks are important " vs. ' makes a big difference.
 

lrusak

Explorer
Joined
Dec 20, 2011
Messages
56
Yea copy and pasted everything into a text document then did a find/replace for the mnt location, other then that it is all the same.

Not a big deal, I just wanted to try it out and see how it works with xbmc.
 

imdos

Dabbler
Joined
Feb 23, 2012
Messages
34
I get this exact same error, I don't know what's wrong. I followed the guide perfectly.

Any help here?

Put this in /etc/rc.conf to get rid of the error message "WARNING: $mysql_limits is not set properly - see rc.conf(5).".

mysql_enable="YES"
mysql_limits="NO"

It appears something is still broken. Have a look in the mysql directory for <hostname>.<network-name>.err e.g. NAS.lan.err in my case. There's a hint why it is failing ...

If I'm not mistaken this code won't survive a reboot, thus it should be added to /conf/base or added as a verification check before mysql-server starts (e.g. if not exists /usr/local/bin/mysql then do ...). Right?
Code:
ln -s /mnt/USB/extensions/mysql/bin/* /usr/local/bin
ln -s /mnt/USB/extensions/mysql/include/* /usr/local/include
ln -s /mnt/USB/extensions/mysql/lib/* /usr/local/lib
ln -s /mnt/USB/extensions/mysql/libdata/ldconfig/* /usr/local/libdata/ldconfig
ln -s /mnt/USB/extensions/mysql/libexec/* /usr/local/libexec
ln -s /mnt/USB/extensions/mysql/share/mysql /usr/local/share/mysql
ln -s /mnt/USB/extensions/mysql/share/aclocal/* /usr/local/share/aclocal
 

lrusak

Explorer
Joined
Dec 20, 2011
Messages
56
Put this in /etc/rc.conf to get rid of the error message "WARNING: $mysql_limits is not set properly - see rc.conf(5).".

mysql_enable="YES"
mysql_limits="NO"

It appears something is still broken. Have a look in the mysql directory for <hostname>.<network-name>.err e.g. NAS.lan.err in my case. There's a hint why it is failing ...

If I'm not mistaken this code won't survive a reboot, thus it should be added to /conf/base or added as a verification check before mysql-server starts (e.g. if not exists /usr/local/bin/mysql then do ...). Right?
Code:
ln -s /mnt/USB/extensions/mysql/bin/* /usr/local/bin
ln -s /mnt/USB/extensions/mysql/include/* /usr/local/include
ln -s /mnt/USB/extensions/mysql/lib/* /usr/local/lib
ln -s /mnt/USB/extensions/mysql/libdata/ldconfig/* /usr/local/libdata/ldconfig
ln -s /mnt/USB/extensions/mysql/libexec/* /usr/local/libexec
ln -s /mnt/USB/extensions/mysql/share/mysql /usr/local/share/mysql
ln -s /mnt/USB/extensions/mysql/share/aclocal/* /usr/local/share/aclocal

still can't get it to work properly,

Code:
[root@freenas] /mnt/utilities/packages/mysql# mysql
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)

Code:
[root@freenas] /mnt/utilities/packages/mysql# service mysql-server start
Starting mysql.
TERM: Undefined variable.
Unmatched ".
Unmatched ".
/etc/rc.d/mysql-server: WARNING: failed to start mysql


who knows :/
 

imdos

Dabbler
Joined
Feb 23, 2012
Messages
34
Please try this:

Code:
sh -xv /etc/rc.d/mysql-server


It appears to be something in the start-up script which is not correct.
 
Status
Not open for further replies.
Top