是否可以通过向 Web 服务器发送请求来重新启动系统?到目前为止,这是我尝试过的,但不断收到错误消息(Plug.Conn.NotSentError) a response was neither set nor sent from the connection
。
defmodule App.Web.SystemController do
use App.Web, :controller
def system(conn, %{"command" => command}) do
"sudo shutdown -r now" |> String.to_char_list |> :os.cmd
conn
end
end
我在 RPI 上的本地服务器上工作,并希望在界面中有一个自动重启服务器的按钮。用 elixir 关闭服务器的正确方法是什么?
我也在想我可以编写一个 bash 脚本,然后直接调用它,但不确定它是否会对网络服务器产生任何负面影响。任何建议,建议表示赞赏!
我从终端得到的错误:
Request: POST /api/v1/system_power/
** (exit) an exception was raised:
** (Plug.Conn.NotSentError) a response was neither set nor sent from the connection
(plug) lib/plug/adapters/cowboy/handler.ex:42: Plug.Adapters.Cowboy.Handler.maybe_send/2
(plug) lib/plug/adapters/cowboy/handler.ex:16: Plug.Adapters.Cowboy.Handler.upgrade/4
(cowboy) /Users/user/app/deps/cowboy/src/cowboy_protocol.erl:442: :cowboy_protocol.execute/4