Skip to content
This repository has been archived by the owner on Nov 18, 2022. It is now read-only.

Commit

Permalink
improved daemon status detection
Browse files Browse the repository at this point in the history
  • Loading branch information
hugbug committed Jul 29, 2015
1 parent 81d7b05 commit 766e5a5
Showing 1 changed file with 28 additions and 4 deletions.
32 changes: 28 additions & 4 deletions app/src/main/java/net/nzbget/nzbget/Daemon.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,11 @@

import android.util.Log;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Daemon
{
Expand All @@ -27,13 +31,33 @@ public Status status()
{
return Status.STATUS_NOTINSTALLED;
}
else if (new File("/data/data/net.nzbget.nzbget/nzbget/nzbget.lock").exists())

File lockFile = new File("/data/data/net.nzbget.nzbget/nzbget/nzbget.lock");
if (!lockFile.exists())
{
return Status.STATUS_RUNNING;
}
else {
return Status.STATUS_STOPPED;
}

try
{
Process process = Runtime.getRuntime().exec("ps nzbget");
BufferedReader br = new BufferedReader(new InputStreamReader(process.getInputStream()));
int num = 0;
while (br.readLine() != null)
{
num++;
}
if (num > 1)
{
return Status.STATUS_RUNNING;
}
}
catch (IOException e)
{
// ignore
}

return Status.STATUS_STOPPED;
}

public boolean exec(String cmdLine)
Expand Down

0 comments on commit 766e5a5

Please sign in to comment.