大网数据广告活动
服务器运维问答

meaning of a @ in /usr/lib/systemd/system .service name files

· 52CE 我爱测

There is a mysql installed in a centos machine. I am trying to modify the mysql service file so as to include a new "RequiresMountsFor=/mnt/mysqldata" line to ensure the disk where the mysql data resides is mounted before the mys…

问题原文

原帖链接 · usuario · CC BY-SA 3.0

There is a mysql installed in a centos machine.

I am trying to modify the mysql service file so as to include a new "RequiresMountsFor=/mnt/mysqldata" line to ensure the disk where the mysql data resides is mounted before the mysql server starts.

But I have noticed there are two mysql.service files. One with an @ and other one without it.

[user@machine system]$ pwd
/usr/lib/systemd/system
[user@machine system]$ ls -l mysqld*
-rw-r--r--. 1 root root 1614 mar 18  2017 mysqld.service
-rw-r--r--. 1 root root 1645 mar 18  2017 mysqld@.service

I do not know which are the difference between them, which one is used or why there are two of them.

Their content is practically the same.

[user@machine system]$ diff mysqld.service mysqld@.service
1c1
< # Copyright (c) 2015, 2016, Oracle and/or its affiliates. All rights reserved.
---
> # Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
35c35
< PIDFile=/var/run/mysqld/mysqld.pid
---
> PIDFile=/var/run/mysqld/mysqld-%i.pid
44c44
< ExecStartPre=/usr/bin/mysqld_pre_systemd
---
> ExecStartPre=/usr/bin/mysqld_pre_systemd %I
47c47
< ExecStart=/usr/sbin/mysqld --daemonize --pid-file=/var/run/mysqld/mysqld.pid $MYSQLD_OPTS
---
> ExecStart=/usr/sbin/mysqld --defaults-group-suffix=@%I --daemonize --pid-file=/var/run/mysqld/mysqld-%i.pid $MYSQLD_OPTS

The status of the unit suggests me the one without the @ is being used. But I still wonder why there are two of them and their meaning.

[user@machine system]$ systemctl status mysqld.service
● mysqld.service - MySQL Server
   Loaded: loaded (/usr/lib/systemd/system/mysqld.service; enabled; vendor preset: disabled)
   Active: active (running) since jue 2017-09-21 09:57:05 CEST; 1h 40min ago
     Docs: man:mysqld(8)
           http://dev.mysql.com/doc/refman/en/using-systemd.html
  Process: 1042 ExecStart=/usr/sbin/mysqld --daemonize --pid-file=/var/run/mysqld/mysqld.pid $MYSQLD_OPTS (code=exited, status=0/SUCCESS)
  Process: 950 ExecStartPre=/usr/bin/mysqld_pre_systemd (code=exited, status=0/SUCCESS)
 Main PID: 1357 (mysqld)
   CGroup: /system.slice/mysqld.service
           └─1357 /usr/sbin/mysqld --daemonize --pid-file=/var/run/mysqld/mysqld.pid

sep 21 09:57:00 machine systemd[1]: Starting MySQL Server...
sep 21 09:57:05 machine systemd[1]: Started MySQL Server.

已采纳解答

原帖链接 · Mike · CC BY-SA 3.0

So the the @ has a special meaning in systemd.

Say we have a service called echo@.service with the following in it

ExecStart=/bin/echo %i

So if I do

systemctl start [email omitted]

I'd get 1 in the journalctl.

So %i in the service file gets replaced with anything after @ when you start the service.

So it looks like in your case the mysqld@.service would be if you wanted to run multiple mysql servers on the same host.

摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。

资料来源与适用范围

资料来源
Server Fault
适用范围
以原帖系统、软件版本与发布日期为准(2017-09-21)
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 3.0

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。