5

したがって、配管工のコマンドを手動で実行すると、サーバー上だけでなくローカルでも正常に動作する API があります。つまり、サーバーで ssh を実行して実行することを意味します。

r <- plumb("plumber.R")
r$run(port=8000, host = "0.0.0.0")

次のようになります。

#* @serializer contentType list(type="application/html")
#* @get /test
function(res){

  include_rmd("test.Rmd", res)

}

#* Echo the parameter that was sent in
#* @param msg The message to echo back.
#* @get /echo
function(msg=""){
  list(msg = paste0("The message is: '", msg, "'"))
}

どちらも問題なく動作します。しかし、systemd を使用してサーバー上でそれらを維持すると、/echo のみが機能します。もう1つは、「例外が発生しました」と言うだけです。

systemd のセットアップは次のようになります。

[Unit]
Description=Plumber API
# After=postgresql
# (or mariadb, mysql, etc if you use a DB with Plumber, otherwise leave this commented)

[Service]
ExecStart=/usr/bin/Rscript -e "api <- plumber::plumb('/home/chrisbeeley/api/plumber.R'); api$run(port=8000, host='0.0.0.0')"
Restart=on-abnormal
WorkingDirectory=/home/chrisbeeley/api/
[Install]
WantedBy=multi-user.target

エラーログがどこにも見つからず、サーバーでコマンドを実行すると機能するはずなのに、systemdを使用すると機能しない理由について非常に混乱しています。

Ubuntu 16.04 を使用しています。

昨夜これを投稿して以来、16.04 を実行しているまったく別のサーバーにすべてをデプロイしましたが、まったく同じ動作を示しています。

編集:pdfを返し、「例外が発生しました」も返す配管工のドキュメントのコードに基づいて、これも試しました

#* @serializer contentType list(type="text/html; charset=utf-8")
#* @get /html
function(){

  tmp <- tempfile()

  render("test_report.Rmd", tmp, output_format = "html_document")

  readBin(tmp, "raw", n=file.info(tmp)$size)
}
4

1 に答える 1