2003-07-18 21:43:12 +00:00
|
|
|
#!/usr/bin/env python
|
|
|
|
|
|
|
|
# $Id$
|
|
|
|
# Creates a new BOINC project.
|
|
|
|
|
2003-09-04 07:16:14 +00:00
|
|
|
# TODO: use database.py (mainly for setup_project.py)
|
2003-09-05 22:12:34 +00:00
|
|
|
# TODO: don't add app / app version here.
|
|
|
|
# TODO: create 'apps' subdirectory and set it in config.xml
|
|
|
|
# TODO: use configxml module
|
2003-09-04 07:16:14 +00:00
|
|
|
|
2003-07-18 22:41:11 +00:00
|
|
|
import sys, os, getopt, re
|
2003-07-18 21:43:12 +00:00
|
|
|
sys.path.append('../py')
|
|
|
|
from version import *
|
|
|
|
from boinc import *
|
|
|
|
|
|
|
|
argv0 = sys.argv[0]
|
|
|
|
HOME = os.path.expanduser('~')
|
2003-07-18 22:41:11 +00:00
|
|
|
USER = os.environ['USER']
|
2003-07-18 21:43:12 +00:00
|
|
|
|
|
|
|
HELP = """
|
2003-07-18 23:20:46 +00:00
|
|
|
syntax: %(argv0)s [options] project-dir-name 'Project Long Name' app-exe 'AppName'
|
2003-07-18 21:43:12 +00:00
|
|
|
|
|
|
|
Creates a new project with given name with everything running on a single
|
|
|
|
server.
|
|
|
|
|
|
|
|
Misc options:
|
2003-07-18 23:20:46 +00:00
|
|
|
--verbose={0,1,2} default: 1
|
|
|
|
-v alias for --verbose=2
|
|
|
|
--no_query accept all directories without querying
|
|
|
|
--user_name default: $USER (%(USER)s)
|
|
|
|
--delete_prev_inst delete project-root first (from prev installation)
|
|
|
|
--drop_db_first drop database first (from prev installation)
|
2003-07-18 21:43:12 +00:00
|
|
|
|
|
|
|
Dir-options:
|
2003-07-18 23:20:46 +00:00
|
|
|
--base default: $HOME (%(HOME)s)
|
|
|
|
--key_dir default: BASE/keys
|
|
|
|
--project_root default: BASE/projects/PROJECT
|
|
|
|
--url_base REQUIRED; e.g.: http://maggie.ssl.berkeley.edu/
|
2003-07-18 21:43:12 +00:00
|
|
|
|
2003-07-18 23:20:46 +00:00
|
|
|
--html_user_url default: URL_BASE/PROJECT/
|
|
|
|
--html_ops_url default: URL_BASE/PROJECT_ops/
|
|
|
|
--cgi_url default: URL_BASE/PROJECT_cgi/
|
2003-07-18 21:43:12 +00:00
|
|
|
|
2003-07-18 23:20:46 +00:00
|
|
|
Example command line:
|
|
|
|
./make_project --base $HOME/boinc --url_base http://boink/ yah 'YETI @ Home' \\
|
|
|
|
upper_case 'UpperCase'
|
2003-07-18 21:43:12 +00:00
|
|
|
|
|
|
|
Then upload_dir = $HOME/boinc/projects/yah/upload
|
|
|
|
and cgi_url = http://boink/yah_cgi/
|
|
|
|
|
|
|
|
By default, directory options will be queried if they do not exist yet.
|
|
|
|
|
|
|
|
""" %locals()
|
|
|
|
|
2003-07-18 22:41:11 +00:00
|
|
|
# Project-specific directory structure that you probably don't need to change:
|
|
|
|
|
|
|
|
# --bin_dir default: PROJECT_ROOT/bin
|
|
|
|
# --cgi_bin_dir default: PROJECT_ROOT/cgi-bin
|
|
|
|
# --html_user_dir default: PROJECT_ROOT/html_user
|
|
|
|
# --html_ops_dir default: PROJECT_ROOT/html_ops
|
|
|
|
# --download_dir default: PROJECT_ROOT/download
|
|
|
|
# --upload_dir default: PROJECT_ROOT/upload
|
|
|
|
# --log_dir default: PROJECT_ROOT/log
|
|
|
|
# --pid_dir default: PROJECT_ROOT/pid
|
|
|
|
|
|
|
|
def syntax_error(str):
|
|
|
|
raise SystemExit('%s; See "%s --help" for help\n' % (str,sys.argv[0]))
|
2003-07-18 21:43:12 +00:00
|
|
|
|
|
|
|
def usage():
|
|
|
|
print HELP
|
|
|
|
raise SystemExit
|
|
|
|
|
|
|
|
try:
|
|
|
|
opts, args = getopt.getopt(sys.argv[1:],
|
|
|
|
'hv',
|
|
|
|
[ 'help',
|
|
|
|
'verbose=',
|
|
|
|
'no_query',
|
2003-07-18 22:41:11 +00:00
|
|
|
'user_name=',
|
2003-07-18 23:20:46 +00:00
|
|
|
'drop_db_first',
|
|
|
|
'delete_prev_inst',
|
2003-07-18 21:43:12 +00:00
|
|
|
'base=',
|
|
|
|
'key_dir=',
|
|
|
|
'project_root=',
|
|
|
|
'url_base=',
|
|
|
|
'html_user_url=',
|
|
|
|
'html_ops_url=',
|
|
|
|
'cgi_url=',
|
2003-07-18 22:41:11 +00:00
|
|
|
# 'bin_dir=',
|
|
|
|
# 'cgi_bin_dir=',
|
|
|
|
# 'html_user_dir=',
|
|
|
|
# 'html_ops_dir=',
|
|
|
|
# 'download_dir=',
|
|
|
|
# 'upload_dir=',
|
|
|
|
# 'log_dir=',
|
|
|
|
# 'pid_dir='
|
|
|
|
])
|
|
|
|
except getopt.GetoptError, e:
|
|
|
|
syntax_error(e)
|
2003-07-18 21:43:12 +00:00
|
|
|
|
|
|
|
options.url_base = None
|
2003-07-18 22:41:11 +00:00
|
|
|
options.no_query = False
|
2003-07-18 23:20:46 +00:00
|
|
|
options.delete_prev_inst = False
|
2003-07-18 21:43:12 +00:00
|
|
|
|
|
|
|
for o,a in opts:
|
|
|
|
if o == '-h' or o == '--help': usage()
|
2003-07-18 22:41:11 +00:00
|
|
|
elif o == '-v': options.echo_verbose = 2
|
|
|
|
elif o == '--verbose': options.echo_verbose = int(a)
|
|
|
|
elif o == '--no_query': options.no_query = True
|
|
|
|
elif o == '--user_name': options.user_name = a
|
2003-07-18 23:20:46 +00:00
|
|
|
elif o == '--drop_db_first': options.drop_db_first = True
|
|
|
|
elif o == '--delete_prev_inst': options.delete_prev_inst = True
|
2003-07-18 22:41:11 +00:00
|
|
|
elif o == '--base': options.base = a
|
|
|
|
elif o == '--key_dir': options.key_dir = a
|
|
|
|
elif o == '--project_root': options.project_root = a
|
|
|
|
elif o == '--url_base': options.url_base = a
|
|
|
|
elif o == '--html_user_url': options.html_user_url = a
|
|
|
|
elif o == '--html_ops_url': options.html_ops_url = a
|
|
|
|
elif o == '--cgi_url': options.cgi_url = a
|
|
|
|
# elif o == '--bin_dir': options.bin_dir = a
|
|
|
|
# elif o == '--cgi_bin_dir': options.cgi_bin_dir = a
|
|
|
|
# elif o == '--html_user_dir': options.html_user_dir = a
|
|
|
|
# elif o == '--html_ops_dir': options.html_ops_dir = a
|
|
|
|
# elif o == '--download_dir': options.download_dir = a
|
|
|
|
# elif o == '--upload_dir': options.upload_dir = a
|
|
|
|
# elif o == '--log_dir': options.log_dir = a
|
|
|
|
# elif o == '--pid_dir': options.pid_dir = a
|
2003-07-18 21:43:12 +00:00
|
|
|
else:
|
2003-07-18 22:41:11 +00:00
|
|
|
raise SystemExit('internal error o=%s'%o)
|
2003-07-18 21:43:12 +00:00
|
|
|
|
2003-07-18 22:41:11 +00:00
|
|
|
if len(args) != 4:
|
|
|
|
syntax_error('Need four arguments')
|
2003-07-18 21:43:12 +00:00
|
|
|
|
2003-07-18 22:41:11 +00:00
|
|
|
(project_shortname, project_longname, app_exe, app_name) = args
|
2003-07-18 21:43:12 +00:00
|
|
|
|
2003-07-18 22:41:11 +00:00
|
|
|
if not options.url_base:
|
|
|
|
syntax_error('Need --url_base')
|
2003-07-18 21:43:12 +00:00
|
|
|
|
2003-07-18 22:41:11 +00:00
|
|
|
if not options.url_base.startswith('http://'):
|
|
|
|
syntax_error('url_base needs to be an URL')
|
2003-07-18 21:43:12 +00:00
|
|
|
|
2003-07-18 22:41:11 +00:00
|
|
|
options.url_base = os.path.join(options.url_base, '')
|
2003-07-18 21:43:12 +00:00
|
|
|
|
2003-07-18 23:20:46 +00:00
|
|
|
opt_repls = {'PROJECT':project_shortname,
|
|
|
|
'PROJECT_ops':project_shortname+'_ops',
|
|
|
|
'PROJECT_cgi':project_shortname+'_cgi',
|
|
|
|
'URL_BASE':options.url_base}
|
2003-07-18 22:41:11 +00:00
|
|
|
def replopt(str):
|
|
|
|
for key in opt_repls:
|
|
|
|
str = re.compile('\\b'+key+'\\b').sub(os.path.join(opt_repls[key],'')[:-1], str)
|
|
|
|
return str
|
|
|
|
def add_slash(str, action=True):
|
|
|
|
if action:
|
|
|
|
return os.path.join(str,'')
|
|
|
|
else:
|
|
|
|
return str
|
|
|
|
def defopt(name, v, isdir=True):
|
|
|
|
options.__dict__[name] = opt_repls[name.upper()] = add_slash(replopt(options.__dict__.get(name) or v), isdir)
|
|
|
|
|
|
|
|
defopt('user_name', USER, isdir=False)
|
|
|
|
defopt('base', HOME)
|
|
|
|
defopt('key_dir', 'BASE/keys')
|
|
|
|
defopt('project_root', 'BASE/projects/PROJECT')
|
|
|
|
|
|
|
|
defopt('html_user_url', 'URL_BASE/PROJECT')
|
|
|
|
defopt('html_ops_url', 'URL_BASE/PROJECT_ops')
|
|
|
|
defopt('cgi_url', 'URL_BASE/PROJECT_cgi')
|
|
|
|
|
|
|
|
print "Creating project '%s' (short name '%s'):" %(project_longname, project_shortname)
|
|
|
|
for k in ['base',
|
|
|
|
'key_dir',
|
|
|
|
'project_root',
|
|
|
|
'url_base',
|
|
|
|
'html_user_url',
|
|
|
|
'html_ops_url',
|
|
|
|
'cgi_url' ]:
|
|
|
|
print k.upper().rjust(15), "=", options.__dict__[k]
|
|
|
|
|
|
|
|
project_root_parent = os.path.realpath(os.path.join(options.project_root,'..'))
|
|
|
|
if not os.path.exists(project_root_parent):
|
|
|
|
os.makedirs(project_root_parent)
|
|
|
|
|
2003-07-18 23:20:46 +00:00
|
|
|
if os.path.exists(options.project_root):
|
|
|
|
if options.delete_prev_inst:
|
|
|
|
if not options.no_query:
|
|
|
|
if not query_noyes('Delete %s?'%options.project_root):
|
|
|
|
raise SystemExit('Aborted')
|
|
|
|
rmtree(options.project_root)
|
|
|
|
else:
|
|
|
|
raise SystemExit('Project root already exists! Specify --delete_prev_inst --drop_db_first to clobber')
|
|
|
|
|
2003-07-18 22:41:11 +00:00
|
|
|
if not options.no_query:
|
|
|
|
if not query_yesno("Continue?"):
|
|
|
|
raise SystemExit('Aborted')
|
|
|
|
|
|
|
|
app = App(app_name)
|
|
|
|
app_version = AppVersion(app, exec_names=[app_exe])
|
|
|
|
|
|
|
|
options.install_method = 'copy'
|
|
|
|
init()
|
|
|
|
project = Project(project_shortname, project_longname,
|
|
|
|
project_dir = options.project_root,
|
|
|
|
master_url = options.url_base,
|
|
|
|
cgi_url = options.cgi_url,
|
2003-07-18 23:20:46 +00:00
|
|
|
key_dir = options.key_dir,
|
2003-07-18 22:41:11 +00:00
|
|
|
apps=[app], app_versions=[app_version],
|
|
|
|
)
|
2003-07-18 23:20:46 +00:00
|
|
|
|
2003-07-18 22:41:11 +00:00
|
|
|
project.install_project()
|
|
|
|
|
2003-07-18 23:20:46 +00:00
|
|
|
project.sched_install('feeder')
|
2003-08-19 00:59:01 +00:00
|
|
|
project.sched_install('transitioner')
|
2003-07-18 23:20:46 +00:00
|
|
|
project.sched_install('validate_test')
|
|
|
|
project.sched_install('assimilator')
|
|
|
|
project.sched_install('file_deleter')
|
|
|
|
|
|
|
|
print '''Done installing files.
|
2003-07-18 22:41:11 +00:00
|
|
|
|
2003-07-18 23:20:46 +00:00
|
|
|
You need to manually edit your Apache httpd.conf to add these lines:
|
|
|
|
|
|
|
|
Alias /%(project)s %(proot)s/html_user
|
|
|
|
Alias /%(project)s_ops %(proot)s/html_ops
|
|
|
|
ScriptAlias /%(project)s_cgi %(proot)s/cgi-bin
|
2003-07-18 22:41:11 +00:00
|
|
|
|
|
|
|
# Note: projects/*/keys/ should NOT be readable!
|
|
|
|
|
2003-07-18 23:20:46 +00:00
|
|
|
<Directory "%(proot)s/html_user">
|
|
|
|
Options Indexes FollowSymlinks MultiViews
|
2003-07-18 22:41:11 +00:00
|
|
|
AllowOverride None
|
|
|
|
Order allow,deny
|
|
|
|
Allow from all
|
|
|
|
</Directory>
|
|
|
|
|
2003-07-18 23:20:46 +00:00
|
|
|
<Directory "%(proot)s/html_ops">
|
2003-07-18 22:41:11 +00:00
|
|
|
Options FollowSymLinks
|
|
|
|
AllowOverride AuthConfig
|
|
|
|
Order allow,deny
|
|
|
|
Allow from all
|
|
|
|
</Directory>
|
2003-07-18 21:43:12 +00:00
|
|
|
|
2003-07-18 23:20:46 +00:00
|
|
|
<Directory "%(proot)s/cgi-bin">
|
|
|
|
Options ExecCGI
|
|
|
|
Order allow,deny
|
|
|
|
Allow from all
|
|
|
|
</Directory>
|
2003-07-18 21:43:12 +00:00
|
|
|
|
2003-07-18 23:20:46 +00:00
|
|
|
Install this in crontab:
|
2003-07-18 21:43:12 +00:00
|
|
|
|
2003-07-18 23:20:46 +00:00
|
|
|
0,5,10,15,20,25,30,35,40,45,50,55 * * * * %(proot)s/bin/start --cron
|
|
|
|
|
|
|
|
(You may need to set PATH and/or PYTHONPATH since cron runs with manilla environment)
|
2003-07-18 21:43:12 +00:00
|
|
|
|
2003-07-18 23:20:46 +00:00
|
|
|
To start, show status, stop BOINC daemons run:
|
2003-07-18 21:43:12 +00:00
|
|
|
|
2003-07-18 23:20:46 +00:00
|
|
|
%(proot)s/bin/start
|
|
|
|
%(proot)s/bin/status
|
|
|
|
%(proot)s/bin/stop
|
|
|
|
|
|
|
|
'''%{'project':project_shortname, 'proot':os.path.join(options.project_root,'')[:-1]}
|
|
|
|
|
|
|
|
## TODO: save settings to a file.
|