... because from time to time I'm a web developer, too
About me
Projects
Contact
Links

Script for start/stop/restart pylons project

September 16, 2009 | frameworks, linux, python
author: Karol Zielinski | comments: 0 | views: 1016
Tags: , , ,

It is always a good idea to run your python projects via paster + nginx. Some time ago I wrote about building environment for pylons projects on ubuntu, so that shouldn’t be a problem. Now… let create some kind of script to start, stop and restart our application.

so…

sudo touch /etc/init.d/our_project
sudo chown +x /etc/init.d/out_project

and now…

sudo vim /etc/init.d/our_project

and put some code in it:


#!/bin/bash -e

PYTHON_ENV=/mnt/python2.5-env/our_project # our pve (python environment)
APP_NAME=our_project # application name
APP_PATH=/mnt/our_project # path to our project
INI_FILE=production.ini # ini file, that we want to use

case "$1" in
  start)
    echo -e "\nConfiguration in use: ${APP_PATH}/${INI_FILE}\n\nStarting ${APP_NAME}..."
    cd ${APP_PATH}
    ${PYTHON_ENV}/bin/paster serve --daemon --pid-file=/var/run/${APP_NAME}.pid --log-file=/var/log/${APP_NAME}.log ${APP_PATH}/${INI_FILE} start
    ;;
  stop)
    echo -e "\nConfiguration in use: ${APP_PATH}/${INI_FILE}\n\nStopping ${APP_NAME}..."
    cd ${APP_PATH}
    ${PYTHON_ENV}/bin/paster serve --daemon --pid-file=/var/run/${APP_NAME}.pid --log-file=/var/log/${APP_NAME}.log ${APP_PATH}/${INI_FILE} stop
    ;;
  restart)
    echo -e "\nConfiguration in use: ${APP_PATH}/${INI_FILE}\n\nRestarting ${APP_NAME}..."
    cd ${APP_PATH}
    ${PYTHON_ENV}/bin/paster serve --daemon --pid-file=/var/run/${APP_NAME}.pid --log-file=/var/log/${APP_NAME}.log ${APP_PATH}/${INI_FILE} restart
    ;;
  *)
    echo "Usage: $0 {start|stop|restart}"
    exit 1
esac

and now run an application:

/etc/init.d/our_project start

logs should be in /var/log/our_project.log, pid file should be in /var/run/our_project.pid.

That’s all.

Bookmark and Share
Post Script for start/stop/restart pylons project to develway Post Script for start/stop/restart pylons project to Delicious Post Script for start/stop/restart pylons project to Digg Post Script for start/stop/restart pylons project to Facebook Post Script for start/stop/restart pylons project to Reddit Post Script for start/stop/restart pylons project to StumbleUpon

Related news and resources

Write a comment

Karol Zielinski :: Just a tech stuff Hello, I'm Karol Zielinski, internet evangelist, an entrepreneur, project manager and a web developer from Gdynia, Poland. I like creative design, good advertisement, social media and all kind of stuff around the web.

Most popular posts

Much more links

Karol Zielinski    |   contact me
Gdynia, Poland
RSS - Just a tech stuff - python, java blog - web development blog Karol Zielinski on twitter Karol Zielinski on LinkedIn Karol Zielinski on facebook Karol Zielinski on delicious Karol Zielinski on digg Karol Zielinski on flickr Karol Zielinski on stumbleupon Karol Zielinski on technorati