ある記事を元に自作で作ったWebサーバをubuntu16のデーモンに登録して、実行させようとするのですが、うまく動作しないためご教授をお願いします。
参考にしたのは、以下のサイトです。
http://denbei.o.oo7.jp/f1/?p=2114
【うまく行かないこと】
登録したサービスを実行し、statusを見ると、サービスの実行に失敗しているようでした。そこで、/var/log/syslogでログを見ると、/home/web/cgiserver.pyのファイルを実行しようとして、権限がないと怒られているようです。
実行権限がないので、とりあえず上記のファイルをchmod 777 /home/web/cgiserver.pyで実行権限をあ与えて見ましたが、同じエラーになりうまくいきません。何が悪いのか思いつかないので、教えてくださいお願いします。
以下がエラー内容です。
Jul 16 15:50:36 ubuntu1607 systemd[53788]: cgid.service: Failed at step EXEC spawning /home/web/cgiserver.py: Permission denied Jul 16 15:50:36 ubuntu1607 systemd[1]: cgid.service: Main process exited, code=exited, status=203/EXEC Jul 16 15:50:36 ubuntu1607 systemd[1]: cgid.service: Unit entered failed state. Jul 16 15:50:36 ubuntu1607 systemd[1]: cgid.service: Failed with result 'exit-code'. Jul 16 15:50:36 ubuntu1607 systemd[1]: cgid.service: Service hold-off time over, scheduling restart. Jul 16 15:50:36 ubuntu1607 systemd[1]: Stopped CGI-Server. Jul 16 15:50:36 ubuntu1607 systemd[1]: cgid.service: Start request repeated too quickly. Jul 16 15:50:36 ubuntu1607 systemd[1]: Failed to start CGI-Server. Jul 16 15:50:36 ubuntu1607 systemd[1]: cgid.service: Unit entered failed state. Jul 16 15:50:36 ubuntu1607 systemd[1]: cgid.service: Failed with result 'start-limit-hit'.
ソースについて追加します。
cgiserver.pyの!/home/web/envは、python3の仮想環境のパスです。
よろしくお願いします。
// cgiserver.py
#!/home/web/env python3 # -*- coding: utf-8 -*- from http.server import HTTPServer, CGIHTTPRequestHandler import os os.chdir('/home/web') host = '192.168.0.14' port = 8000 httpd = HTTPServer((host, port), CGIHTTPRequestHandler) print('serving at port', port) httpd.serve_forever()
// /etc/systemd/system/cgid.service
[Unit] Description = CGI-Server [Service] ExecStart=/home/web/cgiserver.py Restart=always Type=simple [Install] WantedBy=multi-user.target
回答1件
あなたの回答
tips
プレビュー