我用 QtWebApp 编写了自己的服务器
现在我想使用 systemd 在 Ubuntu 15.10 启动时启动该服务器
我创建了这个服务文件
[Unit]
Description=This service maintains a landports server...
After=syslog.target
Wants=network-online.target
After=network.target network-online.target
[Service]
Type=forking
ExecStart=~/LandportsServer
Restart=on-abort
[Install]
WantedBy=multi-user.target
当我跑步时sudo systemctl start landports
系统输出systemd Loaded: error (Reason: Invalid argument)
我将我的服务文件更改为
[Unit]
Description=This service maintains a landports server...
[Service]
Type=forking
ExecStart= /home/wbmanager/LandportsServer
[Install]
WantedBy=multi-user.target
但当我跑步时sudo systemctl start landports
什么也没有发生,也没有显示任何输出,当我尝试使用浏览器连接到我的服务器时,连接失败,因此服务器没有运行
我之前已经通过运行它来测试我的服务器SSH它有效。但我无法让它作为服务运行
等待 systemd 输出后:
Jan 04 22:57:25 yassermyweb LandportsServer[4902]: Pattern handler and tokens: HttpRequestHandler(0x1018790) ("recent", ":portID")
Jan 04 22:57:25 yassermyweb LandportsServer[4902]: added pattern for path: recent/:portID
Jan 04 22:57:25 yassermyweb LandportsServer[4902]: RootHandler 0xffe820: registering handlers...
Jan 04 22:57:25 yassermyweb LandportsServer[4902]: Pattern handler and tokens: HttpRequestHandler(0x10183a0) ("")
Jan 04 22:57:25 yassermyweb LandportsServer[4902]: added pattern for path:
Jan 04 22:57:25 yassermyweb LandportsServer[4902]: HttpListener: Listening on port 0
Jan 04 22:58:55 yassermyweb systemd[1]: landports.service: Start operation timed out. Terminating.
Jan 04 22:58:55 yassermyweb systemd[1]: Failed to start This service maintains a landports server from the point the system is started until it is shut down again..
Jan 04 22:58:55 yassermyweb systemd[1]: landports.service: Unit entered failed state.
Jan 04 22:58:55 yassermyweb systemd[1]: landports.service: Failed with result
'timeout'.
注意行开头为模式处理程序和令牌:HttpRequestHandler(0x1018790)(“最近”,“:portID”)
是 mu=y 服务器的输出
答案1
我猜问题是ExecStart=~/LandportsServer
。请改用绝对路径。 systemd 应该使用哪个主目录?它以 root 身份运行。
另一个问题可能是您已将服务配置为Type=forking
.将其更改为Type=simple
(或注释掉该行)。