Commit 7418e322 authored by Michael Hanus 's avatar Michael Hanus
Browse files

cpns and www moved to currytools

parent 88c283e1
......@@ -220,10 +220,6 @@ compilefrontend:
# compile the tools:
.PHONY: tools
tools:
# compile the Curry Port Name Server demon:
@if [ -r bin/pakcs ] ; then cd cpns && $(MAKE) ; fi
# compile the event handler demon for dynamic web pages:
@if [ -r bin/pakcs ] ; then cd www && $(MAKE) ; fi
@if [ -r bin/pakcs ] ; then cd currytools && $(MAKE) ; fi
@if [ -r bin/pakcs ] ; then cd tools && $(MAKE) ; fi
......@@ -322,8 +318,6 @@ cleantools: $(CLEANCURRY)
cd curry2prolog && $(MAKE) clean
cd currytools && $(MAKE) uninstall
cd tools && $(MAKE) clean
cd cpns && $(MAKE) clean
cd www && $(MAKE) clean
cd bin && rm -f pakcs
# Clean everything (including the front end)
......
......@@ -27,12 +27,6 @@ This directory contains:
A directory containing various executables
to execute the components of PAKCS.
`cpns`:
This directory contains scripts and executables for the
Curry Port Name Server (CPNS) which is responsible for managing the
symbolic names assigned to the named sockes and ports on a local machine
(see libraries `NamedSocket` and `Ports` for more details).
`curry2prolog`:
This directory contains the compiler from Curry into Prolog which
is the basis of the main component of PAKCS: the interactive
......@@ -85,9 +79,3 @@ This directory contains:
`tools`:
This directory contains various tools for PAKCS
(see the README there for a more detailed description).
`www`:
This directory contains scripts and executables for the
event handler server that is required to execute dynamic web
pages implemented with the libraries HTML or WUI.
------------------------------------------------------------------------
--- This is the main program of the CPNS demon.
---
--- @author Michael Hanus
--- @version June 2012
------------------------------------------------------------------------
import qualified CPNS
-- Everything is implemented in the library CPNS:
main :: IO ()
main = CPNS.main
# Translate CPNS demon for fast startup:
# Required:
# - installed Curry system (REPL)
LOGFILE="/tmp/CurryPNSD.log"
CPNSD: ../lib/CPNS.curry CPNSD.curry
$(REPL) $(REPL_OPTS) :load CPNSD :save :q
# Shows the currently registered ports:
.PHONY: show
show: CPNSD
./CPNSD show
# Shows the log file of the demon:
.PHONY: showlog
showlog:
cat $(LOGFILE)
.PHONY: clean
clean:
./stop
$(CLEANCURRY)
rm -f CPNSD
This directory contains the scripts for CPNS,
the Curry Port Name Server, which is responsible for managing the
symbolic names assigned to the named ports on a local machine.
start: script to start the CPNS demon on the local machine
This script will be automatically called by curry2prolog.
stop: script to stop the CPNS demon (usually not used)
The implementation of the CPNS demon in Curry is contained in the
system library CPNS (since it is imported by the library Ports)
based on primitive socket operations.
#!/bin/sh
# Start the Curry Port Name Server demon, if it is not already
# started on this machine:
PIDFILE="/tmp/CurryPNSD.pid"
LOGFILE="/tmp/CurryPNSD.log"
LOCKFILE="/tmp/CurryPNSD.lock" # for startup control
CPNSEXEC="`dirname "$0"`/CPNSD"
STARTSERVER=no
if test ! -f $PIDFILE ; then
STARTSERVER=yes
else
# test whether the server process is still existent:
PID=`cat $PIDFILE`
touch $PIDFILE # to avoid automatic remove if file is too old
ps -p $PID | fgrep $PID > /tmp/TESTPID$$
if test ! -s /tmp/TESTPID$$ ; then
STARTSERVER=yes
rm -f $PIDFILE
echo "CPNS demon seems to be aborted. I try to restart it..." >&2
fi
rm -f /tmp/TESTPID$$
fi
if [ $STARTSERVER = yes ] ; then
if lockfile -r0 $LOCKFILE ; then
echo "Starting demon for Curry Port Name Server..." >&2
if test ! -f $LOGFILE ; then
# create log file with correct access rights:
touch $LOGFILE
chmod -f 666 $LOGFILE # make log file accessible for everybody
fi
echo "Log information in file '$LOGFILE'" >&2
echo "CPNS demon started at `date`" >> $LOGFILE
echo 1 > $PIDFILE # initialize pid file with existing process
chmod -f 666 $PIDFILE # make the pid file readable for everybody
nohup "$CPNSEXEC" start >> $LOGFILE 2>&1 &
echo $! > $PIDFILE # write real cpns process into pid file
lockfile -1 $LOCKFILE # wait for lockfile deletion by CPNS demon startup
rm -f $LOCKFILE
echo "CPNS demon started." >&2
else
echo "CPNS demon seems already started by other process" >&2
echo "If this is not the case, delete file $LOCKFILE" >&2
lockfile -1 $LOCKFILE # wait for lockfile deletion by CPNS demon startup
rm -f $LOCKFILE
fi
fi
#!/bin/sh
# Terminate the Curry Port Name Server demon, if it is not already terminated:
PIDFILE="/tmp/CurryPNSD.pid"
LOCKFILE="/tmp/CurryPNSD.lock" # for startup control
CPNSEXEC="`dirname $0`/CPNSD"
if test ! -f $PIDFILE ; then
rm -f $LOCKFILE
echo "CPNS demon does not seem to be started." >&2
exit
elif test ! -f "$CPNSEXEC" ; then
rm -f $LOCKFILE
echo "CPNS demon does not seem to be generated." >&2
exit
else
# test whether the server process is still existent:
PID=`cat $PIDFILE`
ps -p $PID | fgrep $PID > /tmp/TESTPID$$
if test ! -s /tmp/TESTPID$$ ; then
rm -f $PIDFILE /tmp/TESTPID$$ $LOCKFILE
echo "CPNS demon seems to be already aborted." >&2
exit
fi
fi
"$CPNSEXEC" stop >&2
rm -f $PIDFILE /tmp/TESTPID$$ $LOCKFILE
Subproject commit d92889bfcde2506ac7eae97c6a95942f183fbe89
Subproject commit 41455e39154193596123a2752e629a92315dbe35
......@@ -27,9 +27,10 @@ name for a Curry port or asking the physical port number
of a Curry port. The demon will be automatically started for
the first time on a machine when a user compiles a program
using Curry ports. It can also be manually started and terminated by the
scripts \code{\cyshome/cpns/start} and
\code{\cyshome/cpns/stop}.
If the demon is already running, the command \code{\cyshome/cpns/start}
scripts \code{\cyshome/currytools/cpns/start} and
\code{\cyshome/currytools/cpns/stop}.
If the demon is already running, the command
\code{\cyshome/currytools/cpns/start}
does nothing (so it can be always executed
before invoking a Curry program using ports).
......
Subproject commit bc74f76e341568eb759f65f455d93c317faf7f11
Subproject commit bf61906d3a2497ba4f3245780ece974526e0964b
......@@ -184,14 +184,14 @@ fi
# stop old server, if necessary:
if [ -f $CGISERVERFILE ] ; then
echo "Stop old version of the server '$CGISERVERFILE'..."
$PAKCSHOME/www/Registry stopscript "$CGISERVERFILE"
$PAKCSHOME/currytools/www/Registry stopscript "$CGISERVERFILE"
fi
SUBMITFORM="$PAKCSHOME/www/submitform"
SUBMITFORM="$PAKCSHOME/currytools/www/SubmitForm"
# copy executable from PAKCS system (if required):
if [ $STANDALONE = yes ] ; then
cp -p "$SUBMITFORM" $CGIFILEPATHNAME/submitform
SUBMITFORM="./submitform"
cp -p "$SUBMITFORM" $CGIFILEPATHNAME/SubmitForm
SUBMITFORM="./SubmitForm"
fi
# generate cgi script:
rm -f $CGIFILE
......
# Translate programs for managing cgi server processes:
.PHONY: all
all: submitform Registry
submitform: SubmitForm.curry $(LIBDIR)/HtmlCgi.curry \
$(LIBDIR)/NamedSocket.curry $(LIBDIR)/CPNS.curry
$(REPL) $(REPL_OPTS) :load SubmitForm :save :q
mv SubmitForm submitform
Registry: Registry.curry $(LIBDIR)/HtmlCgi.curry
$(REPL) $(REPL_OPTS) :load Registry :save :q
.PHONY: cleanServers
cleanServers:
./Registry clean
.PHONY: show
show:
./Registry show
.PHONY: showload
showload:
./Registry showload
.PHONY: sketch
sketch:
./Registry sketch
.PHONY: showall
showall:
./Registry showall
.PHONY: stop
stop:
./Registry stop
.PHONY: kill
kill:
./Registry kill
.PHONY: clean
clean:
rm -f submitform Registry
$(CLEANCURRY)
This directory contains the scripts for managing CGI servers that
are executed to generate dynamic web pages implemented with the library HTML.
The CGI servers manage the event handlers used in dynamic web pages
on the server side. Usually, the servers are automatically started
whenever it is necessary to process a dynamic web page. Since these
processes will not be explicitly terminated, it is sometimes necessary
to consider the set of all servers on a machine in order to control
their resources. This is the purpose of the commands in this directory.
The following shell commands can be used to manage the CGI server processes:
> make show
Shows all currently active servers (name and pids)
> make sketch
Sketches the status of all currently active servers
(date of next cleanup and dates of all currently stored event handlers)
> make cleanServers
Starts a cleanup on each server (usually, this is implicitly started
whenever a dynamic web page is requested), i.e., expired event handlers
are deleted. Morever, servers which are inactive for a long time
(the exact period is defined in HTML.cgiServerExpiration) are terminated.
Thus, it is a good idea to execute this command periodically, e.g.,
via a cron job.
> make stop
Stops all currently active servers (however, there are automatically
restarted when a user requests the corresponding dynamic web page)
by sending them a termination message.
> make kill
Kills all currently active servers by killing their processes.
This could be used instead of "make stop" if the server don't
react for some reason.
The use of stop/kill might be necessary in order to restart servers
that have required too much resources without free them (which could
be the case if the underlying run-time system does not deallocate
memory).
------------------------------------------------------------------------
--- A simple command-based manager for CGI servers.
---
--- @author Michael Hanus
--- @version March 2012
------------------------------------------------------------------------
import ReadShowTerm
import System
import IOExts
import HtmlCgi
import Directory(doesFileExist)
main :: IO ()
main = do
args <- getArgs
case args of
["show"] -> showAllActiveServers
["showload"] -> cmdForAllServers "Show load of " GetLoad
["sketch" ] -> cmdForAllServers "Sketch status of " SketchHandlers
["showall"] -> cmdForAllServers "Status of " ShowStatus
["clean"] -> cmdForAllServers "Clean status of " CleanServer >>
getAndCleanRegistry >> done
["stop"] -> cmdForAllServers "Stopping cgi server " StopCgiServer >>
getAndCleanRegistry >> done
["kill"] -> doForAllServers "Killing process of cgi server "
(\(pid,_,_) -> system ("kill -9 "++show pid)) >>
getAndCleanRegistry >> done
["stopscript",scriptprog] -> stopActiveScriptServers scriptprog
_ -> putStrLn $ "ERROR: Illegal arguments!"
showAllActiveServers :: IO ()
showAllActiveServers = do
let header = "Currently active cgi script servers:"
putStrLn header
putStrLn (take (length header) (repeat '='))
doForAllServers "" (const done)
--- Stops the active servers for a particular cgi script by sending them
--- a stop message. This operation is used by the installation script
--- "makecurrycgi" to terminate old versions of a server.
stopActiveScriptServers :: String -> IO ()
stopActiveScriptServers scriptprog = do
regs <- getAndCleanRegistry
putStrLn $ "Stop active servers for cgi script: " ++ scriptprog
mapIO_ stopServer regs
where
stopServer (_,progname,port) =
if progname==scriptprog
then do putStrLn $ "...on port: " ++ port
runCgiServerCmd port StopCgiServer
else done
doForAllServers :: String -> ((Int,String,String) -> IO _) -> IO ()
doForAllServers cmt action = do
regs <- getAndCleanRegistry
mapIO_ doForServer regs
where
doForServer (pid,progname,port) = do
putStrLn $ cmt ++ progname++":\n(pid: "++show pid++", port: "++port++")"
catch (action (pid,progname,port) >> done) (const done)
cmdForAllServers :: String -> CgiServerMsg -> IO ()
cmdForAllServers cmt servercmd =
doForAllServers
cmt
(\ (_,_,port) -> catch (runCgiServerCmd port servercmd) (const done))
-- Get the registry with active processes and clean up the registry file.
getAndCleanRegistry :: IO [(Int,String,String)]
getAndCleanRegistry = exclusiveIO (cgiServerRegistry++".lock") $ do
regexists <- doesFileExist cgiServerRegistry
regs <- if regexists then readQTermListFile cgiServerRegistry
else return []
aregs <- mapIO (\ (pid,pname,port) -> isActivePID pid >>= \pidactive ->
return (if pidactive then [(pid,pname,port)] else [])) regs
let cregs = concat aregs
if cregs==regs
then done
else writeFile cgiServerRegistry (concatMap (\reg->show reg++"\n") cregs)
return cregs
-- Is an integer the pid of an existing process?
isActivePID :: Int -> IO Bool
isActivePID pid = do
mypid <- getPID
let tmp = "/tmp/tmp_pakcs_registry_"++show mypid
system ("ps -p "++show pid++" | fgrep "++show pid++" > "++tmp)
pr <- readCompleteFile tmp
system ("rm "++tmp)
return (not (null pr))
------------------------------------------------------------------------
--- This is the main program to start a cgi script by reading the arguments
--- and forwarding them to the cgi server process.
---
--- @author Michael Hanus
--- @version June 2012
------------------------------------------------------------------------
import HtmlCgi
-- Everything is implemented in the library HtmlCgi:
main :: IO ()
main = submitForm
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment