[英]How to use user's pipenv via systemd? Python is installed via SCL
在CentOS 7服務器上,我已經通過SCL安裝了Python 3.6。 ( https://www.softwarecollections.org/en/scls/rhscl/rh-python36/ )
我在.bashrc中有這一行來啟用SCL的Python 3.6
source scl_source enable rh-python36
我已經安裝了pipenv:
pip install --user pipenv
我通過命令行運行Python程序:
pipenv run python myprogram.py
所有這些都很好。 我有一個使用用戶的pipenv的Flask應用程序。 我正在嘗試創建一個systemd單位文件來啟動/停止/重新加載Flask Web應用程序。 如何獲得sytemd單元文件以使用通過SCL的Python和pip安裝的用戶pipenv?
我試圖從根目錄執行命令行,但出現此錯誤:
[root@localhost ~]# source scl_source enable rh-python36
[root@localhost ~]# /home/user/.local/bin/pipenv run python /home/user/hello.py
Traceback (most recent call last):
File "/home/user/.local/bin/pipenv", line 7, in <module>
from pipenv import cli
ModuleNotFoundError: No module named 'pipenv'
但是,我可以通過加載用戶的bash shell通過su -c執行命令:
su -c 'bash -lc /home/user/.local/bin/pipenv run python hello.py' user
但是這條線似乎很尷尬。 我可以在systemd單位文件的ExecStart行中使用的正確行是什么? 為了使用用戶的pipenv,應包括哪些環境變量?
這是我工作的systemd單位文件:
[Unit]
Description=Python app
# Requirements
Requires=network.target
# Dependency ordering
After=network.target
[Service]
# Let processes take awhile to start up
TimeoutStartSec=0
RestartSec=10
Restart=always
Environment="APP_SITE_SETTINGS=/home/app/.config/settings.cfg"
Environment="PYTHONPATH=/home/app/.local/lib/python3.6/site-packages"
WorkingDirectory=/home/app/app-site
User=app
Group=app
PermissionsStartOnly=true
KillSignal=SIGQUIT
Type=notify
NotifyAccess=all
# Main process
ExecStartPre=/bin/mkdir -p /run/app
ExecStartPre=/bin/chown app:app /run/app
#ExecStartPre=source scl_source enable rh-python36
ExecStart=/usr/bin/scl enable rh-python36 -- /home/app/.local/bin/pipenv run uwsgi \
--socket 127.0.0.1:6003 \
--buffer-size 65535 \
--enable-threads \
--single-interpreter \
--threads 1 \
-L \
--stats /run/app/uwsgi_stats.socket \
--lazy-apps \
--master-fifo /run/stocks/uwsgimasterfifo \
--processes 1 \
--harakiri 960 \
--max-worker-lifetime=21600 \
--ignore-sigpipe \
--ignore-write-errors \
--disable-write-exception \
--mount /=run:app \
--manage-script-name
[Install]
WantedBy=multi-user.target
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.