fixed the httpd conf issue with redirecting to /monitor/
[monitor.git] / web / MonitorWeb / monitorweb / commands.py
1 # -*- coding: utf-8 -*-\r
2 """This module contains functions called from console script entry points."""\r
3 \r
4 import sys\r
5 from os import getcwd, getpid\r
6 from os.path import dirname, exists, join\r
7 \r
8 import pkg_resources\r
9 pkg_resources.require("TurboGears>=1.0.7")\r
10 \r
11 import cherrypy\r
12 import turbogears\r
13 \r
14 cherrypy.lowercase_api = True\r
15 \r
16 \r
17 class ConfigurationError(Exception):\r
18     pass\r
19 \r
20 \r
21 def start():\r
22     """Start the CherryPy application server."""\r
23 \r
24     setupdir = dirname(dirname(__file__))\r
25     curdir = getcwd()\r
26 \r
27     # First look on the command line for a desired config file,\r
28     # if it's not on the command line, then look for 'setup.py'\r
29     # in the current directory. If there, load configuration\r
30     # from a file called 'dev.cfg'. If it's not there, the project\r
31     # is probably installed and we'll look first for a file called\r
32     # 'prod.cfg' in the current directory and then for a default\r
33     # config file called 'default.cfg' packaged in the egg.\r
34     if len(sys.argv) > 1:\r
35         configfile = sys.argv[1]\r
36     elif exists(join(setupdir, "setup.py")):\r
37         configfile = join(setupdir, "dev.cfg")\r
38     elif exists(join(curdir, "prod.cfg")):\r
39         configfile = join(curdir, "prod.cfg")\r
40     else:\r
41         try:\r
42             configfile = pkg_resources.resource_filename(\r
43               pkg_resources.Requirement.parse("MonitorWeb"),\r
44                 "config/default.cfg")\r
45         except pkg_resources.DistributionNotFound:\r
46             raise ConfigurationError("Could not find default configuration.")\r
47 \r
48         if "prod" in configfile:\r
49                 f = open("/var/run/monitorweb.pid", 'w')\r
50                 f.write(str(getpid()))\r
51                 f.close()\r
52 \r
53     turbogears.update_config(configfile=configfile,\r
54         modulename="monitorweb.config")\r
55 \r
56     from monitorweb.controllers import Root\r
57 \r
58     turbogears.start_server(Root())\r