Creating a daemon in Linux is as simple as creating a BASH/SH script in /etc/init.d. BASH is NOT part of this short tutorial so I won't go into the details of the script itself.
To create a daemon create a script in /etc/init.d. To simplify the creation you can copy the skeleton script in /etc/init.d/skeleton. Your script need to handle the following daemon commands:
start
stop
restart/reload
force-reload
status
cp /etc/init.d/skeleton /etc/init.d/daemonName
sudo chmod 775 /etc/init.d/daemonName
To enable the daemon to start at boot:
update-rc.d daemonName defaults 97 03
http://manpages.ubuntu.com/manpages/hardy/man8/update-rc.d.8.html
To disable the daemon from starting at boot:
update-rc.d -f daemonName remove
Great tutorial...
ReplyDeletesudo chown 775 /etc/init.d/daemonName
Should this be sudo chmod 775 not chown?
Yes, you're right. I already updated the post. Thanks.
DeleteI'm still struggling to figure out what further is required to create the service. I followed your tutorial and enabled the daemon. However when I do the service "servicename" start, nothing happens. What am I missing?
ReplyDeleteThe command "update-rc.d daemonName defaults" should enable the service. Then "sudo service daemonName start" should start the service.
DeleteMaybe you're mispelling the service name?
Also the service should implement "start" "stop" "restart" command paraters - example bash script is in /etc/init.d/skeleton
It's worth noting that with upstart in newer versions of Ubuntu (including 12.04) you just need to create the appropriate config file in /etc/init/ (note NOT /etc/init.d). This will result in the service that you can start using service xxx start and the config file is used to start the service automatically on boot so no need for update-rc.d.
ReplyDelete+1: I think upstart is a neater/cleaner way of creating services. See a tutorial on it here: https://help.ubuntu.com/community/UbuntuBootupHowto
Delete-1. you are mixing up services and daemons.og descThe blog describes creation of a service. Deamon is something different.
ReplyDeleteWhat?? A daemon is the equivalent of a Windows Service. Different names but same intent. A daemon IS a Unix/Linux service.
Deletethanks a lot for the tutorial!
ReplyDeleteMany thanks for the manual. Short and correct
ReplyDeleteoakley sunglasses
ReplyDeletemichael kors outlet online sale
true religion shorts
designer handbags
ralph lauren outlet
coach outlet
jordan 8
kobe 9
ray ban sunglasses outlet
kevin durant shoes 8
nike air max
coach outlet online
toms shoes outlet online
adidas shoes
michael kors outlet
celine handbags
retro jordans
abercrombie & fitch
christian louboutin outlet
jordan 4 toro
ray ban sunglasses
ghd flat iron
ray bans
nike roshe run
gucci handbags
true religion
louboutin pas cher
celine outlet
christian louboutin shoes
toms outlet
michael kors handbags
louis vuitton
jordans
louis vuitton outlet
ray ban sunglasses
hollister clothing
michael kors
jordan retro
burberry outlet
nike blazers
2016.6.28haungqin
how can I do something like this but if I want to run a .py file?
ReplyDeleteHi so where should i place the custom script.
ReplyDeletesupreme hoodie
ReplyDeletegolden goose
golden goose outlet
yeezy supply
golden goose
golden goose
supreme clothing
goyard handbags
moncler jackets
goyard handbags