Creating a non-root startup script [CentOS5]

Just wanted to know the correct process for adding a startup script to a CentOS 5 server.

I believe you create an +x file and stick it in /etc/init.d, but I’m not sure if you have to run chkconfig or some other command after that or not.

Also, would want to run this as a non root user.

Here is a basic template script I found. Would this work?

http://spiralbound.net/2007/07/23/example-linux-init-script/

#### SNIP ####

#! /bin/sh
# Basic support for IRIX style chkconfig
###
# chkconfig: 235 98 55
# description: Manages the services you are controlling with the chkconfig command
###

case "$1" in
  start)
        echo -n "Starting new-service"
        #To run it as root:
        /path/to/command/to/start/new-service
        #Or to run it as some other user:
        /bin/su - username -c /path/to/command/to/start/new-service
        echo "."
        ;;
  stop)
        echo -n "Stopping new-service"
        #To run it as root:
        /path/to/command/to/stop/new-service
        #Or to run it as some other user:
        /bin/su - username -c /path/to/command/to/stop/new-service
        echo "."
        ;;

  *)
        echo "Usage: /sbin/service new-service {start|stop}"
        exit 1
esac

exit 0


#### /SNIP ####

Justin, if the script supports the chkconfig (as it seems in your post) you should put it in /etc/init.d, make it executable and add it with the chkconfig command (don’t believe it’s changed in v5):

chkconfig --add new-service
chkconfig new-service on
service new-service start

You can look at the services configured and its status with:

chkconfig --list

Since you can specify:
“/bin/su - username -c /path/to/command/to/start/new-service”
you should be able to start the script as another user (i.e jboss, tomcat etc).

Thanks! Seems to have worked great. Is there another setting to make this run at startup or was that what the chkconfig new-service on did?

Thanks again

Hi,
“chkconfig new-service on” sets the script on at default levels on boot.

If you have a script not controlled by init.d you can put it in /etc/rc.local

cheers
-tsl-