Posted By

stvnz on 07/21/08


Tagged

Shell fastcgi django fcgi nginx


Versions (?)

simple init.d script for django using fastcgi


 / Published in: Bash
 

  1. #!/bin/sh
  2. #
  3. # chkconfig: 345 85 15
  4. # description: FastCGI server for Django
  5.  
  6.  
  7. # Source function library
  8. . /etc/rc.d/init.d/functions
  9.  
  10. # Source networking configuration.
  11. . /etc/sysconfig/network
  12.  
  13. # Check that networking is up.
  14. [ "${NETWORKING}" = "no" ] && exit 0
  15.  
  16. PROJ=myproject # Django project name
  17. PROJSPATH=/home/user/www # The folder Django project is in
  18. SOCKSPATH=/tmp # Where you put UNIX socket file
  19. PIDSPATH=/var/run # Where you put .pid file
  20. RUNAS=root # Set a different user to run the FastCGI server
  21.  
  22. SRVNAME=fcgi-$PROJ # Process name
  23.  
  24. # Maximum requests for a child to service before expiring
  25. #MAXREQ=
  26. # Spawning method - prefork or threaded
  27. #METHOD=
  28. # Maximum number of children to have idle
  29. #MAXSPARE=
  30. # Minimum number of children to have idle
  31. #MINSPARE=
  32. # Maximum number of children to spawn
  33. #MAXCHILDREN=
  34.  
  35. start () {
  36. # Check if the service is already running?
  37. if [ ! -f $PIDSPATH/$SRVNAME.pid ]; then
  38. echo -n $"Starting $SRVNAME..."
  39. daemon --user $RUNAS $PROJSPATH/$PROJ/manage.py runfcgi pidfile=$PIDSPATH/$SRVNAME.pid \
  40. socket=$SOCKSPATH/$SRVNAME.sock \
  41. ${MAXREQ:+maxrequests=$MAXREQ} \
  42. ${METHOD:+method=$METHOD} \
  43. ${MAXSPARE:+maxspare=$MAXSPARE} \
  44. ${MINSPARE:+minspare=$MINSPARE} \
  45. ${MAXCHILDREN:+maxchildren=$MAXCHILDREN} \
  46. ${DAEMONISE:+damonize=True}
  47. echo
  48. chmod 777 $SOCKSPATH/$SRVNAME.sock
  49. RETVAL=$?
  50. else
  51. echo $"$SRVNAME is already running."
  52. fi
  53. }
  54.  
  55. stop() {
  56. # Stop daemons.
  57. if [ -f $PIDSPATH/$SRVNAME.pid ]; then
  58. echo -n $"Stopping $SRVNAME..."
  59. killproc -p "$PIDSPATH/$SRVNAME.pid" -d 60 $SRVNAME
  60. echo
  61. # Delete pidfile only when Django was called successfully
  62. if [ $? -eq 0 ]; then
  63. rm -f $PIDSPATH/$SRVNAME.pid "$SRVNAME.pid" >/dev/null 2>&1
  64. fi
  65. else
  66. echo $"$SRVNAME is NOT running."
  67. fi
  68.  
  69. }
  70.  
  71. RETVAL=0
  72.  
  73. case "$1" in
  74. start)
  75. start
  76. ;;
  77. stop)
  78. stop
  79. ;;
  80. status)
  81. status -p "$PIDSPATH/$SRVNAME.pid" $SRVNAME
  82. RETVAL=$?
  83. ;;
  84. restart)
  85. stop
  86. start
  87. ;;
  88. *)
  89. echo $"Usage: $0 {start|stop|restart|status}"
  90. exit 3
  91. ;;
  92. esac
  93.  
  94. exit $RETVAL

Report this snippet  

You need to login to post a comment.