Skip to content

Commit 3d5852a

Browse files
author
Vladimir Kotal
authored
rename REINDEX to SYNC_PERIOD_MINUTES and allow disable (#3458)
fixes #3455
1 parent b256ec7 commit 3d5852a

File tree

4 files changed

+45
-29
lines changed

4 files changed

+45
-29
lines changed

docker/README.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ If you happen to have one of the following:
2222
- Source Code Management systems not supported in the image (e.g. Perforce,
2323
Clearcase, etc.)
2424
- need for authentication/authorization
25-
25+
2626
then it is advisable to run OpenGrok standalone or construct your own Docker
2727
image based on the official one.
2828

@@ -74,13 +74,13 @@ The volume mounted to `/opengrok/src` should contain the projects you want to ma
7474

7575
| Docker Environment Var. | Default value | Description |
7676
| ----------------------- | ------------- | ----------- |
77-
`REINDEX` | 10 | Period of automatic mirroring/reindexing in minutes. Setting to `0` will disable automatic indexing. You can manually trigger an reindex using docker exec: `docker exec <container> /scripts/index.sh`
77+
`SYNC_PERIOD_MINUTES` | 10 | Period of automatic synchronization (i.e. mirroring + reindexing) in minutes. Setting to `0` will disable automatic syncing.
7878
`INDEXER_OPT` | empty | pass extra options to OpenGrok Indexer. For example, `-i d:vendor` will remove all the `*/vendor/*` files from the index. You can check the indexer options on https://github.com/oracle/opengrok/wiki/Python-scripts-transition-guide
7979
`NOMIRROR` | empty | To avoid the mirroring step, set the variable to non-empty value.
8080
`URL_ROOT` | `/` | Override the sub-URL that OpenGrok should run on.
8181
`WORKERS` | number of CPUs in the container | number of workers to use for syncing
8282

83-
To specify environment variable for `docker run`, use the `-e` option, e.g. `-e REINDEX=30`
83+
To specify environment variable for `docker run`, use the `-e` option, e.g. `-e SYNC_PERIOD_MINUTES=30`
8484

8585
## OpenGrok Web-Interface
8686

@@ -105,7 +105,7 @@ services:
105105
ports:
106106
- "8080:8080/tcp"
107107
environment:
108-
REINDEX: '60'
108+
SYNC_PERIOD_MINUTES: '60'
109109
# Volumes store your data between container upgrades
110110
volumes:
111111
- '~/opengrok/src/:/opengrok/src/' # source code
@@ -123,7 +123,7 @@ Equivalent `docker run` command would look like this:
123123
docker run -d \
124124
--name opengrok \
125125
-p 8080:8080/tcp \
126-
-e REINDEX="60" \
126+
-e SYNC_PERIOD_MINUTES="60" \
127127
-v ~/opengrok-src/:/opengrok/src/ \
128128
-v ~/opengrok-etc/:/opengrok/etc/ \
129129
-v ~/opengrok-data/:/opengrok/data/ \

docker/start.py

Lines changed: 36 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,7 @@ def merge_commands_env(commands, env):
218218
return commands
219219

220220

221-
def syncer(logger, loglevel, uri, config_path, reindex, numworkers, env):
221+
def syncer(logger, loglevel, uri, config_path, sync_period, numworkers, env):
222222
"""
223223
Wrapper for running opengrok-sync.
224224
To be run in a thread/process in the background.
@@ -242,7 +242,7 @@ def syncer(logger, loglevel, uri, config_path, reindex, numworkers, env):
242242
#
243243
# The driveon=True is needed for the initial indexing of newly
244244
# added project, otherwise the incoming check in the opengrok-mirror
245-
# would short circuit it.
245+
# program would short circuit it.
246246
#
247247
if env:
248248
logger.info('Merging commands with environment')
@@ -262,7 +262,7 @@ def syncer(logger, loglevel, uri, config_path, reindex, numworkers, env):
262262

263263
save_config(logger, uri, config_path)
264264

265-
sleep_seconds = int(reindex) * 60
265+
sleep_seconds = sync_period * 60
266266
logger.info("Sleeping for {} seconds".format(sleep_seconds))
267267
time.sleep(sleep_seconds)
268268

@@ -305,13 +305,22 @@ def main():
305305
logger.debug("URL_ROOT = {}".format(url_root))
306306
logger.debug("URI = {}".format(uri))
307307

308-
# default period for reindexing (in minutes)
309-
reindex_env = os.environ.get('REINDEX')
310-
if reindex_env:
311-
reindex_min = reindex_env
308+
# default period for syncing (in minutes)
309+
sync_period = 10
310+
sync_env = os.environ.get('SYNC_TIME_MINUTES')
311+
if sync_env:
312+
try:
313+
n = int(sync_env)
314+
if n >= 0:
315+
sync_period = n
316+
except ValueError:
317+
logger.error("SYNC_TIME_MINUTES is not a number: {}".
318+
format(sync_env))
319+
320+
if sync_period == 0:
321+
logger.info("synchronization disabled")
312322
else:
313-
reindex_min = 10
314-
logger.debug("reindex period = {} minutes".format(reindex_min))
323+
logger.info("synchronization period = {} minutes".format(sync_period))
315324

316325
# Note that deploy is done before Tomcat is started.
317326
deploy(logger, url_root)
@@ -335,18 +344,25 @@ def main():
335344
os.path.getsize(OPENGROK_CONFIG_FILE) == 0:
336345
create_bare_config(logger)
337346

338-
if os.environ.get('WORKERS'):
339-
num_workers = os.environ.get('WORKERS')
340-
else:
347+
if sync_period > 0:
341348
num_workers = multiprocessing.cpu_count()
342-
logger.info('Number of sync workers: {}'.format(num_workers))
343-
344-
logger.debug("Starting sync thread")
345-
thread = threading.Thread(target=syncer, name="Sync thread",
346-
args=(logger, log_level, uri,
347-
OPENGROK_CONFIG_FILE,
348-
reindex_min, num_workers, env))
349-
thread.start()
349+
workers_env = os.environ.get('WORKERS')
350+
if workers_env:
351+
try:
352+
n = int(workers_env)
353+
if n > 0:
354+
num_workers = n
355+
except ValueError:
356+
logger.error("WORKERS is not a number: {}".format(workers_env))
357+
358+
logger.info('Number of sync workers: {}'.format(num_workers))
359+
360+
logger.debug("Starting sync thread")
361+
thread = threading.Thread(target=syncer, name="Sync thread",
362+
args=(logger, log_level, uri,
363+
OPENGROK_CONFIG_FILE,
364+
sync_period, num_workers, env))
365+
thread.start()
350366

351367
# Start Tomcat last. It will be the foreground process.
352368
logger.info("Starting Tomcat")

tools/src/main/python/opengrok_tools/mirror.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,14 +96,14 @@ def main():
9696
help='batch mode - will log into a file')
9797
parser.add_argument('-L', '--logdir',
9898
help='log directory')
99-
parser.add_argument('-B', '--backupcount', default=8,
99+
parser.add_argument('-B', '--backupcount', default=8, type=int,
100100
help='how many log files to keep around in batch mode')
101101
parser.add_argument('-I', '--check-changes', action='store_true',
102102
help='Check for changes in the project or its'
103103
' repositories,'
104104
' terminate the processing'
105105
' if no change is found.')
106-
parser.add_argument('-w', '--workers', default=cpu_count(),
106+
parser.add_argument('-w', '--workers', default=cpu_count(), type=int,
107107
help='Number of worker processes')
108108
add_http_headers(parser)
109109
parser.add_argument('--api_timeout', type=int,

tools/src/main/python/opengrok_tools/sync.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ def do_sync(loglevel, commands, cleanup, dirs_to_process, ignore_errors,
100100

101101
# Map the commands into pool of workers so they can be processed.
102102
retval = SUCCESS_EXITVAL
103-
with Pool(processes=int(numworkers)) as pool:
103+
with Pool(processes=numworkers) as pool:
104104
try:
105105
cmds_base_results = pool.map(worker, cmds_base, 1)
106106
except KeyboardInterrupt:
@@ -127,7 +127,7 @@ def main():
127127
tool_version=__version__)
128128
])
129129
parser.add_argument('-w', '--workers', default=multiprocessing.cpu_count(),
130-
help='Number of worker processes')
130+
help='Number of worker processes', type=int)
131131

132132
# There can be only one way how to supply list of projects to process.
133133
group1 = parser.add_mutually_exclusive_group()

0 commit comments

Comments
 (0)