14

I am actually using MariaDB (drop-in replacement for MySQL).

I'm trying to make some changes to my systemd mysql.service file.

I can see it exists because running sudo systemctl lists it and indicates that it is loaded / active / running.

The issue is that I can't find the file to make edits. From what I've read in various articles I've found is that the doc should be located at

/etc/systemd/system/multi-user.target.wants/mysql.service

But it isn't. I've browsed through other directories at the /etc/systemd level to no avail. Any ideas?

1
  • What is the return value for ps -p 1 on your system? I'm just wondering after reading this article SystemdForUpstartUsers.
    – John K. N.
    Nov 17, 2016 at 10:57

8 Answers 8

16

For units defined in static files you could use systemctl status, with the information outputed issuing that command, you will be able to see its location.

For example:

# systemctl  status sshd
● sshd.service - OpenSSH Daemon
   Loaded: loaded (/usr/lib/systemd/system/sshd.service; enabled; vendor preset: disabled)
   Active: active (running) since Mon 2016-10-31 17:01:01 UTC; 1 weeks 0 days ago
 Main PID: 283 (sshd)
    Tasks: 1 (limit: 4915)
   CGroup: /system.slice/sshd.service
           └─290 /usr/bin/sshd -D

Note that the tab command could be helpful here.

Therefore, in my system the systemd services are placed under /usr/lib/systemd/. Please, note that there could be folders in that location.

Another way is to use the find command in that specific location to find a service:

# find /usr/lib/systemd/ | grep -i mysql

I hope that helps ;)

5

The default location for systemd init script is:

/lib/systemd/system

But the preferred way to modify them is to create a custom script in:

/etc/systemd/system

scripts in the latter folder override the script in the former location.

1
  • Thanks, this is helpful, but I looked in the /lib/systemd/system but I'm still not seeing anything labeled close to mysql.service. Where else could it be pulling from? Dec 5, 2015 at 4:09
3

In your particular case it's probably because MySQL doesn't have a systemd service file, but only a SystemV init script in /etc/init.d/mysql. You do have to use systemctl or service to control it though. Running /etc/init.d/mysql stop makes systemd thinks it crashed and restarts it.

Not sure if the newer Ubuntu's do this too, but older ones definitely.

1
  • This is the actual correct answer to the question specific to Ubuntu 16.04. As stated in the answer above systemctl status mysql.service (the service name used for Mariadb servier) shows the location of the file loaded -- Loaded: loaded (/etc/init.d/mysql; bad; vendor preset: enabled) -- so it is not a service file but the initscript via the sysVinit compatibility interface facility. Hopefully someday, after forcing systemd on to users, Debian and Ubuntu will finally get around to converting all init scripts to service files and the sysVinit directories will disappear.
    – J G Miller
    Aug 16, 2017 at 0:59
2

On Ubuntu you can find it at

/lib/systemd/system/mysql.service

I once tried to run the command systemctl enable mysql.service, but found that it searches for the file at /etc/systemd/system/ (where usually there's a hard link for it there) and in my case there was no mysql.service file there. So I created a hard link with:

ln -T /lib/systemd/system/mysql.service /etc/systemd/system/mysql.service

1

I use ubuntu 16.04! after modifing /etc/security/limit.conf and /etc/mysql/my.cnf, then run
sudo systemctl edit mysql.service

adding following lines

[Service]
LimitNOFILE=infinity

1
  • 1
    I'm not sure if this will help the OP. Are you suggesting he just create a new mysql.service file?
    – John K. N.
    Nov 8, 2016 at 8:07
1

More generically, to find a file by its name you can use one of the following approach:

  • find / -iname "<filename>"
  • updatedb && locate <filename>
1

systemd

According to the official documentation for systemd on the maria.db site, the configuration files for the maria.db service are stored here:

/usr/lib/systemd/system/mariadb.service

systemd quick info:

systemd is an init replacement that MariaDB uses on releases since 10.1.8. Distribution packages before this version may use a different configuration so consult their documentation if required.

...and for the configuration file we have:

The service definition is installed in /usr/lib/systemd/system/mariadb.service. The service name is mariadb.service; however aliases to mysql.service and mysqld.service are included for convenience.

If your installation is using a customized configuration file to start the maria.db service, then you might find the script in this location:

/etc/systemd/system/mariadb.service.d/XXXX.conf

Where XXXX can be any file name!

This could be because of the recommendation made in the above mentioned link:

If there are some systemd settings to override or to set, create a file /etc/systemd/system/mariadb.service.d/XXXX.conf file where XXXX is something meaningful to you and place the configuration option(s) in an appropriate section, usually [Service]. If a systemd option is a list you may need to set this to empty before you set the replacement values....

In the feedback to the online article there is a short comment that points out that:

MariaDB 10.1.17 and other recent releases still include an init script as well as a systemd unit. The init script ships with chkconfig on and this causes a race condition as to which version of the daemon starts first. This has causes us significant problems with RPM updates and system reboots.

This leads me to the conclusion that you might still have to search for the init.d variants of the configuration files (as pointed out in my initial version of this post) to pinpoint your issues.

init.d

I would check the directory /etc/init.d for the existence of a mysql or mariadb file.

ls /etc/init.d -lash

If you then open up the corresponding file (e.g. mysql on my Ubuntu Server) you can find the startup part.

cat /etc/init.d/mysql

(note: no mysqld file, just a plain mysql file)

At some point you will find the sanity checks in the service startup script:

## Do some sanity checks before even trying to start mysqld.
sanity_checks() {
  # check for config file
  if [ ! -r /etc/mysql/my.cnf ]; then
    log_warning_msg "$0: WARNING: /etc/mysql/my.cnf cannot be read. See README.Debian.gz"
    echo                "WARNING: /etc/mysql/my.cnf cannot be read. See README.Debian.gz" | $ERR_LOGGER
  fi

So the actual file for my setup would be the /etc/mysql/my.cnf file. Then go from there.

Your configuration may differ, but equipped with this knowledge you should be able to find the configuration file for your service.

2
  • 1
    The OP asked for systemd as a init system not System V Nov 9, 2016 at 14:47
  • Thank you for pointing that out. I will rewrite an answer.
    – John K. N.
    Nov 17, 2016 at 10:48
1

Here is how I found on my Ubuntu 16

#list all timer
systemctl list-timers #--> got apt-daily.service

#locate where is systemd 
sudo find / -name apt-daily.service
> /lib/systemd/system/apt-daily.service #--> /lib/systemd/system/

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .