Create custom service to auto start commands on boot

There are many solutions to automatically execute shell commands during the start-up process. My favorite is using services.

So we are going to create a small script in /etc/init.d/ and use chkconfig to auto start it on boot. We call the service “starter”!

vi /etc/init.d/starter

And add the following code to starter:

#!/bin/bash
# chkconfig: 345 99 10
# description: starting some commands at boot
#
case "$1" in
 'start')
	/usr/local/bin/searchd
	python /opt/deploy/main.py
	echo "started" >> /home/user/service.track
	;;
 'stop')
	killall searchd
	killall python
	;;
esac

And finally set permissions and configure the chkconfig:

chmod +x /etc/init.d/starter
chkconfig starter on
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s