I have installed gunicorn webserver and make gunicorn virtualenv init.d script but when i run service gunicorn start
service from my project directory it works well, But when my present working directory changed such as /root or anyother directory it gives me error. I have edited init script and add following command at start of that script cd /root/demoproject/
script runs from any working directory. What else will be the actual solution other that adding cd /root/demoproject/
command in init script ?
1 Answer
There is nothing wrong with letting the script change its working directory, if it needs to be run with a specific working directory (due to it using relative paths, or whatever it does).
The only thing that one may want to do is to exit with a non-zero exit status if the cd
failed:
cd /root/demoproject || exit 1
You may also change directory in the script depending on the value of an environment variable:
cd "${MY_WORK_DIR:-/root/demoproject}" || exit 1
This would change working directory to the directory given by MY_WORK_DIR
, but would default to /root/demoproject
if this variable is empty or unset.
-
I have edited the question, Actually i want to know Is there anything possible to make env variable instead of adding
cd /root/demoproject/
in init script ? Jun 27, 2018 at 8:12 -