NETB362
Daemons
Zlatin Stanimirov, F64571
Table of contents:
- Downloads
- Creating half daemons
- Daemonizing in the source code
- Daemonizing in initialization
- Cron 101
- Tasks
There are code listings to help you get started. You need root privileges to install 2 packages
Downloads:
You may download a small perl script which can be used as a daemon here: https://gist.github.com/IamBc/940820c33b79b9225f55
Perl
- Is the only scripting language installed in all *nix systems
- Favored amongst system administrators
Run the source code by typing: perl <file name>.pl in a terminal window.
Daemonize by hand
- Redirect STDIN, STDOUT and STDERR
- Run in background
There are a few things which are easy to do by hand.
You can use the script on the previous slide or make your own.
Daemonize with nohup
What you get:
- The program may continue to run if you have exited the terminal.
What you don't get:
- Tasks aren't ran in bg automatically
- You still need to redirect things
Daemonize in the source code
Your programming language needs to support it. Usually it doesn't by default, but there are a lot of modules. Here are some examples:
- Go https://github.com/sevlyar/go-daemon
- perl http://search.cpan.org/dist/Proc-Daemon/lib/Proc/Daemon.pod
- ruby emons.rubyforge.org/Daemons.html
- C http://stackoverflow.com/questions/17954432/creating-a-daemon-in-linux
Case study
I suggest to daemonize the script in the beginning of the slides with the module Proc::Daemon, although feel free to do it in any language you like :)
To install the perl library, you need to install the following package with a package manager of your choice:
libproc-daemon-perl
Daemonize in initialization
We are going to use daemonize.
To install run sudo apt-get install daemon
Daemonize a script by your choice
Cron 101
- Daemon that does periodic jobs
- For more info type man cron in a terminal
- Turn a script to a cron job
Questions ?
NETB362
By Zlatin Stanimirov
NETB362
- 785