Create Centos 6.6 startup script

How to start a custom script/app on CentOs boot

Open a terminal and as root go to /etc/init.d/
Create the file here with whatever name you want, we will use gitlab as an example.

Copy and paste the code below into the file and change it as per your application requirements:

#!/bin/bash
#
# gitlab    GitLab Docker container 7.9
#
# chkconfig: 345 70 30
# description: GitLab Docker container 7.9
# processname: gitlab

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

RETVAL=0
prog=gitlab
dockerImgName="gitlab_app_79_new_local_2data"
LONGID=$(sudo docker inspect $dockerImgName | grep '"Id"' | sed 's/^.*: *"\([^"]*\)".*$/\1/')
shortId=${LONGID:0:12}
start() {
	echo -n "Starting $prog with container ID: $shortId: "
        sudo docker start $shortId
        return $RETVAL
}

stop() {
        echo -n "Shutting down $prog: "
        sudo docker stop $shortId
        return $RETVAL
}

status() {
	echo -n "Checking $prog status: "
        containersRunning=$(docker ps | grep $shortId | wc -l)
        if [ "$containersRunning" -gt "0" ]; then
                echo -n "$prog has a running container";
        else
            	echo -n "$prod has no running container";
        fi
	return $RETVAL
}

case "$1" in
    start)
	start
	;;
    stop)
	stop
	;;
    status)
	status
	;;
    restart)
	stop
	start
	;;
    *)
      	echo "Usage: $prog {start|stop|status|restart}"
        exit 1
	;;
esac
exit $RETVAL

now we need to let centos know about the new script so we run:

chkconfig --add gitlab

And finally to see if everything is okay we do

chkconfig --list

Our new program should show up as

gitlab         	0:off	1:off	2:off	3:on	4:on	5:on	6:off