redmine init script

From WebHostingNeeds.com
Jump to: navigation, search

Create user redmine, set permissions

useradd redmine
chown -R redmine:redmine /home/redmine
cd /home/redmine
chmod -R 777 files log tmp
vi /etc/init.d/redmine

Add

[[email protected] config]# cat /etc/init.d/redmine
#!/bin/sh
#
# Startup script for redmine (redhad flavour)
#
# chkconfig: 345 85 15
# description: redmine project manager
# processname: redmine
# pidfile: /var/run/redmine.pid

# Source function library.
. /etc/rc.d/init.d/functions

program="redmine"
port="3000"
server="webrick" # webrick|thin
other_opts="-d"

program_home="/home/${program}/"
[ -d ${program_home} ] || exit 0
PIDFILE="/var/run/${program}.pid"
LOCKFILE="/var/lock/subsys/${program}"

# See how we were called.
case "$1" in
  start)
        echo -n "Starting ${program} ..."
        #### Commands to start the process running
        cd ${program_home}
        # -d: detach
        # -e: environment
        # -p: port
        /bin/su - redmine -c "/usr/local/bin/ruby script/rails server ${server} -e production -p ${port} ${other_opts}"
        sleep 1
        echo `pgrep -f  "ruby script/rails server ${server} -e production -p ${port} ${other_opts}"` > ${PIDFILE}
        touch ${LOCKFILE}
        echo
        ;;
  stop)
        echo -n "Shutting down ${program} ..."
        killproc ${program}
        echo
        rm -f ${LOCKFILE}
        rm -f ${PIDFILE}
        ;;
  status)
        status ${program}
        ;;
  restart)
        $0 stop
        $0 start
        ;;
  *)
        echo "Usage: $0 {start|stop|restart|status}"
        exit 1
esac

exit 0


[[email protected] config]#

make it executable

chmod 755 /etc/init.d/redmine

Set it to start on boot

chkconfig redmine on

Usage

[email protected] [~]# service redmine stop
Shutting down redmine ...                                  [  OK  ]
[email protected] [~]# service redmine start
Starting redmine ...=> Booting WEBrick
=> Rails 2.3.5 application starting on http://0.0.0.0:3000

[email protected] [~]# service redmine status
redmine (pid  28870) is running...
[email protected] [~]# service redmine restart
Shutting down redmine ...                                  [  OK  ]
Starting redmine ...=> Booting WEBrick
=> Rails 2.3.5 application starting on http://0.0.0.0:3000

[email protected] [~]#



redmine