Commit 71f0abca authored by Jeffrey Schiller's avatar Jeffrey Schiller

Merge pull request #81 from jisqyv/buildserversupport

Add the tools used to run a buildserver to the source tree along with
parents 94a98f8d caf5e166
The files in this directory are for supporting an App Inventor
buildserver on a Ubuntu Linux server.[*] What you do:
* Create an account named "buildserver":
prompt% sudo adduser buildserver --system
* copy launch-buildserver and buildmonitor.py to
/home/buildserver/
* Create /home/buildserver/lib
* Copy file files from
${ROOT}/appinventor/buildserver/build/run/lib/*
to /home/buildserver/lib/
(${ROOT} is the source root directory)
* Copy buildserver.conf to /etc/init/buildserver.conf
You can now start the buildserver via:
prompt% sudo start buildserver
Note: The buildserver will now automatically start when the server
boots. The buildmonitor.py script arranges to restart the buildserver
if it exits. So you cannot just kill the buildserver java
program. Instead you "sudo stop buildserver" which instructs "upstart"
(the Ubuntu daemon management program) to shut it down.
[*] Valid at least as of Ubuntu 12.04LTS
from subprocess import Popen,PIPE
import time
import signal
import os
import pwd
from logging.handlers import SysLogHandler
import logging
server = None
stopping = False
def main():
'''Start the buildserver and keep track of it, i.e., restart if it fails'''
global server, log
signal.signal(signal.SIGTERM, sighandler)
signal.signal(signal.SIGQUIT, sighandler)
signal.signal(signal.SIGINT, sighandler)
count = 0
buildpwd = pwd.getpwnam('buildserver')
os.setgid(buildpwd.pw_gid)
os.setuid(buildpwd.pw_uid)
os.chdir('/home/buildserver')
log = logging.getLogger()
log.addHandler(SysLogHandler('/dev/log'))
log.handlers[0].setFormatter(logging.Formatter('BUILDSERVER: %(levelname)s: %(message)s'))
log.info('Buildserver Monitor Starting')
while True:
ts = time.time()
server = Popen(['./launch-buildserver',], close_fds=True)
while not server.poll(): # While we are still running
time.sleep(10) # Sleep for ten seconds
nts = time.time()
code = server.wait()
server = None
log.warn('Build Server Terminated with code = %d' % code)
if (nts - ts) < 60: # It was running less then a minute?
log.error('Build Server Terminated within 1 minute of start!')
count += 1 # Bump count
if count > 4:
log.critical('Count of looping buildserver > 4, just hanging...')
while True:
signal.pause()
def sighandler(*args):
if server:
server.terminate()
log.warn('Build Server Shutdown')
logging.shutdown()
raise SystemExit # bye bye
if __name__ == '__main__':
main()
# buildserver - App Inventor Build Server Process Manager
description "App Inventor Build Server Process Manager"
start on runlevel [2345]
stop on runlevel [!2345]
expect fork
respawn
exec /usr/bin/python /home/buildserver/buildmonitor.py
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