How to run the socket io server using gunicorn service

I'm using the service in my Django app, and I want to create one gunicorn service that is responsible for starting the service.

Below is the socket io server code

File name:

from wsgi import application
from server_events import sio

app = socketio.WSGIApp(sio, application)

class Command(BaseCommand):
    help = 'Start the server'

    def handle(self, *args, **options):
        eventlet.wsgi.server(eventlet.listen(('', 8001)), app)

Below is the actual code of the server with connect, disconnect and one custom method

File name:

from wsgi import application

sio = socketio.Server(logger=True)
app = socketio.WSGIApp(sio, application)

def connected(sid, environ):
    print("Server connected with sid: {}".format(sid))

def disconnect(sid):
    print("Server disconnected with sid: {}".format(sid))

def run_bots(sid):
    print("func executed")
    **# Here custom logic**

When I hit python server in local, it will work fine, but on a production server, I don't want to type the python server command. What I want is to create one Gunicorn service and provide some instructions to that service so that when I hit the Gunicorn service command, it will start the socket IO server automatically, just like the runserver command.

I tried to implement those things by creating the Gunicorn service file, but it couldn't work.


Description=SocketIO server



ExecStart=/home/ubuntu/crypto-trading-bot/venv/bin/python3 server >> /home/ubuntu/crypto-trading-bot/socketIO.log 2>&1


I am new to server-side stuff, so any help will be good.


Back to Top