Installing supervisord with erpnext - nginx

I am a newbie to centos commands and scripting.
Scenario:
I have installed ERPNEXT and is working okay on the server but I have to do it manually by doing ./lib/wnfy.py --serve
What I want to do is to start it automatically using supervisord. I have gunicorn and nginx installed. Upon trying to start supervisord here's the error:
[root#vps3 etc]# chkconfig supervisord on [root#vps3 etc]# service
supervisord start /etc/init.d/supervisord: line 11:
./etc/rc.d/init.d/functionsprog=supervisord: No such file or directory
Starting : daemon --pidfile [ -f ]/etc/init.d/supervisord: line 14:
success: command not found /etc/init.d/supervisord: line 14: failure:
command not found
I am not yet familiar with how things work. Please advise. Thanks in advance.

Have you installed supervisor? Follow,
Install supervisor
Initscripts (use jkoppe ones).
Also for production setup, use gunicorn. Supervisor config for it is,
[program:gunicorn]
command=gunicorn -b 127.0.0.1:8000 -w 2 -t 120 lib.webnotes.app:application
directory=/path/to/erpnext
user=erpnext
process_name=%(program_name)s
autostart=True
autorestart=True
redirect_stderr=True

Related

Running Passenger 6.0.2 without Nginx?

For an existing rails app I would like to use Passenger without Nginx (because I already use Traefik as reverse-proxy / load balancer).
But passenger start always stats Nginx too. Sadly I'm neither an Passenger nor an Nginx expert.
How can I start passenger "standalone" ?
I'm using
Passenger 6.0.2
Rails 5.1.1
I'm starting passenger with ...
bundle exec passenger start -e production
There's no passengerconfig.json (...)
Reading the docs didn't help.
This is how I start the passenger
#!/bin/bash
bundle exec rake db:migrate RAILS_ENV=production
bundle exec passenger start -e production
When I check the processes using grep I see
nginx: master process /usr/local/bundle/gems/passenger-6.0.2/buildout/support-binaries/nginx-1.15.8 -c /tmp/passenger-standalone.184ibaq/nginx.conf -p /tmp/passenger-standalone.184ibaq
nginx: worker process
root
/usr/local/bundle/gems/passenger-6.0.2/buildout/support-binaries/PassengerAgent temp-dir-toucher /tmp/passenger-standalone.184ibaq --cleanup --daemonize --pid-file /tmp/passenger-standalone.184ibaq/temp_dir_toucher.pid --log-file /usr/src/app/log/passenger.3000.log --nginx-pid 27
Please help me how I can (re-)configure Passenger, so it skips Nginx.
I guess I found the solution myself:
passenger start -e production --engine=builtin
If you know a better solution, please let me know.

uWSGI autostart with systemd

So I was trying to get uWSGI and nginx working together and wanted to set the following command line to automatically execute and start my uWSGI background service:
uwsgi --master --processes 4 --die-on-term --uid uwsgi --gid nginx --socket /tmp/uwsgi.sock --chmod-socket --stats :1717 --no-site --vhost --logto /var/log/uwsgi.log
When using systemd I thought the only thing I'd need to do was using ExecStart= and starting that command. But since systemd needs absolute paths I take a look in the default uWSGI start script and saw that /usr/bin/uwsgi or usr/sbin/uwsgi would be the default start path.
So the final exec command for me looks something like this:
ExecStart=/usr/bin/uwsgi --master --processes 4 --die-on-term --uid uwsgi --gid nginx --socket /tmp/uwsgi.sock --chmod-socket --stats :1717 --no-site --vhost --logto /var/log/uwsgi.log
The Problem: When running this it's unable to find the option --no-site for running everything in a virtualenv.
When starting this with uwsgi in the command line it's not a problem.
But even when starting /usr/bin/uwsgi directly from the command line I get this error.
So to me it looks like the uwsgicommand isn't just running /usr/bin/uwsgi directly. But I'm not sure what I need to do to get this working.
I'd really appreciate any help I can get.
So I used whereis uwsgi to look through every folder that has a uwsgi instance in it again and found out that the default uwsgi application seems to be in /usr/local/uwsgi.
Have you tried putting your uwsgi config in a separate file?
ExecStart=/usr/bin/uwsgi --ini /path/to/your/app/uwsgi.ini
You can read more on uwsgi ini configs here

"configuration file /etc/nginx/nginx.conf test failed": How do I know why this happened?

I'm an nginx noob trying out this this tutorial on nginx 1.1.19 on ubuntu 12.04. I have this nginx config file.
When I run this command the test fails:
$ sudo service nginx restart
Restarting nginx: nginx: [crit] pread() "/etc/nginx/sites-enabled/csv" failed (21: Is a directory)
nginx: configuration file /etc/nginx/nginx.conf test failed
How do I know why the nginx.conf test failed?
sudo nginx -t should test all files and return errors and warnings locations
This particular commands worked for me.
sudo apt-get remove --purge nginx nginx-full nginx-common
and
sudo apt-get install nginx
credit to this answer on stackexchnage
The first solution is to test nginx conf using the basic
sudo nginx -t
Secondly, if you've changed the file yourself, copy/pasted json from one to another, there's a high chance that there's an encoding issue.
For example: " is not the same as
``
Try to write configurations by yourself. Check commas, colon and braces. Don't forget to reload the nginx.
sudo systemctl reload nginx
If you want to check syntax error for any nginx files, you can use the -c option.
[root#server ~]# sudo nginx -t -c /etc/nginx/my-server.conf
nginx: the configuration file /etc/nginx/my-server.conf syntax is ok
nginx: configuration file /etc/nginx/my-server.conf test is successful
[root#server ~]#
Show file and track error
systemctl status nginx.service

How to gracefully reload a spawn-fcgi script for nginx

My stack is nginx that runs python web.py fast-cgi scripts using spawn-fcgi. I am using runit to keep the process alive as a Daemon. I am using unix sockets fior the spawed-fcgi.
The below is my runit script called myserver in /etc/sv/myserver with the run file in /etc/sv/myserver/run.
exec spawn-fcgi -n -d /home/ubuntu/Servers/rtbTest/ -s /tmp/nginx9002.socket -u www-data -f /home/ubuntu/Servers/rtbTest/index.py >> /var/log/mylog.sys.log 2>&1
I need to push changes to the sripts to the production servers. I use paramiko to ssh into the box and update the index.py script.
My question is this, how do I gracefully reload the index.py using best practice to update to the new code.
Do I use:
sudo /etc/init.d/nginx reload
Do I restart the the runit script:
sudo sv start myserver
Or do I use both:
sudo /etc/init.d/nginx reload
sudo sv start myserver
Or none of the above?
Basically you have to re-start the process that's loaded your Python script. This is spawn-cgi and not nginx itself. nginx only communicates with spawn-cgi via the Unix socket and will happily re-connect if the connection is lost due to a restart of the spawn-cgi process.
Therefore I'd suggest a simple sudo sv restart myserver. No need to re-start/re-load nginx itself.

Nginx Invalid PID number

I issued a nginx -s stop and after that I got this error when trying to reload it.
[error]: invalid PID number "" in "/var/run/nginx.pid"
That /var/run/nginx/pid file is empty atm.
What do I need to do to fix it?
nginx -s reload is only used to tell a running nginx process to reload its config. After a stop, you don't have a running nginx process to send a signal to. Just run nginx (possibly with a -c /path/to/config/file)
in my case I solved this by starting the service.
sudo /etc/init.d/nginx start
The command above will start the service in Debian/Ubuntu. It will issue an error if there is any problem (like Apache listening in the same port)
After that nginx -s reload will work like a charm
This will clear out the issue on ubuntu 16.04 and above
sudo service nginx stop
you may need to remove the pid file nginx.pid whose location may be defined in file /etc/nginx/nginx.conf look for line like
cat /etc/nginx/nginx.conf | grep pid # see if pid file is defined
this line may live in file /etc/nginx/nginx.conf
pid /run/nginx.pid; # in file /etc/nginx/nginx.conf
if pid file does exist then remove it now
ls -la /var/run/nginx/pid # this file may live elsewhere
ls -la /run/nginx.pid # on Ubuntu 16.04+
after the pid file has been removed lets launch nginx
sudo service nginx start
ps -eaf|grep nginx # confirm its running
sudo nginx -t && sudo nginx -s reload # confirm config is OK
# typical output
# nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
# nginx: configuration file /etc/nginx/nginx.conf test is successful
sudo service nginx stop # issue stop
ps -eaf|grep nginx # confirm it actually stopped
now sanity has been restored and you are free to launch at will
In the latest version(1.2.0) that I downloaded there is no "-s start" option, it will say
nginx: invalid option: "-s start"
You can start nginx by
sudo /etc/nginx/sbin/nginx
The server will be started and then there wont be any Invalid pid number errors.
To avoid downtime with restarting nginx,
ps aux | grep nginx
PID of nginx master process
echo PID > /var/run/nginx.pid
nginx -s reload
In my case nginx was stopped (crashed I assume). Solved the issue by:
service nginx status
nginx stop/waiting
service nginx start
nginx start/running, process 3535
Then nginx -s reload worked like a charm.
I am using nginx/1.8.0 on trusty.
This happens if the nginx process was stopped manually or was killed.
Check if the process is still running:
sudo lsof -nP -iTCP:<port> | grep LISTEN
I am on mac, and I reinstall the nginx with:
brew reinstall nginx
Then start the service using brew:
brew services start nginx
On CentOS 7 I done it with this:
sudo systemctl start nginx
#Then check all things are OK
sudo systemctl status -l nginx
For anyone who still has issues, in my case, there was an apache2 server that was running.
You can try debugging what went wrong in your nginx machine by executing this command -
systemctl status nginx
This gave me an insight that the port was already in us by apache2 server.
so you can do sudo service apache2 stop and then do sudo service nginx start.
Docker Alpine users should use
nginx
by using that nginx will be start there is no error by
nginx -t
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful
then reload it by
nginx -s reload

Resources