我正在尝试制作一个服务文件,以便在使用systemd引导时启动进程。
我的服务文件如下
[Unit]
>Description=ProtonVPN daemon
> After=network.target
>
> [Service]
>Type=simple
> User=doback
>WorkingDirectory=/usr/local/bin/
>ExecStart=/bin/bash /usr/local/bin/protonvpn.sh
>RemainAfterExit=yes
> Restart=always
>
> [Install] WantedBy=multi-user.target
systemctl状态为myservicefile.service的输出
> ● protonvpn.service - ProtonVPN daemon Loaded: loaded
> (/etc/systemd/system/protonvpn.service; enabled; vendor preset:
> enabled) Active: active (exited) since Tue 2019-02-19 09:06:48 MST;
> 10h ago Main PID: 1043 (code=exited, status=0/SUCCESS)
> Tasks: 0 (limit: 4915) CGroup: /system.slice/protonvpn.service
>
> Feb 19 09:06:48 doback-Flex-3-1580 systemd[1]: Started ProtonVPN
> daemon. Feb 19 15:08:23 doback-Flex-3-1580 systemd[1]:
> /etc/systemd/system/protonvpn.service:9: Executable path is not
> absolute: protonvpn.sh Feb 19 15:08:30 doback-Flex-3-1580 systemd[1]:
> /etc/systemd/system/protonvpn.service:9: Executable path is not
> absolute: protonvpn.sh
journalctl -u myservicefile.service的输出
root@doback-Flex-3-1580:/usr/local/bin# nano protonvpn.sh
root@doback-Flex-3-1580:/usr/local/bin# nano protonvpn.python
root@doback-Flex-3-1580:/usr/local/bin# nano protonvpn.sh
root@doback-Flex-3-1580:/usr/local/bin# journalctl -u protonvpn.service
-- Logs begin at Sun 2019-01-06 18:53:48 MST, end at Tue 2019-02-19 19:21:44 MST. --
Feb 04 21:24:33 doback-Flex-3-1580 systemd[1]: /etc/systemd/system/protonvpn.service:3: Unknown lvalue 'After network.target' in section 'Unit'
Feb 04 21:24:33 doback-Flex-3-1580 systemd[1]: /etc/systemd/system/protonvpn.service:7: Executable path specifies a directory: / usr / local / bin / start protonvpn.sh
Feb 04 21:25:28 doback-Flex-3-1580 systemd[1]: /etc/systemd/system/protonvpn.service:3: Unknown lvalue 'After network.target' in section 'Unit'
Feb 04 21:25:28 doback-Flex-3-1580 systemd[1]: /etc/systemd/system/protonvpn.service:7: Executable path specifies a directory: / usr / local / bin / start protonvpn.sh
Feb 04 21:29:07 doback-Flex-3-1580 systemd[1]: /etc/systemd/system/protonvpn.service:3: Unknown lvalue 'After network.target' in section 'Unit'
Feb 04 21:29:07 doback-Flex-3-1580 systemd[1]: /etc/systemd/system/protonvpn.service:7: Executable path specifies a directory: / usr / local / bin / start protonvpn.sh
Feb 04 21:29:17 doback-Flex-3-1580 systemd[1]: /etc/systemd/system/protonvpn.service:3: Unknown lvalue 'After network.target' in section 'Unit'
Feb 04 21:29:17 doback-Flex-3-1580 systemd[1]: /etc/systemd/system/protonvpn.service:7: Executable path specifies a directory: / usr / local / bin / start protonvpn.sh
Feb 04 21:42:41 doback-Flex-3-1580 systemd[1]: /etc/systemd/system/protonvpn.service:3: Unknown lvalue 'After network.target' in section 'Unit'
Feb 04 21:42:41 doback-Flex-3-1580 systemd[1]: /etc/systemd/system/protonvpn.service:7: Executable path specifies a directory: / usr / local / bin / start protonvpn.sh
-- Reboot --
Feb 05 16:11:41 doback-Flex-3-1580 systemd[1]: /etc/systemd/system/protonvpn.service:3: Unknown lvalue 'After network.target' in section 'Unit'
Feb 05 16:11:41 doback-Flex-3-1580 systemd[1]: /etc/systemd/system/protonvpn.service:7: Executable path specifies a directory: / usr / local / bin / start protonvpn.sh
Feb 05 16:12:57 doback-Flex-3-1580 systemd[1]: /etc/systemd/system/protonvpn.service:3: Unknown lvalue 'After network.target' in section 'Unit'
Feb 05 16:12:57 doback-Flex-3-1580 systemd[1]: /etc/systemd/system/protonvpn.service:7: Executable path specifies a directory: / usr / local / bin / start protonvpn.sh
Feb 05 16:12:59 doback-Flex-3-1580 systemd[1]: /etc/sy
我似乎无法弄清楚问题出在哪里。状态表明它已启用并已加载,并且路径是绝对路径,但是我一直收到错误消息。
编辑:
我从WorkingDirectory语句中删除了最后的/。似乎已将systemctl状态myservicefile.service的错误代码更改为
● protonvpn.service - ProtonVPN daemon
Loaded: loaded (/etc/systemd/system/protonvpn.service; enabled; vendor preset: enabled)
Active: active (exited) since Wed 2019-02-20 03:15:34 MST; 45min ago
Main PID: 1022 (code=exited, status=0/SUCCESS)
Tasks: 0 (limit: 4915)
CGroup: /system.slice/protonvpn.service
Feb 20 03:15:34 doback-Flex-3-1580 systemd[1]: Started ProtonVPN daemon.
Feb 20 03:15:37 doback-Flex-3-1580 bash[1022]: sudo: no tty present and no askpass program specified
Feb 20 03:15:39 doback-Flex-3-1580 bash[1022]: sudo: no tty present and no askpass program specified
journalctl -u myservicefile.service的输出相同 另外,我还赋予了shell脚本sudo权限,因此它不需要密码即可运行。重新加载了守护程序。同样的问题。