clash icon indicating copy to clipboard operation
clash copied to clipboard

[Help] 如何设置日志的保存位置呢?(systemd运行模式)

Open LonePheasantWarrior opened this issue 2 years ago • 4 comments

Verify steps

  • [X] 我已经在 Issue Tracker 中找过我要提出的请求 I have searched on the issue tracker for a related feature request.
  • [X] 我已经仔细看过 Documentation 并无法自行解决问题 I have read the documentation and was unable to solve the issue.

Description

这是我现在的systemd命令:

[Unit]
Description=clash daemon  
[Service] 
Type=simple 
User=root 
ExecStart=/usr/local/bin/clash -d /home/wxh/.config/clash
Restart=on-failure  
[Install]
WantedBy=multi-user.target

即使我将其变更为:

/usr/local/bin/clash -d /home/wxh/.config/clash > /var/log/clash.log 2>&1

其中的/var/log/clash.log也不会有任何内容出现 通过

sudo systemctl status clash
wxh@ubuntu:~$ sudo systemctl status clash
● clash.service - clash daemon
     Loaded: loaded (/etc/systemd/system/clash.service; enabled; vendor preset: enabled)
     Active: active (running) since Mon 2022-07-25 11:37:55 CST; 7s ago
   Main PID: 61522 (clash)
      Tasks: 9 (limit: 9237)
     Memory: 7.4M
        CPU: 219ms
     CGroup: /system.slice/clash.service
             └─61522 /usr/local/bin/clash -d /home/wxh/.config/clash

Jul 25 11:37:55 ubuntu systemd[1]: Started clash daemon.
Jul 25 11:37:55 ubuntu clash[61522]: time="2022-07-25T11:37:55+08:00" level=info msg="Start initial compatible provider 自动选择快速节点"
Jul 25 11:37:55 ubuntu clash[61522]: time="2022-07-25T11:37:55+08:00" level=info msg="Start initial compatible provider PROXY"
Jul 25 11:37:55 ubuntu clash[61522]: time="2022-07-25T11:37:55+08:00" level=info msg="Start initial compatible provider Final"
Jul 25 11:37:55 ubuntu clash[61522]: time="2022-07-25T11:37:55+08:00" level=info msg="Start initial compatible provider HKMTMedia"
Jul 25 11:37:55 ubuntu clash[61522]: time="2022-07-25T11:37:55+08:00" level=info msg="Start initial compatible provider Apple"

发现Started clash daemon.应该fork了子进程跑的服务,啊这,这这... 应该是在config.yaml里面配置,但是具体该怎么配置呢?在网上也找了些config的描述文章,但是都没有提到日志位置相关的配置 或者说systemd相关服务的日志有其专用的查看方式?(写到这里的时候突然想到的,先发出来再说,一会儿我自己再查资料吧,linux用的比较烂哈哈哈) 有大神有更好的方案请不吝赐教!

Possible Solution

No response

LonePheasantWarrior avatar Jul 25 '22 03:07 LonePheasantWarrior

我的是这样的 [Unit] Description=tun-clash proxy Documentation=https://github.com/Dreamacro/clash After=network.target

[Service] Type=simple LimitCORE=infinity LimitNOFILE=65535 LimitNPROC=65535 Slice=tun-clash.slice ExecStart=/usr/local/bin/tun_clash -d /opt/clash ExecStartPost=/opt/start_tun_clash.sh ExecStopPost=/opt/stop_clash.sh Restart=always RestartSec=1s StandardOutput=file:/tmp/tun_clash.log

[Install] WantedBy=default.targe

xuan880 avatar Jul 28 '22 00:07 xuan880

我的是这样的 [Unit] Description=tun-clash proxy Documentation=https://github.com/Dreamacro/clash After=network.target

[Service] Type=simple LimitCORE=infinity LimitNOFILE=65535 LimitNPROC=65535 Slice=tun-clash.slice ExecStart=/usr/local/bin/tun_clash -d /opt/clash ExecStartPost=/opt/start_tun_clash.sh ExecStopPost=/opt/stop_clash.sh Restart=always RestartSec=1s StandardOutput=file:/tmp/tun_clash.log

[Install] WantedBy=default.targe

感觉比较靠谱,我试试

LonePheasantWarrior avatar Jul 28 '22 10:07 LonePheasantWarrior

我的是这样的 [Unit] Description=tun-clash proxy Documentation=https://github.com/Dreamacro/clash After=network.target [Service] Type=simple LimitCORE=infinity LimitNOFILE=65535 LimitNPROC=65535 Slice=tun-clash.slice ExecStart=/usr/local/bin/tun_clash -d /opt/clash ExecStartPost=/opt/start_tun_clash.sh ExecStopPost=/opt/stop_clash.sh Restart=always RestartSec=1s StandardOutput=file:/tmp/tun_clash.log [Install] WantedBy=default.targe

感觉比较靠谱,我试试

ExecStartPost=/opt/start_tun_clash.sh ExecStopPost=/opt/stop_clash.sh 这两句是我自己写的启动前后处理脚本,你不需要用,StandardOutput=file:/tmp/tun_clash.log 这句就是你需要的重定向日志到指定文件.

xuan880 avatar Jul 28 '22 12:07 xuan880

对于名为clash的systemd服务,其stdout/stderr输出一般会自动有journald进行收集,可以使用journalctl -u clash进行查看,可以看一下更详细的journalctl的用法

fanvinga avatar Jul 29 '22 13:07 fanvinga

我的是这样的 [Unit] Description=tun-clash proxy Documentation=https://github.com/Dreamacro/clash After=network.target [Service] Type=simple LimitCORE=infinity LimitNOFILE=65535 LimitNPROC=65535 Slice=tun-clash.slice ExecStart=/usr/local/bin/tun_clash -d /opt/clash ExecStartPost=/opt/start_tun_clash.sh ExecStopPost=/opt/stop_clash.sh Restart=always RestartSec=1s StandardOutput=file:/tmp/tun_clash.log [Install] WantedBy=default.targe

感觉比较靠谱,我试试

ExecStartPost=/opt/start_tun_clash.sh ExecStopPost=/opt/stop_clash.sh 这两句是我自己写的启动前后处理脚本,你不需要用,StandardOutput=file:/tmp/tun_clash.log 这句就是你需要的重定向日志到指定文件.

我觉得 journalctl -u clash 这个方法更好,完全满足我需求了

LonePheasantWarrior avatar Aug 10 '22 05:08 LonePheasantWarrior

对于名为clash的systemd服务,其stdout/stderr输出一般会自动有journald进行收集,可以使用journalctl -u clash进行查看,可以看一下更详细的journalctl的用法

3Q!

LonePheasantWarrior avatar Aug 10 '22 05:08 LonePheasantWarrior