17

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?

6 Answers 6

22

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.

1
  • Thanks! I actually wrote my own mysqld.service that resembles this very closely yesterday, but passes through to /etc/rc.d/mysqld start/stop for ExecStart/ExecStop. Accepted, will post my version up also in case somebody else finds it! Thanks Feb 1, 2012 at 8:17
3

@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
2

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/.

1
  • 1
    This doesn't really answer his question. This looks more like a comment to @Rudi's answer.
    – PhilT
    Nov 23, 2014 at 22:54
0

Enable is to activate "unit" aka daemon aka service at startup of systemd.

OpenSUSE:

# systemctl list-units --all | grep sql
mysql.service             loaded inactive dead          LSB: Start the MySQL database 
(good)

# systemctl enable mysql.service
mysql.service is not a native service, redirecting to /sbin/chkconfig.
Executing /sbin/chkconfig mysql on
insserv: Service localfs has to exists for service vmware-USBArbitrator
insserv: Service network is missed in the runlevels 2 to use service vmware
Warning: unit files do not carry install information. No operation executed.

(it actually redirects to old chkconfig/sysvinit and that corrects init databases)

# systemctl start mysql.service

(no output)

# systemctl status mysql.service
mysql.service - LSB: Start the MySQL database server
          Loaded: loaded (/etc/init.d/mysql)
          Active: active (running) since Tue, 31 Jan 2012 20:07:52 +0100; 5s ago
         Process: 999999 ExecStart=/etc/init.d/mysql start (code=exited, status=0/SUCCESS)
          CGroup: name=systemd:/system/mysql.service
                  ├ 999999 /bin/sh /usr/bin/mysqld_safe --mysqld=mysqld --user=mysql...
                  └ 999999 /usr/sbin/mysqld --basedir=/usr --datadir=/var/lib/mysql...

(sort of runs)
1
  • Yes I understand this, and mysqld is a daemon/service that I want to run at startup. This is my point, it starts/stops, but won't "enable". Jan 31, 2012 at 15:58
0

On my FC15 system, when I ran 'systemctl enable mysqld.service', it automagically came back with:

mysqld.service is not a native service, redirecting to /sbin/chkconfig. Executing /sbin/chkconfig mysqld on

So try running: /sbin/chkconfig mysqld on

0

If you've got ... when enabling your service unit, copy it to /etc/systemd/system

Failed to issue method call: No such file or directory

To enable your service unit, add below the ... so you can system enable mysqld.service (its enable in every user's namespace)

[Install]
WantedBy=multi-user.target

Cheers, sugatang itlog

You must log in to answer this question.

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