Best practices, Wt app as a daemon/service on Linux?
Added by Jim Fred over 11 years ago
I'm looking for suggestions and best practices to setup a Wt app as a daemon or service on Linux Mint/Debian. This page describes several steps to daemonize a process: [[[http://www-theorie.physik.unizh.ch/\~dpotter/howto/daemonize]]] which is a little more involved than simply starting an app in an initd script. Other people using Wt on Linux would probably have useful suggestions.
Thanks!
Replies (5)
RE: Best practices, Wt app as a daemon/service on Linux? - Added by Plug Gulp over 11 years ago
@Jim Fred
"This page describes several steps to daemonize a process: [[[http://www-theorie.physik.unizh.ch/\~dpotter/howto/daemonize]]] which is a little more involved..."
Why not use the system call?:
int daemon(int nochdir, int noclose);
HTH,
~Plug
RE: Best practices, Wt app as a daemon/service on Linux? - Added by Jim Fred over 11 years ago
Using the daemon call would be easier than re-inventing the wheel.
A command-line parameter to enable/disable the daemon call would probably be useful for dev/debug purposes.
Then, to auto-start, I suppose I'd just add a init script. But, then would the daemon call really be necessary?
RE: Best practices, Wt app as a daemon/service on Linux? - Added by Jim Fred over 11 years ago
It looks like init.d is being replaced on many Linux distros with upstart so I tried an upstart script to start my Wt app with no daemon system calls. The script looks like this:
description "MyWtApp"
author "author"
# Upstart auto-start file. This file goes in /etc/init/MyWtApp.conf
# http://askubuntu.com/a/97770/74150, http://upstart.ubuntu.com/cookbook/
start on (local-filesystems and net-device-up IFACE!=lo)
stop on runlevel [!2345]
# Keep service running
respawn
# Run as 'user'
setuid user
setgid user
chdir /MyWtAppDir
exec /MyWtAppDir/MyWtApp
Then the service is started and stopped using...
sudo start MyWtApp
sudo stop MyWtApp
...and the output gets piped to
/var/log/upstart/MyWtApp.log
RE: Best practices, Wt app as a daemon/service on Linux? - Added by Koen Deforche over 11 years ago
Hey,
We usually use monitoring software like 'monit' to start the Wt server. See http://rimuhosting.com/knowledgebase/applications/monit-service-monitoring for an introduction to monit.
Better safe than sorry!
Regards,
koen
RE: Best practices, Wt app as a daemon/service on Linux? - Added by Pau Garcia i Quiles over 11 years ago
Take a look at the README.Debian included in Debian and its derivatives:
(start from "HOW TO START/STOP WT WEBAPPS")