systemctl enable differs from systemctl start, how?
mysqld.service
is a "virtual" unit – it doesn't exist on the filesystem, it's just part of systemd's compatibility layer. You can start it and systemd will run the legacy /etc/rc.d/mysqld
initscript, but you cannot systemctl enable
it because you need a real .service
file which could be symlinked into the proper place.
You can write such a unit yourself and put it in /etc/systemd/system/mysqld.service
:
[Unit] Description=MySQL Server After=network.target [Service] ExecStart=/usr/bin/mysqld --defaults-file=/etc/mysql/my.cnf --datadir=/var/lib/mysql --socket=/var/run/mysqld/mysqld.sock User=mysql Group=mysql WorkingDirectory=/usr [Install] WantedBy=multi-user.target
Run systemctl daemon-reload
after creating/modifying.
Alternatively, you can install the initscripts-systemd
package, which includes arch-daemons.target
for automatically starting services defined in rc.conf
. However, this package might go away soon, and it's always better to have native configuration files for the init system in use.
@Grawity's answer is correct and probably better than this, but I did get it solved yesterday basically by passing through to the rc.d script...
/lib/systemd/system/mysqld.service
[Unit]
Description=MySQL Server
After=network.target
[Service]
Type=forking
ExecStart=/etc/rc.d/mysqld start
ExecStop=/etc/rc.d/mysqld stop
[Install]
WantedBy=multi-user.target
Nota bene: Remember to put host-specific unit files under /etc/systemd/system/
and NOT /lib/systemd/system/
.
The latter is for distro-specific stuff; the former is for host-specific stuff that you configure yourself. It's like /usr/bin/
vs. /usr/local/bin/
, respectively.
So unless a package installs unit files by itself (under /lib/systemd/system/
), put your own "custom" stuff under /etc/systemd/system/
.