Skip to content

Commit

Permalink
making --setWatchDir required before running --start
Browse files Browse the repository at this point in the history
  • Loading branch information
will-rowe committed Jan 7, 2020
1 parent 48973c1 commit 1de59b4
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 13 deletions.
10 changes: 10 additions & 0 deletions run-antman-tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,14 @@
errorCode = e.returncode
sys.exit("---\nerror: failed to call `antman --setWhiteList=misc/data/NiV_6_Malaysia.fasta` (error code: {})." .format(errorCode))

# check --setWatchDir
print("setting watch dir...")
try:
setWatchDir = subprocess.run(['antman', '--setWatchDir=/tmp'], stdout=subprocess.PIPE)
except subprocess.CalledProcessError as e:
errorCode = e.returncode
sys.exit("---\nerror: failed to call `antman --setWatchDir=/tmp` (error code: {})." .format(errorCode))

# check daemonization
print("checking daemonization...")
# first make sure we can get pid
Expand All @@ -61,6 +69,8 @@
errorCode = e.returncode
sys.exit("---\nerror: failed to call `antman --getPID` (error code: {})." .format(errorCode))
pid = getPID2.stdout.decode('utf-8').rstrip('\n')
if pid == "-1":
sys.exit("---\nerror: antman did not start and failed to issue a launch error")
# check the PID is in use
try:
os.kill(int(pid), 0)
Expand Down
22 changes: 9 additions & 13 deletions src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -312,6 +312,12 @@ int main(int argc, char *argv[])
slog(0, SLOG_LIVE, "\t- daemon running: false");
}

// make sure there is a log file on record - create the default if needed (can be changed by the user later)
if (amConfig->current_log_file == NULL && logFile == NULL)
{
logFile = strdup(defaultLog);
}

// handle any --stop request
if (stop == 1)
{
Expand Down Expand Up @@ -400,12 +406,6 @@ int main(int argc, char *argv[])
{
slog(0, SLOG_INFO, "checking antman...");

// make sure there is a log - create the default if needed
if (amConfig->current_log_file == NULL)
{
amConfig->current_log_file = strdup(defaultLog);
}

// check the daemon is not already running
if (amConfig->pid != -1)
{
Expand All @@ -425,13 +425,9 @@ int main(int argc, char *argv[])
}
if (amConfig->watch_directory == NULL)
{
slog(0, SLOG_WARN, "no watch directory set, trying default location");
if (setWatchDir(amConfig, DEFAULT_WATCH_DIR) != 0)
{
destroyConfig(amConfig);
slog(0, SLOG_ERROR, "could not set watch dir");
}
slog(0, SLOG_LIVE, "\t- set to: %s", amConfig->watch_directory);
slog(0, SLOG_ERROR, "no watch directory set");
slog(0, SLOG_LIVE, "\t- try `antman --setWatchDir=some/dir`");
destroyConfig(amConfig);
return 1;
}
slog(0, SLOG_LIVE, "\t- ready");
Expand Down

0 comments on commit 1de59b4

Please sign in to comment.