Centos 7. Freeradius fails to start on boot due to priority

I was messing around with FreeRADIUS and MySQL (MariaDB) and it seems FreeRADIUS service can't start properly on startup. But it starts fine using root user or in debug mode (radiusd -X) and works just fine! Debug mode shows no errors.

systemctl command shows that radiusd.service has failed to start.

/var/log/messages output:

Aug 21 15:52:29 nexus-test systemd: Starting The Apache HTTP Server...
Aug 21 15:52:29 nexus-test systemd: Starting MariaDB database server...
Aug 21 15:52:29 nexus-test systemd: Starting FreeRADIUS high performance RADIUS server....
Aug 21 15:52:29 nexus-test systemd: Started OpenSSH server daemon.
Aug 21 15:52:29 nexus-test mysqld_safe: 140821 15:52:29 mysqld_safe Logging to '/var/log/mariadb/mariadb.log'.
Aug 21 15:52:29 nexus-test mysqld_safe: 140821 15:52:29 mysqld_safe Starting mysqld daemon with databases from /var/lib/mysql
Aug 21 15:52:30 nexus-test systemd: Started Postfix Mail Transport Agent.
Aug 21 15:52:30 nexus-test avahi-daemon[604]: Registering new address record for fe80::250:56ff:fe85:e4af on eth0.*.
Aug 21 15:52:30 nexus-test systemd: radiusd.service: control process exited, code=exited status=1
Aug 21 15:52:30 nexus-test systemd: Failed to start FreeRADIUS high performance RADIUS server..
Aug 21 15:52:30 nexus-test systemd: Unit radiusd.service entered failed state.
Aug 21 15:52:31 nexus-test kdumpctl: kexec: loaded kdump kernel
Aug 21 15:52:31 nexus-test kdumpctl: Starting kdump: [OK]
Aug 21 15:52:31 nexus-test systemd: Started Crash recovery kernel arming.
Aug 21 15:52:31 nexus-test systemd: Started The Apache HTTP Server.
Aug 21 15:52:31 nexus-test systemd: Started MariaDB database server.

/var/log/radius/radius.log output:

Thu Aug 21 15:24:16 2014 : Info: rlm_sql (sql): Driver rlm_sql_mysql (module rlm_sql_mysql) loaded and linked
Thu Aug 21 15:24:16 2014 : Info: rlm_sql (sql): Attempting to connect to database "radius"
Thu Aug 21 15:24:16 2014 : Info: rlm_sql (sql): Opening additional connection (0)
Thu Aug 21 15:24:16 2014 : Error: rlm_sql_mysql: Couldn't connect socket to MySQL server radius@localhost:radius
Thu Aug 21 15:24:16 2014 : Error: rlm_sql_mysql: Mysql error 'Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2)'
Thu Aug 21 15:24:16 2014 : Error: rlm_sql (sql): Opening connection failed (0)
Thu Aug 21 15:24:16 2014 : Error: /etc/raddb/mods-enabled/sql[47]: Instantiation failed for module "sql"

After seeing this I tried to replicate the problem, killed mariadb.service and started to run debug mode again. And it spits out the same problem as in the radius.log.

I tried disabling iptables and firewalld and rebooting, but no luck:

systemctl disable iptables
systemctl disable firewalld

So maybe the problem is in the process startup order or delay of some kind. Maybe FreeRADIUS's SQL module can't connect to not yet started MariaDB? If it, how can I fix this?

In earlier versions of RHEL/CENTOS I know you easily see service start order in like rc.d or stuff, now IDK. I am new to this fancy "systemd", "systemctl", "firewalld" stuff Centos 7 introduced so sorry I'm a little bit confused. Also this new FreeRADIUS 3 structure...

PS. MariaDB is enabled on startup, credentials in FR DB configuration are correct


A little update:

cat /etc/systemd/system/multi-user.target.wants/radiusd.service output:

[Unit]
Description=FreeRADIUS high performance RADIUS server.
After=syslog.target network.target

[Service]
Type=forking
PIDFile=/var/run/radiusd/radiusd.pid
ExecStartPre=-/bin/chown -R radiusd.radiusd /var/run/radiusd
ExecStartPre=/usr/sbin/radiusd -C
ExecStart=/usr/sbin/radiusd -d /etc/raddb
ExecReload=/usr/sbin/radiusd -C
ExecReload=/bin/kill -HUP $MAINPID

[Install]
WantedBy=multi-user.target

Thank you, dawud, you pushed me in the right direction. What I had to do here is make radiusd.service start AFTER mariadb.service.

I fired up vim at /etc/systemd/system/multi-user.target.wants/radiusd.service and added a line in [Unit] section:

After=mariadb.service

So it looks like this:

[Unit]
Description=FreeRADIUS high performance RADIUS server.
After=syslog.target network.target
After=mariadb.service

After rebooting, FreeRADIUS started just fine.

Also this resource helped me a little bit.


You set up FreeRADIUS to connect to a local MySQL server, but that server is not running. Start the server and try again.