将 mbpfan 转换为系统服务时遇到问题

将 mbpfan 转换为系统服务时遇到问题

我是一名 Ubuntu 新手,正在关注本教程启用风扇管理mbpfan在运行 Ubuntu 18.04 的 Mac Mini 4.1 上。

一开始我成功了,然后开始尝试将 mbpfan 变成系统服务。我遇到的第一个问题是安装后我的系统上没有 mbpfan.service 文件,所以我就下载了它来自 GitHub,通过 SFTP 将其上传到我的下载文件夹,然后按照 的指示进行复制sudo cp mbpfan.service /etc/systemd/system/

但是当我尝试执行时,结果如下sudo systemctl enable mbpfan.service

Synchronizing state of mbpfan.service with SysV service script with /lib/systemd/systemd-sysv-install.
Executing: /lib/systemd/systemd-sysv-install enable mbpfan
Failed to enable unit: File mbpfan.service: Invalid argument

我目前有点困惑,希望您能帮我一下。谢谢。

= = = = = = = = =

编辑1:

~$ systemctl status mbpfancs.service

制作:

mbpfancs.service - mbpfan Custom Service
Loaded: loaded (/etc/systemd/system/mbpfancs.service; disabled; vendor preset
Active: failed (Result: exit-code) since Sat 2019-09-28 10:57:08 UTC; 27s ago
Process: 8521 ExecStart=/usr/sbin/mbpfan -f (code=exited, status=1/FAILURE)
Main PID: 8521 (code=exited, status=1/FAILURE)

Sep 28 10:57:08 macmini systemd[1]: Starting mbpfan Custom Service...
Sep 28 10:57:08 macmini systemd[1]: mbpfancs.service: Main process exited, code=
Sep 28 10:57:08 macmini systemd[1]: mbpfancs.service: Failed with result 'exit-c
Sep 28 10:57:08 macmini systemd[1]: Failed to start mbpfan Custom Service.`

然后

~$ journalctl -xe

Sep 28 09:10:19 macmini dbus-daemon[1048]: [system] Successfully activated service 'org.freedesktop.hostname1'
Sep 28 09:10:19 macmini systemd[1]: Started Hostname Service.
-- Subject: Unit systemd-hostnamed.service has finished start-up
-- Defined-By: systemd
-- Support: http://www.ubuntu.com/support
-- 
-- Unit systemd-hostnamed.service has finished starting up.
-- 
-- The start-up result is RESULT.
Sep 28 09:10:19 macmini hassio-supervisor[9614]: 19-09-28 09:10:19 INFO (MainThread) [hassio.host.services] Update service information
Sep 28 09:10:19 macmini hassio-supervisor[9614]: 19-09-28 09:10:19 INFO (MainThread) [hassio.utils.gdbus] Call org.freedesktop.systemd1.Manager.L
Sep 28 09:17:01 macmini CRON[2158]: pam_unix(cron:session): session opened for user root by (uid=0)
Sep 28 09:17:01 macmini CRON[2159]: (root) CMD (   cd / && run-parts --report /etc/cron.hourly)
Sep 28 09:17:01 macmini CRON[2158]: pam_unix(cron:session): session closed for user root
Sep 28 09:50:53 macmini systemd-timesyncd[548]: Network configuration changed, trying to establish connection.
Sep 28 09:50:53 macmini systemd-timesyncd[548]: Synchronized to time server 91.189.89.198:123 (ntp.ubuntu.com).
Sep 28 10:17:01 macmini CRON[5657]: pam_unix(cron:session): session opened for user root by (uid=0)
Sep 28 10:17:01 macmini CRON[5658]: (root) CMD (   cd / && run-parts --report /etc/cron.hourly)
Sep 28 10:17:01 macmini CRON[5657]: pam_unix(cron:session): session closed for user root
Sep 28 10:36:59 macmini hassio-supervisor[9614]: 19-09-28 10:36:59 INFO (MainThread) [hassio.updater] Fetch update data from https://version.home
Sep 28 10:36:59 macmini hassio-supervisor[9614]: 19-09-28 10:36:59 INFO (MainThread) [hassio.store.git] Update add-on https://github.com/home-ass
Sep 28 10:36:59 macmini hassio-supervisor[9614]: 19-09-28 10:36:59 INFO (MainThread) [hassio.store.git] Update add-on https://github.com/danimtb/
Sep 28 10:36:59 macmini hassio-supervisor[9614]: 19-09-28 10:36:59 INFO (MainThread) [hassio.store.git] Update add-on https://github.com/hassio-a
Sep 28 10:37:00 macmini hassio-supervisor[9614]: 19-09-28 10:37:00 INFO (MainThread) [hassio.store] Load add-ons from store: 61 all - 0 new - 0 r
Sep 28 10:56:04 macmini sudo[8465]:    grant : TTY=pts/0 ; PWD=/home/grant ; USER=root ; COMMAND=/bin/nano /etc/systemd/system/mbpfancs.service
Sep 28 10:56:04 macmini sudo[8465]: pam_unix(sudo:session): session opened for user root by grant(uid=0)
Sep 28 10:56:49 macmini sudo[8465]: pam_unix(sudo:session): session closed for user root
Sep 28 10:57:08 macmini sudo[8518]:    grant : TTY=pts/0 ; PWD=/home/grant ; USER=root ; COMMAND=/bin/systemctl start mbpfancs
Sep 28 10:57:08 macmini sudo[8518]: pam_unix(sudo:session): session opened for user root by grant(uid=0)
Sep 28 10:57:08 macmini systemd[1]: Starting mbpfan Custom Service...
-- Subject: Unit mbpfancs.service has begun start-up
-- Defined-By: systemd
-- Support: http://www.ubuntu.com/support
-- 
-- Unit mbpfancs.service has begun starting up.
Sep 28 10:57:08 macmini mbpfan[8521]: mbpfan starting up
Sep 28 10:57:08 macmini mbpfan[8521]: A previously created .pid file exists at: /var/run/mbpfan.pid. Aborting
Sep 28 10:57:08 macmini systemd[1]: mbpfancs.service: Main process exited, code=exited, status=1/FAILURE
Sep 28 10:57:08 macmini systemd[1]: mbpfancs.service: Failed with result 'exit-code'.
Sep 28 10:57:08 macmini systemd[1]: Failed to start mbpfan Custom Service.
-- Subject: Unit mbpfancs.service has failed
-- Defined-By: systemd
-- Support: http://www.ubuntu.com/support
-- 
-- Unit mbpfancs.service has failed.
-- 
-- The result is RESULT.
Sep 28 10:57:08 macmini sudo[8518]: pam_unix(sudo:session): session closed for user root
lines 1061-1108/1108 (END)

= = = = = = = = =

编辑2:

~$ systemctl status mbpfancs.service
● mbpfancs.service - mbpfan Custom Service
   Loaded: loaded (/etc/systemd/system/mbpfancs.service; enabled; vendor preset:
   Active: activating (start) since Sat 2019-09-28 12:17:54 UTC; 2h 41min ago
 Main PID: 13324 (mbpfan)
    Tasks: 1 (limit: 4915)
   CGroup: /system.slice/mbpfancs.service
           └─13324 /usr/sbin/mbpfan -f

Sep 28 12:17:54 macmini systemd[1]: Starting mbpfan Custom Service...
Sep 28 12:17:54 macmini mbpfan[13324]: mbpfan starting up

答案1

您可以按照如下所述创建自定义服务。

但是,您需要知道mbpfan系统上可执行文件的确切路径。为此,请在终端中运行以下命令:

which mbpfan

你将获得如下输出:

/usr/sbin/mbpfan

复制输出并将PATH_TO_MBPFAN其替换到下面的服务文件中。然后,请按照以下说明进行操作。


首先,mbpfan通过在终端中运行以下命令来创建和编辑自定义 systemd 服务:

sudo nano /etc/systemd/system/mbpfancs.service 

第二,复制并粘贴以下代码到编辑器中替换PATH_TO_MBPFAN输出并按+然后按 然后按which mbpfan保存文件:CtrlXYEnter

[Unit]
Description=mbpfan Custom Service

[Service]
Type=oneshot
ExecStart=PATH_TO_MBPFAN -f

[Install]
WantedBy=multi-user.target

第三,通过在终端中运行以下命令来启动服务:

sudo systemctl start mbpfancs

第四,通过在终端中运行以下命令来启用该服务:

sudo systemctl enable mbpfancs

最后,重新启动系统。

相关内容