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.


[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.


# run this as the rhodecode user!                                                                         

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


# rhodecode-server RhodeCode server instance                                                                                                                                                                                                 

# PATH=/sbin:/usr/sbin:/bin:/usr/bin                                                                                                                                                                                                         


. /etc/init.d/functions                                                                                                                                                                                                                      


remove_pid () {                                                                                                                                                                                                                              
    rm -f ${PID_FILE}                                                                                                                                                                                                                        

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

stop_rhodecode () {                                                                                                                                                                                                                          
    killproc -p $PID_FILE                                                                                                                                                                                                                    
    rm -f $LOCK_FILE                                                                                                                                                                                                                         
    rm -f $PID_FILE                                                                                                                                                                                                                          
    return $RETVAL                                                                                                                                                                                                                           

restart_rhodecode () {                                                                                                                                                                                                                       

case "$1" in                                                                                                                                                                                                                                 
    echo -n $"Starting $DESC: "                                                                                                                                                                                                              
    echo -n $"Stopping $DESC: "                                                                                                                                                                                                              
    echo -n $"Restarting $DESC: "                                                                                                                                                                                                            
    echo $"Usage: $0 {start|stop|restart}"                                                                                                                                                                                                   

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?

  • @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. 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? 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). 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
  • daemon --pidfile only specifies where the pid file is. functions in CentOS doesn't seem to have the required --make-pidfile option
    – KCD
    Mar 16 '15 at 3:19

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.

  • 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. 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. 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:

start_rhodecode () {                                                                                                                                                                                                                         
    daemon --user $USER --name $NAME $CMD                                                                                                                                                                                        
    return $RETVAL                                                                                                                                                                                                                           

stop_rhodecode () {                                                                                                                                                                                                                          
    daemon --name $NAME --stop                                                                                                                                                           
    return $RETVAL                                                                                                                                                                                                                           
  • There is no option like '--stop' or --name in Centos 6.5
    – MariuszS
    Apr 4 '14 at 18:36
  • There is no --name or --stop in Centos 5 either. Jul 18 '14 at 20:14

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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