appy.shared: improvements in Debianizing an Appy app: the Debian install creates now scripts for starting the Zope/Appy/app instance and OpenOffice in server mode at boot time.
This commit is contained in:
parent
1275df5753
commit
cb53c6b9b2
|
@ -6,7 +6,7 @@
|
||||||
import os, os.path, sys, shutil, re
|
import os, os.path, sys, shutil, re
|
||||||
from optparse import OptionParser
|
from optparse import OptionParser
|
||||||
from appy.shared.utils import cleanFolder, copyFolder
|
from appy.shared.utils import cleanFolder, copyFolder
|
||||||
from appy.shared.packaging import ooStart, zopeConf
|
from appy.shared.packaging import ooStartSh, zopeConf
|
||||||
|
|
||||||
# ------------------------------------------------------------------------------
|
# ------------------------------------------------------------------------------
|
||||||
class NewError(Exception): pass
|
class NewError(Exception): pass
|
||||||
|
@ -114,7 +114,7 @@ class ZopeInstanceCreator:
|
||||||
os.chmod('bin/runzope', 0744) # Make it executable by owner.
|
os.chmod('bin/runzope', 0744) # Make it executable by owner.
|
||||||
# Create bin/startoo
|
# Create bin/startoo
|
||||||
f = file('bin/startoo', 'w')
|
f = file('bin/startoo', 'w')
|
||||||
f.write(ooStart)
|
f.write(ooStartSh)
|
||||||
f.close()
|
f.close()
|
||||||
os.chmod('bin/startoo', 0744) # Make it executable by owner.
|
os.chmod('bin/startoo', 0744) # Make it executable by owner.
|
||||||
# Create etc/zope.conf
|
# Create etc/zope.conf
|
||||||
|
|
|
@ -17,6 +17,7 @@ class ZopeRunner:
|
||||||
options = zctl.ZopeCtlOptions()
|
options = zctl.ZopeCtlOptions()
|
||||||
options.realize(None)
|
options.realize(None)
|
||||||
options.program = ['/usr/bin/%srun' % app]
|
options.program = ['/usr/bin/%srun' % app]
|
||||||
|
options.sockname = '/var/lib/%s/zopectlsock' % app
|
||||||
c = zctl.ZopeCmd(options)
|
c = zctl.ZopeCmd(options)
|
||||||
c.onecmd(" ".join(options.args))
|
c.onecmd(" ".join(options.args))
|
||||||
return min(c._exitstatus, 1)
|
return min(c._exitstatus, 1)
|
||||||
|
|
|
@ -24,8 +24,9 @@ ZopeRunner().run()
|
||||||
appRun = '''#! /bin/sh
|
appRun = '''#! /bin/sh
|
||||||
exec "/usr/lib/zope2.12/bin/runzope" -C "/etc/%s.conf" "$@"
|
exec "/usr/lib/zope2.12/bin/runzope" -C "/etc/%s.conf" "$@"
|
||||||
'''
|
'''
|
||||||
ooStart = '#!/bin/sh\nsoffice -invisible -headless -nofirststartwizard ' \
|
ooStart = 'soffice -invisible -headless -nofirststartwizard ' \
|
||||||
'"-accept=socket,host=localhost,port=2002;urp;"&\n'
|
'"-accept=socket,host=localhost,port=2002;urp;"'
|
||||||
|
ooStartSh = '#! /bin/sh\n%s\n' % ooStart
|
||||||
zopeConf = '''# Zope configuration.
|
zopeConf = '''# Zope configuration.
|
||||||
%%define INSTANCE %s
|
%%define INSTANCE %s
|
||||||
%%define DATA %s
|
%%define DATA %s
|
||||||
|
@ -67,6 +68,38 @@ effective-user $ZOPE_USER
|
||||||
container-class Products.TemporaryFolder.TemporaryContainer
|
container-class Products.TemporaryFolder.TemporaryContainer
|
||||||
</zodb_db>
|
</zodb_db>
|
||||||
'''
|
'''
|
||||||
|
# initScript below will be used to define the scripts that will run the
|
||||||
|
# app-powered Zope instance and OpenOffice in server mode at boot time.
|
||||||
|
initScript = '''#! /bin/sh
|
||||||
|
### BEGIN INIT INFO
|
||||||
|
# Provides: %s
|
||||||
|
# Required-Start: $syslog $remote_fs
|
||||||
|
# Required-Stop: $syslog $remote_fs
|
||||||
|
# Should-Start: $remote_fs
|
||||||
|
# Should-Stop: $remote_fs
|
||||||
|
# Default-Start: 2 3 4 5
|
||||||
|
# Default-Stop: 0 1 6
|
||||||
|
# Short-Description: Start %s
|
||||||
|
# Description: Start the Zope and Appy-based %s application.
|
||||||
|
### END INIT INFO
|
||||||
|
|
||||||
|
case "$1" in
|
||||||
|
start)
|
||||||
|
%s
|
||||||
|
;;
|
||||||
|
restart|reload|force-reload)
|
||||||
|
%s
|
||||||
|
;;
|
||||||
|
stop)
|
||||||
|
%s
|
||||||
|
;;
|
||||||
|
*)
|
||||||
|
echo "Usage: $0 start|restart|stop" >&2
|
||||||
|
exit 3
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
exit 0
|
||||||
|
'''
|
||||||
|
|
||||||
class Debianizer:
|
class Debianizer:
|
||||||
'''This class allows to produce a Debian package from a Python (Appy)
|
'''This class allows to produce a Debian package from a Python (Appy)
|
||||||
|
@ -132,7 +165,7 @@ class Debianizer:
|
||||||
# startoo
|
# startoo
|
||||||
name = '%s/startoo' % binFolder
|
name = '%s/startoo' % binFolder
|
||||||
f = file(name, 'w')
|
f = file(name, 'w')
|
||||||
f.write(ooStart)
|
f.write(ooStartSh)
|
||||||
f.close()
|
f.close()
|
||||||
os.chmod(name, 0744) # Make it executable by owner.
|
os.chmod(name, 0744) # Make it executable by owner.
|
||||||
# /var/lib/<app> (will store Data.fs, lock files, etc)
|
# /var/lib/<app> (will store Data.fs, lock files, etc)
|
||||||
|
@ -159,6 +192,24 @@ class Debianizer:
|
||||||
'/var/log/%s' % n,
|
'/var/log/%s' % n,
|
||||||
'products %s\n' % productsFolder))
|
'products %s\n' % productsFolder))
|
||||||
f.close()
|
f.close()
|
||||||
|
# /etc/init.d/<app> (start the app at boot time)
|
||||||
|
initdFolder = j(etcFolder, 'init.d')
|
||||||
|
os.makedirs(initdFolder)
|
||||||
|
name = '%s/%s' % (initdFolder, self.appNameLower)
|
||||||
|
f = file(name, 'w')
|
||||||
|
n = self.appNameLower
|
||||||
|
f.write(initScript % (n, n, 'Start the Zope and Appy-based %s ' \
|
||||||
|
'application.' % n, '%sctl start' % n,
|
||||||
|
'%sctl restart' % n, '%sctl stop' % n))
|
||||||
|
f.close()
|
||||||
|
os.chmod(name, 0744) # Make it executable by owner.
|
||||||
|
# /etc/init.d/oo (start OpenOffice at boot time)
|
||||||
|
name = '%s/oo' % initdFolder
|
||||||
|
f = file(name, 'w')
|
||||||
|
f.write(initScript % ('oo', 'oo', 'Start OpenOffice in server mode',
|
||||||
|
ooStart, ooStart, "#Can't stop OO."))
|
||||||
|
f.close()
|
||||||
|
os.chmod(name, 0744) # Make it executable by owner.
|
||||||
# Get the size of the app, in Kb.
|
# Get the size of the app, in Kb.
|
||||||
os.chdir(tempFolder)
|
os.chdir(tempFolder)
|
||||||
cmd = subprocess.Popen(['du', '-b', '-s', 'debian'],
|
cmd = subprocess.Popen(['du', '-b', '-s', 'debian'],
|
||||||
|
@ -205,6 +256,8 @@ class Debianizer:
|
||||||
# Create postinst, a script that will:
|
# Create postinst, a script that will:
|
||||||
# - bytecompile Python files after the Debian install
|
# - bytecompile Python files after the Debian install
|
||||||
# - change ownership of some files if required
|
# - change ownership of some files if required
|
||||||
|
# - [in the case of an app-package] call update-rc.d for starting it at
|
||||||
|
# boot time.
|
||||||
f = file('postinst', 'w')
|
f = file('postinst', 'w')
|
||||||
content = '#!/bin/sh\nset -e\n'
|
content = '#!/bin/sh\nset -e\n'
|
||||||
for version in self.pythonVersions:
|
for version in self.pythonVersions:
|
||||||
|
@ -218,6 +271,9 @@ class Debianizer:
|
||||||
# database and log files.
|
# database and log files.
|
||||||
content += 'chown -R zope:root /var/lib/%s\n' % self.appNameLower
|
content += 'chown -R zope:root /var/lib/%s\n' % self.appNameLower
|
||||||
content += 'chown -R zope:root /var/log/%s\n' % self.appNameLower
|
content += 'chown -R zope:root /var/log/%s\n' % self.appNameLower
|
||||||
|
# Call update-rc.d for starting the app at boot time
|
||||||
|
content += 'update-rc.d %s defaults\n' % self.appNameLower
|
||||||
|
content += 'update-rc.d oo defaults\n'
|
||||||
# (re-)start the app
|
# (re-)start the app
|
||||||
content += '%sctl restart\n' % self.appNameLower
|
content += '%sctl restart\n' % self.appNameLower
|
||||||
# (re-)start oo
|
# (re-)start oo
|
||||||
|
|
Loading…
Reference in a new issue