The django command is a command that you run with'python manage.py ~'. By default, many useful commands such as shell are provided. Although not explained in detail here, it is possible to create custom commands. And, the custom command etc. are often run as a batch such as crontab, but for some reason I will try not to double start.
custom_command.py
import sys
import commands
from django.core.management.base import BaseCommand
def is_process_exist(process_name):
"""
Returns True if this process is running
"""
output = commands.getoutput("ps -ef | grep '%s' | grep -v grep | wc -l" % (process_name))
is_exist = int(output) >= 2
return is_exist
class Command(BaseCommand):
def handle(self, *args, **options):
#Double startup check
if is_process_exist(__name__.split('.')[-1]):
sys.exit('duplication!')
#The following processing ~
Recommended Posts