I have just upgraded from CentOS 6.5 to 7.0 and I am not too happy as the new systemd
is probably giving me problems. It seems it is just simply booting too fast, starting up processes asynchronously and screwing up service dependencies.
For example I have a few scripts setup in crond
which are triggered after a reboot:
@reboot /root/scripts/check_gmail.sh
@reboot /root/scripts/start_gps_listener.sh
This results in all kind of weird errors (only showing one of them):
Warning: stream_socket_client(): unable to connect to tcp://192.168.20.4:4001
(Network is unreachable) in /root/scripts/check_gmail.php on line 137
ERROR: Network is unreachable (101)
In the above I am writing to a TCP socket. It is pretty clear to me that crond
is started before the network is properly initialized as the network is unreachable
.
The same thing goes with Apache and MySQL (MariaDB). MySQL is quite slow to startup (much data) meaning that both Apache and a lot of my crond
startup scripts are failing as the MySQL database is not running when the scripts are being called.
I have tried to setup dependencies but without any luck; I have appended network
and mysql
services to [Unit]
(as seen with systemctl list-dependencies
). Ideally all services wait until MySQL is up and running:
vi /lib/systemd/system/httpd.service
[Unit]
Description=The Apache HTTP Server
After=network.target remote-fs.target nss-lookup.target network.service mysql.service
vi /lib/systemd/system/crond.service
[Unit]
Description=Command Scheduler
After=syslog.target auditd.service systemd-user-sessions.service time-sync.target network.service mysql.service
When booting with the above I get the same errors. I also get the emails in mailq
as the network/DNS is not ready when processing cron-scripts. A few minutes after startup they are sent correctly.
Can anyone help getting this right by making sure the services are fired in the correct order? It seems very wrong that it is so fast booting and ideally it did it the good old way, "launching one serice... wait... launching a new service... wait... so on).
Do note that I am not sure it is systemd
that is my problem - it is just my theory of what I can read from the net.
grep -i concurrency /etc/default/rcS
? I might be mixing up my init systems but I seem to recall that controls whether processes wait for one another to finish./etc/default/rc*
Requires=network.target
to the units above.Requires=network.target
in to/lib/systemd/system/crond.service