未能添加对 mongod.target[Service] 的依赖,忽略:无效参数

Posted

技术标签:

【中文标题】未能添加对 mongod.target[Service] 的依赖,忽略:无效参数【英文标题】:Failed to add dependency on mongod.target[Service], ignoring: Invalid argument 【发布时间】:2017-09-13 18:32:49 【问题描述】:

当我在 CentOS 7 上安装 Rocket.Chat 服务器时,我创建了rocketchat.service

[Unit]
Description=The Rocket.Chat server
After=network.target remote-fs.target nss-lookup.target 
mongod.target[Service]
Type=simple
ExecStart=/usr/local/bin/node /opt/Rocket.Chat/main.js
Restart=always
StandardOutput=syslog
StandardError=syslog
SyslogIdentifier=rocketchat
User=root
Environment=MONGO_URL=mongodb://localhost:27017/rocketchat 
ROOT_URL=http://www.leavenotrace.cn PORT=3000
[Install] WantedBy=multi-user.target

当我按下命令时:

systemctl start rocketchat
systemctl status rocketchat

显示以下错误:

Apr 18 11:50:13 VM_56_252_centos systemd[1]: [/etc/systemd/system/rocketchat.service:3] Failed to add dependency on mongod.target[Service], ignoring: Invalid argument
Apr 18 11:50:13 VM_56_252_centos systemd[1]: [/etc/systemd/system/rocketchat.service:4] Unknown lvalue 'Type' in section 'Unit'
Apr 18 11:50:13 VM_56_252_centos systemd[1]: [/etc/systemd/system/rocketchat.service:5] Unknown lvalue 'ExecStart' in section 'Unit'
Apr 18 11:50:13 VM_56_252_centos systemd[1]: [/etc/systemd/system/rocketchat.service:6] Unknown lvalue 'Restart' in section 'Unit'
Apr 18 11:50:13 VM_56_252_centos systemd[1]: [/etc/systemd/system/rocketchat.service:7] Unknown lvalue 'StandardOutput' in section 'Unit'
Apr 18 11:50:13 VM_56_252_centos systemd[1]: [/etc/systemd/system/rocketchat.service:8] Unknown lvalue 'StandardError' in section 'Unit'
Apr 18 11:50:13 VM_56_252_centos systemd[1]: [/etc/systemd/system/rocketchat.service:9] Unknown lvalue 'SyslogIdentifier' in section 'Unit'
Apr 18 11:50:13 VM_56_252_centos systemd[1]: [/etc/systemd/system/rocketchat.service:10] Unknown lvalue 'User' in section 'Unit'
Apr 18 11:50:13 VM_56_252_centos systemd[1]: [/etc/systemd/system/rocketchat.service:11] Unknown lvalue 'Environment' in section 'Unit'
Apr 18 11:50:13 VM_56_252_centos systemd[1]: [/etc/systemd/system/rocketchat.service:12] Invalid section header '[Install] WantedBy=multi-user.target'

【问题讨论】:

您的问题是rocketchat.service 文件中缺少两个换行符,就在[Service] 之前和WantedBy= 之前。 【参考方案1】:

之前:

nano /etc/systemd/system/rocketchat.service

它会显示这些错误。

之后:

nano /usr/lib/systemd/system/rocketchat.service

在里面写:

  [Unit]
  Description=The Rocket.Chat server
  After=network.target remote-fs.target nss-lookup.target nginx.target mongod.target
  [Service]
  ExecStart=/usr/local/bin/node /opt/Rocket.Chat/main.js
  StandardOutput=syslog
  StandardError=syslog
  SyslogIdentifier=rocketchat
  User=root
  Environment=MONGO_URL=mongodb://localhost:27017/rocketchat ROOT_URL=http://www.leavenotrace.cn:3000/ PORT=3000
  [Install]
  WantedBy=multi-user.target

没关系。

【讨论】:

文件的位置不是问题,无论是在/etc 还是/usr/lib。只需将您的答案切入重点:OP 的 rocketchat.service 文件中缺少两个换行符。 顺便说一下,这是OP。

以上是关于未能添加对 mongod.target[Service] 的依赖,忽略:无效参数的主要内容,如果未能解决你的问题,请参考以下文章

VS2017 添加引用时报错未能正确加载ReferenceManagerPackage包的解决方法

Kafka Connect 未能添加 MySqlConnector

Ehcache put 未能添加到堆上

约束未能添加填充

vs2017添加引用时报错未能正确加载“ReferenceManagerPackage”包。

Vs2017添加引用时报错未能正确加载“ReferenceManagerPackage”包