[Zope] Zope as NT Service

Andy McKay andym@ActiveState.com
Mon, 4 Jun 2001 13:45:01 -0700


This is a multi-part message in MIME format.

------=_NextPart_000_024F_01C0ECFC.8D653DB0
Content-Type: text/plain;
	charset="iso-8859-1"
Content-Transfer-Encoding: 7bit

Heres a script I use for installing Zope. Ive been meaning to clean it up
and make it friendlier, but this makes the Windows changes you need to
install Zope from say source control. It will install Zope as a Service for
you. Copy this into your Zope root. Then go:

cd <ZopeRoot>
<ZopeRoot>\bin\python install.py -p 80

Where -p is the port. You must use the Zope root python because
PythonService needs to be correctly registered.

Cheers.
--
  Andy McKay.


----- Original Message -----
From: "Montagne, Michael" <montagne@BOORA.com>
To: <zope@zope.org>
Sent: Monday, June 04, 2001 1:22 PM
Subject: [Zope] Zope as NT Service


> When installing zope, I chose to not run Zope as a service.  Now I want to
> change my mind.  How do I start Zope as a service and avoid the DOS
window?
>
> -mjm
>
> _______________________________________________
> Zope maillist  -  Zope@zope.org
> http://lists.zope.org/mailman/listinfo/zope
> **   No cross posts or HTML encoding!  **
> (Related lists -
>  http://lists.zope.org/mailman/listinfo/zope-announce
>  http://lists.zope.org/mailman/listinfo/zope-dev )
>

------=_NextPart_000_024F_01C0ECFC.8D653DB0
Content-Type: text/plain;
	name="install.py"
Content-Transfer-Encoding: quoted-printable
Content-Disposition: attachment;
	filename="install.py"

# Copyright 2001, Andy McKay, andym@activestate.com=0D
=0D
import sys, os, string, time, imp, getopt, urllib=0D
=0D
def usage():=0D
    print '''=0D
    Usage <ZopeInstallation>\bin\python <this script> -p <port> [-h]=0D
=0D
    <ZopeInstallation> is where Zope is installed. This is necessary so tha=
t=0D
    python uses the correct PythonService. It also means you dont need a =
=0D
    seperate version of python.=0D
=0D
    -p <port> the port you want this to run on eg: 8080 (required)=0D
    -h print this help=0D
=0D
    For more info contact andym@activestate.com=0D
    '''=0D
    sys.exit()=0D
=0D
home=3Dos.path.split(os.path.split(sys.executable)[0])[0]=0D
opts, args =3D getopt.getopt(sys.argv[1:], 'p:ih')=0D
=0D
if '-p' not in opts[0]: usage()=0D
for o, v in opts:=0D
    if o=3D=3D'-p': port=3Dint(v)=0D
    if o=3D=3D'-h': usage()=0D
=0D
script =3D os.path.join(home, 'ZServer', 'ZService.py')=0D
python =3D os.path.join(home, 'bin', 'python.exe')=0D
=0D
# delete pyc, pyo=0D
def deleter(arg, dirname, filenames):=0D
    files_to_delete =3D ['.pyc', '.pyo']=0D
    for file in filenames:=0D
        if file[-4:] in files_to_delete:=0D
            os.chmod(dirname + os.sep + file, 0666)=0D
            os.unlink(dirname + os.sep + file)=0D
=0D
def alterstartbat(home, python):=0D
    _file =3D os.path.join(home, 'start.bat')=0D
    os.chmod(_file, 0666)=0D
    data =3D '"%s" "%s" -D ' % (python, os.path.join(home, 'z2.py'))=0D
    data =3D data + '%1 %2 %3 %4 %5 %6 %7 %8 %9'=0D
    f =3D open(_file, 'w')=0D
    f.write(data)=0D
    f.close=0D
=0D
def isvar(home):=0D
    dir =3D os.path.join(home, 'var')=0D
    lock =3D os.path.join(home, 'var', 'Data.fs.lock')=0D
    try:=0D
        os.chdir(dir)=0D
        print "no, already exists"=0D
    except:=0D
        os.mkdir(dir)=0D
        f =3D open(lock, 'w')=0D
        f.close=0D
        print "yes, made and lock file written"=0D
=0D
# fiddle z2=0D
def alterz2(home):=0D
    _file =3D os.path.join(home, 'z2.py')=0D
    os.chmod(_file, 0666)=0D
=0D
    data =3D open(_file, 'r').read()=0D
    txt =3D "swhome=3Dr'"=0D
    start =3D string.find(data, txt)=0D
    if start < 0:=0D
        raise "Error", "Couldnt locate swhome in z2 to edit"=0D
    end =3D string.find(data[start+len(txt):], "'")=0D
    file =3D data[start+len(txt):start+len(txt)+end]=0D
=0D
    data =3D string.replace(data, file, home)=0D
=0D
    f =3D open(_file, 'w')=0D
    f.write(data)=0D
    f.close=0D
=0D
# fiddle with svcname=0D
def fiddlesvc(home):=0D
    _file =3D os.path.join(home, 'ZServer', 'svcname.txt')=0D
    os.chmod(_file, 0666)=0D
    f =3D open(_file, 'w')=0D
    f.write('%s:%s' % (string.split(home, os.sep)[-1],port))=0D
    f.close=0D
=0D
# install service=0D
def installsvc(home, port, _scr, _py):=0D
    _file =3D os.path.join(home, 'bin', 'lib', 'win32', 'PythonService.exe'=
)=0D
    _cmd =3D '%s /register' % _file=0D
    os.system(_cmd)=0D
    _cmd =3D '%s %s install' % (_py, _scr)=0D
    os.system(_cmd)=0D
=0D
def removesvc(_scr, _py):=0D
    _cmd =3D '%s %s remove' % (_py, _scr)=0D
    os.system(_cmd)=0D
=0D
def stopsvc(_scr, _py):=0D
    _cmd =3D '%s %s stop' % (_py, _scr)=0D
    os.system(_cmd)=0D
=0D
#start=0D
def startsvc(_scr, _py):=0D
    _cmd =3D '%s %s start' % (_py, _scr)=0D
    os.system(_cmd)=0D
=0D
print "Deleting compiled files...."=0D
os.path.walk(home, deleter, None)=0D
=0D
print "Need to make var?...,"=0D
isvar(home)=0D
=0D
print "Altering z2.py and start.bat..."=0D
alterz2(home)=0D
alterstartbat(home, python)=0D
=0D
print "Setting service name..."=0D
fiddlesvc(home)=0D
=0D
print "\nRemoving service..."=0D
removesvc(script, python)=0D
=0D
print "\nInstalling service..."=0D
installsvc(home, port, script, python)=0D
=0D
print "\n(Re)starting service..."=0D
stopsvc(script, python)=0D
time.sleep(3)=0D
startsvc(script, python)=0D
=0D
print "Installation finished"
------=_NextPart_000_024F_01C0ECFC.8D653DB0--