Yaping's Weblog

April 13, 2009

Add Linux service manually

Filed under: Unix/Linux — Yaping @ 3:01 pm

Here I demo how to add commands to system service on Linux.

Assume I have one shell script named collectd, like the following:

# Startup script for the collectd Server
# chkconfig: – 50 50
# description: collectd gathers statistics about the system it is running on and stores this information
# processname: collectd
# pidfile: /opt/collectd/var/run/collectd.pid
# config:  /opt/collectd/etc/collectd.conf
# command: /opt/collectd/sbin/collectd

case “$1” in
# Starts the collectd deamon
echo “Starting collectd”

# stops the daemon bt cat’ing the pidfile
echo “stopping collectd”
kill -9 `cat $PID_FILE`

## Stop the service regardless of whether it was
## running or not, start it again.
echo “Restarting collectd”
$0 stop
$0 start

# reloads the config file by sending HUP
echo “Reloading config”
kill -HUP `cat $PID_FILE`

echo “Usage: collectd (start|stop|restart|reload)”
exit 1


Then I copy this script to /etc/init.d/collectd and perform the below commands.

chkconfig –add collectd
chkconfig –level 2345 collectd on
service collectd start

Leave a Comment »

No comments yet.

RSS feed for comments on this post. TrackBack URI

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 )

Connecting to %s

Create a free website or blog at WordPress.com.

%d bloggers like this: