Quoting Michael Medin <[EMAIL PROTECTED]>:
> Hello,
>
> First off, I am a witty newbie so pardon me if I ask stupid questions.
>
> Anyways are there any info/samples on how to use the built in http server?
> I tried to look around a bit but it seemed all examples assumed the
> program was a "stupid demon" as they all did
> void main(void) {
> Wrun(...);
> }
>
> I need to start the server and continue with my own work and also be
> able to shut it down and what not when I want to.
> When I tried to do this (I copied the code from Wrun) it seemed to
> require me to include much of the "internal source code" of Witty and I
> started thinking there has to be a better way.
>
> What I want to do (sort of) is:
> void main(void) {
> ...
> server = new server(my,own,configuration);
> server.start();
> ...
> ...
> server.stop();
> ...
> ...
> server.start();
> ...
> ...
> server.exit();
> delete server;
> ...
> }
It's not clear to me if what you want to do is to keep your
application running but not serving HTTP requests, or to stop the
application, then restart it.
If the former, I don't know what to do. If the latter, read on.
If on Windows, you want your application to run as a service. You have
two options:
a) Complex but more powerful: use the Service Control Manager to
develop a true service. Read
http://msdn.microsoft.com/en-us/library/d56de412(VS.80).aspx
b) Develop a normal application and use INSTSRV.EXE from the Windows
Server Resource Kit to run it as a service. Read
http://support.microsoft.com/default.aspx?scid=kb;en-us;137890 (free
Resource Kit download:
http://www.microsoft.com/downloads/details.aspx?FamilyID=9D467A69-57FF-4AE7-96EE-B18C4790CFFD&displaylang=en
)
If on Linux, you have two options which are equivalent to what you
could do on Windows:
a) fork and make the 'init' process parent your daemon (this would
work on any other Unix, too)
b) Create an init script and use the LSB init functions. In
particular, you will be interested in start-stop-daemon. Here comes an
example of how I daemonize a toy webapp developed with Wt:
==========
#!/bin/sh
# /etc/init.d/pfsi
#
# Written by Pau Garcia i Quiles <[EMAIL PROTECTED]>
set -e
if [ ! -f /etc/arisnova/pfsi.conf ] ; then
exit 0
fi
DAEMON=/usr/wt/pfsi/pfsi.wt
NAME=pfsi.wt
test -x $DAEMON || exit 0
. /lib/lsb/init-functions
case "$1" in
start)
log_begin_msg "Starting PF Infrastructure server: $NAME"
[ -d /var/run/pfsi ] || mkdir -p /var/run/pfsi
start-stop-daemon --background -m --pidfile
/var/run/pfsi/pfsi.pid --exec $DAEMON -c www-data:www-data --start --
--docroot /usr/wt/pfsi --http-addr 0.0.0.0 --http-port 9000 &&
log_end_msg 0 || log_end_msg 1
;;
stop)
log_begin_msg "Stopping PF Infrastructure server: $NAME"
start-stop-daemon --stop --pidfile /var/run/pfsi/pfsi.pid
--oknodo --exec $DAEMON && log_end_msg 0 || log_end_msg 1
rm -f /var/run/pfsi/pfsi.pid
;;
restart)
$0 stop
$0 start
;;
reload|force-reload)
log_begin_msg "Reloading $NAME configuration files"
start-stop-daemon --stop --pidfile /var/run/pfsi/pfsi.pid
--signal 1 --exec $DAEMON && log_end_msg 0 || log_end_msg 1
;;
*)
log_success_msg "Usage: /etc/init.d/$NAME {start|stop|restart|reload}"
exit 1
;;
esac
exit 0
==========
Then use a different application to start and stop the daemon.
--
Pau Garcia i Quiles
http://www.elpauer.org
(Due to my workload, I may need 10 days to answer)
-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2008.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
_______________________________________________
witty-interest mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/witty-interest