我在Ubuntu上运行了一个Nodejs脚本,它充当HTTP服务器(使用Express),当向服务器发出特定的POST时,它将尝试登录到SVN并使用以下代码执行svn info命令:
svn_info = ["info", server, "--xml", "--non-interactive", "--username", svn_username, "--password", svn_password, "--no-auth-cache"];
output = spawnSync("svn", svn_info, { encoding: 'utf8' });
logger.debug(output.output);这与使用命令行的独立脚本工作得很好。执行nodejs app.js并发送适当的POST,结果如下(路径名等已在此处手动替换为方括号中的"labels“):
<?xml version="1.0" encoding="UTF-8"?>
<info>
<entry path="my_path" revision="67368" kind="dir">
<url>https://[svn_server]/[root_path]/[relative_path]/my_path</url>
<relative-url>^/[relative_path]/my_path</relative-url>
<repository>
<root>https://[svn_server]/[root_path]</root>
<uuid>[UUID]</uuid>
</repository>
<commit revision="67334">
<author>author@domain</author>
<date>2019-02-07T15:33:15.806240Z</date>
</commit>
</entry>
</info>我的systemd脚本test_server.service像这样调用Nodejs脚本:
[Unit]
Wants=network-online.target
After=network-online.target
[Service]
ExecStart=/usr/bin/nodejs /home/some_path/app.js
[Install]
WantedBy=multi-user.target当通过boot或service test_server start命令启动脚本并执行相同的POST命令时,我在日志文件中看到以下内容:
[2019-02-08T15:25:19.251Z] debug: ,<?xml version="1.0" encoding="UTF-8"?>
<info>
,svn: E170013: Unable to connect to a repository at URL 'https://[svn_server]/[root_path]/[relative_path]/my_path'
svn: E000111: Error running context: Connection refused无论是从shell还是在systemd启动时,脚本都是以root用户身份运行的。我很难理解是什么细微的差异导致脚本在由systemd执行时失败。
发布于 2019-03-05 20:50:59
tldr;
结果表明,这与上面发布的代码无关。这是因为运行web服务器的机器与运行SVN服务器的机器在不同的网络上。两者仅允许通过代理进行通信,需要在~/.subversion/servers文件中进行设置。
更长的故事
当以“SVN”身份登录时,该用户在~/.subversion/servers文件中正确设置了user1代理服务器。可以对SVN存储库运行sudo svn info,大概是因为使用了相同的~/.subversion/servers文件。
如果我使用sudo -i (它以“根”身份运行,所有环境变量都设置为以“根”身份登录),我会发现,果然,在使用svn info时,我得到了“连接被拒绝”的错误。
编辑~/.subversion/servers文件以使用正确的代理后:
[global]
# http-proxy-exceptions = *.exception.com, www.internal-site.org
http-proxy-host = defaultproxy.whatever.com
http-proxy-port = 7000一切都运行得很完美!
https://stackoverflow.com/questions/54597359
复制相似问题