创建服务报错“service: control process exited, code=exited status=2”的解决办法

内容

本文最后更新于 2020年2月12日。

2020年2月12日将v2设置为Linux服务时启动始终报错。

终于晚上11点时看官方教程知道用journalctl -u v2ray命令看服务启动日志,发现了这个问题

 Feb 12 10:55:26 iz2zeay7xfu2g305d5e2tvz systemd[1]: Starting v2ray-gxm...
Feb 12 10:55:27 iz2zeay7xfu2g305d5e2tvz v2ray[781]: flag provided but not defined: -c
Feb 12 10:55:27 iz2zeay7xfu2g305d5e2tvz v2ray[781]: Usage of /root/v2ray/v2ray:
Feb 12 10:55:27 iz2zeay7xfu2g305d5e2tvz v2ray[781]: -config string
Feb 12 10:55:27 iz2zeay7xfu2g305d5e2tvz v2ray[781]: Config file for V2Ray.
Feb 12 10:55:27 iz2zeay7xfu2g305d5e2tvz v2ray[781]: -format string
Feb 12 10:55:27 iz2zeay7xfu2g305d5e2tvz v2ray[781]: Format of input file. (default "json")
Feb 12 10:55:27 iz2zeay7xfu2g305d5e2tvz v2ray[781]: -test
Feb 12 10:55:27 iz2zeay7xfu2g305d5e2tvz v2ray[781]: Test config file only, without launching V2Ray serv
Feb 12 10:55:27 iz2zeay7xfu2g305d5e2tvz v2ray[781]: -version
Feb 12 10:55:27 iz2zeay7xfu2g305d5e2tvz v2ray[781]: Show current version of V2Ray.
Feb 12 10:55:27 iz2zeay7xfu2g305d5e2tvz systemd[1]: v2.service: control process exited, code=exited sta
Feb 12 10:55:27 iz2zeay7xfu2g305d5e2tvz systemd[1]: Failed to start v2ray-gxm.
Feb 12 10:55:27 iz2zeay7xfu2g305d5e2tvz systemd[1]: Unit v2.service entered failed state.
Feb 12 10:55:27 iz2zeay7xfu2g305d5e2tvz systemd[1]: v2.service failed.
Feb 12 11:08:59 iz2zeay7xfu2g305d5e2tvz systemd[1]: Starting v2ray-gxm...

原来是service文件中引用配置文件参数 -c 无法识别,改为-config就好了

 [root@iz2zeay7xfu2g305d5e2tvz ~]# service v2 start
Redirecting to /bin/systemctl start v2.service
Warning: v2.service changed on disk. Run 'systemctl daemon-reload' to reload units.
[root@iz2zeay7xfu2g305d5e2tvz ~]# systemctl daemon-reload
[root@iz2zeay7xfu2g305d5e2tvz ~]# service v2 start
Redirecting to /bin/systemctl start v2.service
[root@iz2zeay7xfu2g305d5e2tvz ~]# service v2 status
Redirecting to /bin/systemctl status v2.service
● v2.service - v2ray-gxm
Loaded: loaded (/usr/lib/systemd/system/v2.service; enabled; vendor preset: disabled)
Active: active (running) since Wed 2020-02-12 23:01:22 CST; 30s ago
Docs: https://weiyoun.com
Main PID: 15584 (v2ray)
CGroup: /system.slice/v2.service
└─15584 /root/v2ray/v2ray
Feb 12 23:01:22 iz2zeay7xfu2g305d5e2tvz systemd[1]: Started v2ray-gxm.
Feb 12 23:01:22 iz2zeay7xfu2g305d5e2tvz v2ray[15584]: V2Ray 4.21.3 (V2Fly, a community-driven edit...om
Feb 12 23:01:22 iz2zeay7xfu2g305d5e2tvz v2ray[15584]: A unified platform for anti-censorship.
Feb 12 23:01:22 iz2zeay7xfu2g305d5e2tvz v2ray[15584]: 2020/02/12 23:01:22 [Warning] v2ray.com/core...ed
Feb 12 23:01:38 iz2zeay7xfu2g305d5e2tvz systemd[1]: Current command vanished from the unit file, ...ed.
Hint: Some lines were ellipsized, use -l to show in full.

之前报这种错误

 [root@iz2zeay7xfu2g305d5e2tvz ~]# service v2 status -l
Redirecting to /bin/systemctl status -l v2.service
● v2.service - v2ray-gxm
Loaded: loaded (/usr/lib/systemd/system/v2.service; enabled; vendor preset: disabled)
Active: failed (Result: exit-code) since Wed 2020-02-12 22:09:03 CST; 51min ago
Docs: https://weiyoun.com
Feb 12 22:09:03 iz2zeay7xfu2g305d5e2tvz v2ray[28053]: -format string
Feb 12 22:09:03 iz2zeay7xfu2g305d5e2tvz v2ray[28053]: Format of input file. (default "json")
Feb 12 22:09:03 iz2zeay7xfu2g305d5e2tvz v2ray[28053]: -test
Feb 12 22:09:03 iz2zeay7xfu2g305d5e2tvz v2ray[28053]: Test config file only, without launching V2Ray server.
Feb 12 22:09:03 iz2zeay7xfu2g305d5e2tvz v2ray[28053]: -version
Feb 12 22:09:03 iz2zeay7xfu2g305d5e2tvz v2ray[28053]: Show current version of V2Ray.
Feb 12 22:09:03 iz2zeay7xfu2g305d5e2tvz systemd[1]: v2.service: control process exited, code=exited status=2
Feb 12 22:09:03 iz2zeay7xfu2g305d5e2tvz systemd[1]: Failed to start v2ray-gxm.
Feb 12 22:09:03 iz2zeay7xfu2g305d5e2tvz systemd[1]: Unit v2.service entered failed state.
Feb 12 22:09:03 iz2zeay7xfu2g305d5e2tvz systemd[1]: v2.service failed.
Warning: v2.service changed on disk. Run 'systemctl daemon-reload' to reload units.

总结用到的的其他命令

将服务设为自启动

systemctl enable v2

 

刷新service文件

systemctl daemon-reload

 

官方说明

V2Ray 闪退

如果你使用 Linux 并开启了 systemd,可以使用 journalctl -u v2ray 查看 V2Ray 退出时的日志;

一般情况可以手动运行 v2ray -config=<config-file> -test 来查看错误信息