Archives
Tags
- General (18)
- Food (1)
- Cooking (1)
- Ruby (6)
- Rails (2)
- Svn (2)
- Linux (9)
- Git (1)
- Firefox (8)
- Porn (1)
- Freyja (1)
- Witchhammer (6)
- Music (1)
- Merb (3)
- Poetry (0)
- Bolverk (3)
- Sinatra (1)
- Discogs (1)
- Centos (1)
- Python (1)
- Whinging (2)
- Travel (2)
- Scheme (7)
- Lisp (8)
- Sicp (1)
- Rot13 (1)
- Czech (2)
- Metal (3)
- Passenger (1)
- Fun (5)
- Fractals (2)
- Plt (2)
- Clojure (1)
- Continuations (1)
- Javascript (1)
- Presentation (1)
Running Linux processes as Daemons
Running an arbitrary process, such as a Python script, on your Linux box as a daemon is really quite simple if you have the right tools.
In my case, I had a simple Python socket server that needed to run permanently. Simply running it in the background (Ctrl-z) is no good as it would die the moment I logged off!
Enter daemon, a really handy tool for solving this exact problem.
Installation is easy. On Debian-based distros, you can just install it directly form aptitude. On CentOS, which uses yum, I had to install it from source. But I ran into no problems there.
Once installed, getting things running was easy:
$ daemon -r --name=myserver python /full/path/to/myserver.py
The "r" flag tells daemon to respawn itself if the service is killed. I've given it a name so I can refer to it later. And the rest of the line is the actual command I want to run.
To test if the process is still running, you can look in ps or pgrep, but the best way to do it is to simply ask daemon personally:
$ daemon -v --name=myserver --running
The "v" flag is for verbosity (of coarse). The "running" flag tell daemon that I want to know if the process specified by "name" is still running. The output you receive is simple to interpret, e.g: "myserver is running with PID: 23324".
To finally kill the process at some point in the future, you can issue the following command:
$ daemon -v --name=myserver --stop
And this one should be rather self-explanatory by now. :)
I've only grazed the surface here. Just check out the man page for an idea of how much more you can do with this. Good luck, muchachos!