Linux – systemctl enable differs from systemctl start, how

arch linuxMySQLsystemd

I am running an Arch Linux (latest, up-to-date) box, and attempting to get MySQL to start at boot. With the systemd package installed I have systemctl available, and as such I can do things like this:

systemctl start mysqld.service
systemctl [stop|status|restart] mysqld.service

That's all fine, and works great when I want to start/stop manually, however, when it comes to getting it to start at boot (by using 'enable' on systemctl, I get some nasty output):

[root@rudivarch ~]# systemctl enable mysqld.service
Failed to issue method call: No such file or directory

Obviously, since the other commands work just fine, I'm seriously confused by this and have spent a good while trying to figure it out… systemctl status outputs this:

[root@rudivarch ~]# systemctl status mysqld.service
mysqld.service
     Loaded: loaded (/etc/rc.d/mysqld)
     Active: inactive (dead) since Tue, 31 Jan 2012 15:32:28 +0000; 1min 25s ago
    Process: 589 ExecStop=/etc/rc.d/mysqld stop (code=exited, status=0/SUCCESS)
    Process: 257 ExecStart=/etc/rc.d/mysqld start (code=exited, status=0/SUCCESS)
    CGroup: name=systemd:/system/mysqld.service

Anybody have any ideas as to why 'enable' doesn't work?

Best Answer

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.