Skip to content

Commit

Permalink
simple log file rotation for daemon on start
Browse files Browse the repository at this point in the history
  • Loading branch information
dev-zero committed Nov 3, 2017
1 parent 63e7c59 commit 3c6690d
Showing 1 changed file with 14 additions and 3 deletions.
17 changes: 14 additions & 3 deletions aiida/cmdline/commands/daemon.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,21 +149,32 @@ def daemon_start(self, *args):

print "Clearing all locks ..."
from aiida.orm.lock import LockManager
LockManager().clear_all()

import gzip
import shutil
from aiida.common import setup
import aiida # ok, this should definitely change

LockManager().clear_all()
# rotate an existing log file out of the way
daemon_logfile = os.path.join(setup.AIIDA_CONFIG_FOLDER, setup.LOG_SUBDIR, "celery.log")
if os.path.isfile(daemon_logfile):
with open(daemon_logfile, 'rb') as curr_log_fh:
with gzip.open(daemon_logfile + '.0.gz', 'wb') as old_log_fh:
shutil.copyfileobj(curr_log_fh, old_log_fh)
os.remove(daemon_logfile)

daemon_workdir = os.path.join(os.path.split(os.path.abspath(aiida.__file__))[0], "daemon")
print "Starting AiiDA Daemon in {}...".format(daemon_workdir)

print "Starting AiiDA Daemon (log file: {})...".format(daemon_logfile)
currenv = _get_env_with_venv_bin()
process = subprocess.Popen([
"celery", "worker",
"--app", "tasks",
"--loglevel", "INFO",
"--beat",
"--schedule", os.path.join(setup.AIIDA_CONFIG_FOLDER, setup.DAEMON_SUBDIR, "celerybeat-schedule"),
"--logfile", os.path.join(setup.AIIDA_CONFIG_FOLDER, setup.LOG_SUBDIR, "celery.log"),
"--logfile", daemon_logfile,
"--pidfile", self._get_pid_full_path(),
],
cwd=daemon_workdir,
Expand Down

0 comments on commit 3c6690d

Please sign in to comment.