Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

EDIT: For some reason half of my post got truncated, not sure what happened. I will update soon and will post that it is updated here at the top.

EDIT: I have updated the post again, sorry for the incomplete question.

EDIT (8:55PM EST 10/10/2011): I updated /srv/rhodecode/start.sh like Steven suggested, still no joy. It continues to hang like so:

[lpeabody@vcs rhodecode]$ sudo /etc/init.d/rhodecode-server start
Starting rhodecode-server:

I've updated the scripts below to show the changes.


I've never written a shell or a bash script in my life. I'm trying to get RhodeCode installed on CentOS, and there are init scripts for Debian and Gentoo, but not for RedHat/CentOS which is insane to me. So I need to write one because our server environment is restricted to running CentOS 5. The source for the project can be found at Bitbucket here.

The idea is to run RhodeCode w/ Celery and RabbitMQ. It is all written in Python and I have the environment in it's own separate virtual container using virtualenv. I got the idea for the shell script here.

I've created a system user named rhodecode and created the directory /var/run/rhodecode and it's owned by rhodecode. I've also created /var/www/rhodecode where production.ini resides, as well as /srv/rhodecode/start.sh, all of which is owned by rhodecode.

Permissions:

[lpeabody@vcs run]$ ll -a /var/run/rhodecode
total 12
drwxr-xr-x  2 rhodecode rhodecode 4096 Oct 10 15:57 .
drwxr-xr-x 21 root      root      4096 Oct 10 16:07 ..

[lpeabody@vcs run]$ ll -a /var/www/rhodecode
total 76
drwxr-xr-x  4 rhodecode rhodecode  4096 Oct 10 16:47 .
drwxr-xr-x 11 root      root       4096 Oct  5 14:54 ..
drwxrwxr-x  3 rhodecode rhodecode  4096 Oct  5 19:40 data
-rw-r--r--  1 rhodecode rhodecode     0 Oct 10 16:41 debug.log
-rw-r--r--  1 rhodecode rhodecode  1466 Oct 10 16:41 error.log
-rw-rw-r--  1 rhodecode rhodecode  6000 Oct  6 15:27 production.ini
drwxrwxr-x  2 rhodecode rhodecode  4096 Oct  5 18:37 repos
-rw-r--r--  1 rhodecode rhodecode 44032 Oct  5 19:16 rhodecode.db

[lpeabody@vcs run]$ ll -a /srv/rhodecode/
total 16
drwxr-xr-x 2 rhodecode rhodecode 4096 Oct 10 16:40 .
drwxr-xr-x 4 root      root      4096 Oct  7 14:40 ..
-rwxr-xr-x 1 rhodecode rhodecode  277 Oct 10 16:40 start.sh

I have the following bash and shell scripts.

/srv/rhodecode/start.sh

#!/bin/bash                                                                                               
# run this as the rhodecode user!                                                                         

WDIR=/var/www/rhodecode                                                                                   
VIRTUALENV_DIR=/opt/python_virtualenvironments/rhodecode-venv                                             
export PYTHON_EGG_CACHE=/tmp/.python-eggs                                                                 

source $VIRTUALENV_DIR/bin/activate                                                                       

cd $WDIR                                                                                                  
exec paster serve production.ini 1> debug.log 2> error.log

/etc/init.d/rhodecode-server

#!/bin/sh                                                                                                                                                                                                                                    
#                                                                                                                                                                                                                                            
# rhodecode-server RhodeCode server instance                                                                                                                                                                                                 
#                                                                                                                                                                                                                                            
#                                                                                                                                                                                                                                            

# PATH=/sbin:/usr/sbin:/bin:/usr/bin                                                                                                                                                                                                         
NAME=rhodecode-server                                                                                                                                                                                                                        
DESC=rhodecode-server                                                                                                                                                                                                                        
USER=rhodecode                                                                                                                                                                                                                               
PID_FILE=/var/run/rhodecode/pid                                                                                                                                                                                                              
CMD=/srv/rhodecode/start.sh                                                                                                                                                                                                                  

LOCK_FILE=/var/lock/subsys/$NAME                                                                                                                                                                                                             

. /etc/init.d/functions                                                                                                                                                                                                                      

RETVAL=0                                                                                                                                                                                                                                     

remove_pid () {                                                                                                                                                                                                                              
    rm -f ${PID_FILE}                                                                                                                                                                                                                        
}                                                                                                                                                                                                                                            

start_rhodecode () {                                                                                                                                                                                                                         
    daemon --user $USER --pidfile $PID_FILE $CMD                                                                                                                                                                                        
    RETVAL=$?                                                                                                                                                                                                                                
    [ $RETVAL -eq 0 ] && touch $LOCK_FILE                                                                                                                                                                                                    
    return $RETVAL                                                                                                                                                                                                                           
}                                                                                                                                                                                                                                            

stop_rhodecode () {                                                                                                                                                                                                                          
    killproc -p $PID_FILE                                                                                                                                                                                                                    
    RETVAL=&?                                                                                                                                                                                                                                
    rm -f $LOCK_FILE                                                                                                                                                                                                                         
    rm -f $PID_FILE                                                                                                                                                                                                                          
    return $RETVAL                                                                                                                                                                                                                           
}                                                                                                                                                                                                                                            

restart_rhodecode () {                                                                                                                                                                                                                       
    stop_rhodecode                                                                                                                                                                                                                           
    start_rhodecode                                                                                                                                                                                                                          
    RETVAL=$?                                                                                                                                                                                                                                
}                                                                                                                                                                                                                                            

case "$1" in                                                                                                                                                                                                                                 
  start)                                                                                                                                                                                                                                     
    echo -n $"Starting $DESC: "                                                                                                                                                                                                              
    start_rhodecode                                                                                                                                                                                                                          
    echo                                                                                                                                                                                                                                     
    ;;                                                                                                                                                                                                                                       
  stop)                                                                                                                                                                                                                                      
    echo -n $"Stopping $DESC: "                                                                                                                                                                                                              
    stop_rhodecode                                                                                                                                                                                                                           
    echo                                                                                                                                                                                                                                     
    ;;                                                                                                                                                                                                                                       
  restart)                                                                                                                                                                                                                                   
    echo -n $"Restarting $DESC: "                                                                                                                                                                                                            
    restart_rhodecode                                                                                                                                                                                                                        
    echo                                                                                                                                                                                                                                     
    ;;
  *)                                                                                                                                                                                                                                         
    echo $"Usage: $0 {start|stop|restart}"                                                                                                                                                                                                   
    RETVAL=1                                                                                                                                                                                                                                 
    ;;                                                                                                                                                                                                                                       
esac                                                                                                                                                                                                                                         

exit $RETVAL

When I run sudo /etc/init.d/rhodecode-server start and then run ps -aux | grep paster, I can see the paster serve production.ini command from /srv/rhodecode/start.sh went through and is running with rhodecode's user id (102).

102       5222  0.7  7.8 144300 80988 ?        Sl   16:08   0:00 /opt/python_virtualenvironments/rhodecode-venv/bin/python /opt/python_virtualenvironments/rhodecode-venv/bin/paster serve production.ini

However, no pid file is created, so I can't stop the server from my init script. I'm not sure why daemon isn't creating the pidfile. The path to the pid file is valid and the permissions are correct. Thoughts?

share|improve this question
    
@mailq I updated my question. For some reason half the post had been truncated... The question is regarding why daemon doesn't create a pid file. –  Lester Peabody Oct 10 '11 at 20:14
    
Are the permission on /var/run/rhodecode/pid correct for the user this is running as? For that matter, is the that variable correct or should it be /var/run/rhodecode.pid? –  John Gardeniers Oct 10 '11 at 20:41
    
@John I've added a permissions section to my post to list the permissions on all directories and files involved in this process (to my knowledge). –  Lester Peabody Oct 10 '11 at 20:49
    
Please enclose your debug info sh -x /etc/init.d/rhodecode-server start? –  quanta Oct 11 '11 at 4:54

2 Answers 2

I think your problem is in /srv/rhodecode/start.sh. It is currently starting paster as a separate background process and then immediately exiting. This poses a problem for your init script, which expects start.sh to itself be the long-running daemon process to be managed.

Thus, try changing the last line of /srv/rhodecode/start.sh to read as follows:

exec paster serve production.ini 1> debug.log 2> error.log

Using exec makes start.sh become paster, which is then daemonized by the daemon command in the init script.

share|improve this answer
    
In my mind I knew this was exactly the problem, I just had no clue what to search for. I tried paster both with and without the & and obviously both times I had no results. Unfortunately I just got home from the office, I will implement this first thing tomorrow morning. –  Lester Peabody Oct 11 '11 at 0:33
    
I actually just SSHd in and tried it and it didn't work either.. it continues to hang, I'll update my post. –  Lester Peabody Oct 11 '11 at 0:54

Do you have to specify the location? Could you use the --name option to give it a name? That will create the PID for you and clean it up when you're done. So it would look like:

$NAME="rhodecode"
start_rhodecode () {                                                                                                                                                                                                                         
    daemon --user $USER --name $NAME $CMD                                                                                                                                                                                        
    RETVAL=$?                                                                                                                                                                                                                                
    return $RETVAL                                                                                                                                                                                                                           
} 

stop_rhodecode () {                                                                                                                                                                                                                          
    daemon --name $NAME --stop                                                                                                                                                           
    RETVAL=&?                                                                                                                                                                                                                                                                                                         
    return $RETVAL                                                                                                                                                                                                                           
}     
share|improve this answer
    
There is no option like '--stop' or --name in Centos 6.5 –  MariuszS Apr 4 at 18:36
    
There is no --name or --stop in Centos 5 either. –  jcm Jul 18 at 20:14

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.