Run Redmine as local service at startup on Linux


Open a console on the linux machine where your Redmine installation is and create the init script by typing:

touch /etc/init.d/redmine.sh

If you haven’t write permissions on “/etc/init.d/” dir, please switch to root user, typing:

su –

and redo the previous commands . Otherwise (for Ubuntu users) use “sudo”:

sudo touch /etc/init.d/redmine.sh

Now open the init file (in case with “sudo”) with a text editor (e.g. vim):

vim /etc/init.d/redmine.sh

Then write the following lines:

#!/bin/bash
DIR=/var/www/my_redmine/
IP=192.168.1.100
RUN_ENV=production
PORT=3001

# Start Redmine in daemon mode
start(){
cd $DIR
#ruby script/server -d -e $RUN_ENV -b $IP -p $PORT
rails server -d -e $RUN_ENV -b $IP -p $PORT
}

# Stop Redmine daemon
stop(){
RUBYPID=`ps aux | grep “rails server -d -e $RUN_ENV -b $IP -p $PORT” | grep -v grep | awk ‘{print $2}’`
if [ “x$RUBYPID” != “x” ]; then
kill -2 $RUBYPID
fi
}

# Check if Redmine is running
status(){
RUBYPID=`ps aux | grep “rails server -d -e $RUN_ENV -b $IP -p $PORT” | grep -v grep | awk ‘{print $2}’`
if [ “x$RUBYPID” = “x” ]; then
echo “* Redmine is not running”
else
echo “* Redmine is running”
fi
}

case “$1” in
start)
start
;;
stop)
stop
;;
status)
status
;;
restart|force-reload)
stop
start
;;
*)
echo “Usage: $0 {start|stop|restart|force-reload|status}”
exit 1
esac

In this example our redmine installation dir is “/var/www/my_redmine/”, the Redmine service will be available on ip address:port 192.168.1.100:3001 with the “production” environment. Change them to match your configuration.
For old Redmine versions, use the “ruby script/server” command instead the “rails server”, in “start)” section

Now update system services list by typing (in case with “sudo”):

update-rc.d redmine defaults

REMEMBER. Every time the script change, you have to rerun the above command.

Now Redmine service will start at machine boot and you can start and stop the service from cli.

IMPORTANT. Consider that the above procedure is not suitable for production environment. See redmine documents for how to setup redmine service in other ways (e.g. behind an apache/nginx web server).

Leave a comment

Your email address will not be published. Required fields are marked *