Linux – How to create Daemon Service

>Installation Part
1-Create a directory called /package
[root@testserver ~]# mkdir /package
2- Download Daemon tool on package directory
[root@testserver package]# wget -c
3-Download Daemon tools patch to avoid compile/svscan- “daemontools-0.76.errno.patch”
4) patch daemon tools-
(i) Go to ‘/package/admin/daemontools-0.76’ directory and run the following command
[root@testserver daemontools-0.76]# patch -p1 < ../daemontools-0.76.errno.patch (ii) Installing Daemon Tools – Go to ‘/package/admin/daemontools-0.76’ directory and run the following command [root@testserver daemontools-0.76]# package/install Implementation Part

1-Make sure /service/ directory is created with 755 permission
2- Create a folder where you would like to configure your daemon script linked with /service directory like /var/svc.d
3-Create a folder which indicates your Daemon service i.e /var/svc.d/nagios_check
4- create two folder and file as below
run ( file, permission must be 755 in order to execute )
log ( Folder )
env ( folder )
Further create a ‘run’ script inside ‘log’ directory to supervise daemon log with timestamp
The structure would like this.
[root@testserver svc.d]# tree

`– nagios_check
|– env
|– log
| `– run
`– run
5- create run file inside /var/svc.d/nagios-check like this
exec 2>&1
echo “*** Starting service nagios_check…”
exec envdir ./env /root/admin/
Note – This will run /root/admin/ as a deamon
6-create run file inside /var/svc/.d/nagios-check/log like this.
exec multilog t ./main

Note –‘t’ feature with multilog with use for timpstamp of log files.
7- now create the softlink with /service folder to get daemon activiated.
i)-Go to /service directory and run the following commands
[root@testserver service]# ln -s /var/svc.d/nagios_check nagios_check
ii)- run the svc –t command to get /service recognized new deamon
iii) you can use svstat /service/* to see the daemon status like
[root@testserver ~]# svstat /service/*
/service/nagios-check: up (pid 6118) 1 seconds

Note- you can use ‘env’ directory to declare ENVIRNOMENT VARIABLE used inside script like /root/admin/ for daemon purpose.


3 thoughts on “Linux – How to create Daemon Service

  1. Jacoby November 17, 2011 at 11:07 pm Reply

    Hahahaha. I’m not too brihgt today. Great post!

    • Roseanna December 1, 2011 at 5:55 pm Reply

      Ppl like you get all the brnais. I just get to say thanks for he answer.

    • Raynoch December 3, 2011 at 7:16 am Reply

      Stands back from the keyboard in amaezmnet! Thanks!

Leave a Reply

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

You are commenting using your 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

%d bloggers like this: