시스템 서비스를 시작할 수 없습니다

시스템 서비스를 시작할 수 없습니다

방금 Python Flask 프로젝트의 모든 작업을 마쳤으며 이를 사용하여 서비스를 제공하고 싶습니다.

시작하기 위해 서버를 시작하고 /home/pi에 위치할 수 있는 bash 파일을 만들었습니다.

#!/bin/bash
cd /home/pi/Desktop/secure-pi-tensorflow
python3 /home/pi/Desktop/secure-pi-tensorflow/run.py

내 서비스 파일은 다음과 같습니다.

[Unit]
After=multi-user.target

[Service]
Type=idle
ExecStart=/home/pi/securepi.sh

[Install]
WantedBy=multi-user.target

내가 직면한 문제는 bash 파일을 사용하여 서버를 시작할 수 있지만 서비스로 시작되지 않고 다음 오류가 나타난다는 것입니다.

pi@securepi:~ $ systemctl status securepi.service
Warning: The unit file, source configuration file or drop-ins of securepi.service changed on disk. Run 'systemctl daemon-reload' to reload units.
● securepi.service
   Loaded: loaded (/lib/systemd/system/securepi.service; enabled; vendor preset: enabled)
   Active: failed (Result: exit-code) since Mon 2019-10-28 15:42:39 GMT; 8min ago
  Process: 1325 ExecStart=/usr/bin/python3 /home/pi/Desktop/secure-pi-tensorflow/run.py (code=exited, status=1/FAILURE)
 Main PID: 1325 (code=exited, status=1/FAILURE)

Oct 28 15:42:38 securepi systemd[1]: Started securepi.service.
Oct 28 15:42:39 securepi python3[1325]: Traceback (most recent call last):
Oct 28 15:42:39 securepi python3[1325]:   File "/home/pi/Desktop/secure-pi-tensorflow/run.py", line 12, in <module>
Oct 28 15:42:39 securepi python3[1325]:     from securepi import app
Oct 28 15:42:39 securepi python3[1325]:   File "/home/pi/Desktop/secure-pi-tensorflow/securepi/__init__.py", line 4, in <module>
Oct 28 15:42:39 securepi python3[1325]:     from flask_jsglue import JSGlue
Oct 28 15:42:39 securepi python3[1325]: ModuleNotFoundError: No module named 'flask_jsglue'
Oct 28 15:42:39 securepi systemd[1]: securepi.service: Main process exited, code=exited, status=1/FAILURE
Oct 28 15:42:39 securepi systemd[1]: securepi.service: Failed with result 'exit-code'.

이 오류로 인해 무슨 일이 일어나고 있는지 아는 사람이 있습니까? bash 파일을 사용하면 모든 것이 잘 실행되지만 서비스를 시도하면 항상 실패합니다.

나는 또한 언급하고 싶다플라스크_jsgluePython2.7 및 3용으로 설치됨

pi@securepi:~ $ python3
Python 3.7.3 (default, Apr  3 2019, 05:39:12) 
[GCC 8.2.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import flask_jsglue
[2]+  Stopped                 python3
pi@securepi:~ $ python
Python 2.7.16 (default, Apr  6 2019, 01:42:57) 
[GCC 8.2.0] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import flask_jsglue

답변1

/etc/systemd/system/my_service.service 파일의 [Service] 섹션에 시스템 사용자(예: pi 또는 ubuntu)를 추가하기만 하면 됩니다.

[Unit]
After=multi-user.target

[Service]
Type=idle
ExecStart=/home/pi/securepi.sh
User=your_system_user

[Install]
WantedBy=multi-user.target

답변2

내가 해야 할 일은 문제를 해결하기 위해 User=pi를 추가하는 것뿐이었습니다.

관련 정보