我有一個django應用程序,我使用gunicorn來運行它。我的腳本啓動gunicorn看起來像這樣:如何使用django作爲非root用戶運行gunicorn
django_path=/path/to/your/manage.py
settingsfile=my_name
workers=2
cd $django_path
exec gunicorn --env DJANGO_SETTINGS_MODULE=app.$settingsfile app.wsgi --workers=$workers &
這個工程,當我執行它。然而,當我在projectfolder (cd /path/to/your/manage.py && ll)
看我的數據庫中,我得到這個:
-rw-r--r-- 1 root root 55K Dec 2 13:33 db.sqlite3
這意味着我需要的根在未經許可做就DATABSE anyhting(例如做一個createuser
)。所以我看了看周圍#2和嘗試了幾件事情:
- 我整過的腳本在
/etc/init.d/rc.local
- 頂部然後我把腳本作爲腳本文件
gunicorn_script.sh
放於/etc/init.d
,做了/usr/sbin/update-rc.d -f gunicorn_script.sh defaults
- 最後,我想在
rc.local
文件的頂部把這個命令:su debian -c '/etc/init.d/gunicorn_script.sh start'
執行gunicorn_script作爲Debian的用戶
他們都開始了我的應用程序,但親數據庫依然存在(僅限於root權限)。
那麼如何以非root用戶身份運行該腳本?
嗨保羅。這是一篇關於以非root用戶身份運行Django,Nginx,Gunicorn的好文章:http://michal.karzynski.pl/blog/2013/06/09/django-nginx-gunicorn-virtualenv-supervisor/ –