Here is my unit file:

Description=Backend Service



Here is what I previous wrote that used to work (instructions for setting up the service):

BEd.service must be moved to /etc/systemd/system

systemctl daemon-reload
systemctl enable BEd
systemctl start BEd

Here is what the /etc/systemd/system folder currently contains:

basic.target.wants  dbus-org.freedesktop.NetworkManager.service  default.target.wants     sockets.target.wants
BEd                 dbus-org.freedesktop.nm-dispatcher.service   getty.target.wants       sysinit.target.wants
BEd.service         default.target                               multi-user.target.wants  system-update.target.wants

Here is the error message after rebooting:

[root@BEKappa ~]# systemctl status -l BHd
BEd.service - Backend Service
   Loaded: loaded (/etc/systemd/system/BEd.service; enabled)
   Active: failed (Result: exit-code) since Sat 2016-01-16 18:39:27 EST; 34s ago
  Process: 3852 ExecStart=/var/www/html/pythonscripts/BEd.py (code=exited, status=1/FAILURE)
 Main PID: 3852 (code=exited, status=1/FAILURE)
   CGroup: /system.slice/BEd.service

Jan 16 18:39:27 BEKappa BEd.py[3852]: Traceback (most recent call last):
Jan 16 18:39:27 BEKappa BEd.py[3852]: File "/var/www/html/pythonscripts/BEd.py", line 147, in <module>
Jan 16 18:39:27 BEKappa BEd.py[3852]: cur.execute(network_adapters_sql)
Jan 16 18:39:27 BEKappa BEd.py[3852]: File "/usr/lib64/python2.7/site-packages/MySQLdb/cursors.py", line 174, in execute
Jan 16 18:39:27 BEKappa BEd.py[3852]: self.errorhandler(self, exc, value)
Jan 16 18:39:27 BEKappa BEd.py[3852]: File "/usr/lib64/python2.7/site-packages/MySQLdb/connections.py", line 36, in defaulterrorhandler
Jan 16 18:39:27 BEKappa BEd.py[3852]: raise errorclass, errorvalue
Jan 16 18:39:27 BEKappa BEd.py[3852]: _mysql_exceptions.ProgrammingError: (1064, 'You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near \'\'IP\', \'ethernet\', \'connecting\', \'(getting\', \'enp7s0\', \'yes\', \'1000\', \'"dhcp"\', )\' at line 1')
Jan 16 18:39:27 BEKappa systemd[1]: BEd.service: main process exited, code=exited, status=1/FAILURE
Jan 16 18:39:27 BEKappa systemd[1]: Unit BEd.service entered failed state.

I am 100% sure it isn't the service code, since it starts just fine after reboot manually (i.e. systemctl start BEd).

Based on the error I'm 90% sure mariaDB isn't finished loading when BEd starts, it fails on the first SQL statement of the program. Yet, this unit file worked before, and it's currently working on another server. So I am baffled.

  • Wow, no one knows? Isn't this a linux forum? I think I've given all necessary information, I wonder what it could be. – gunslingor Jan 29 '16 at 20:17
  • Well, I have an idea. Could I just put some code in my service that will just make sure MariaDB is running before the service starts? – gunslingor Jan 31 '16 at 17:45

It's likely your question didn't attract an answer because of the generic question of "What's wrong with my file?". Try asking a specific question next time.

In this case you think the issue might be that the script before MySQL was ready. You can confirm if that's the case. Manually turn off MySQL and run the script. It should produce the same result.

You can also add error checking to the script to confirms that it can connect to MySQL before proceeding.

If the issue is indeed that MySQL hasn't started, then that's an interesting, specific question to ask, because your config appears to indicate that you asked that MySQL be started first.

There should be a way to solve /that/ issue with systemd, but you can also test if that's really the issue by updating your script to sleep for a minute (or five) before it tries to do anything. That should give MySQL plenty of time to finish coming online before it proceeds.

As a side note, I noticed you are storing your Python script under a web root. If the script is not always meant to be run the web, security may be improved by moving it outside of the web root.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.