Skip to content

Commit

Permalink
service filepath fix
Browse files Browse the repository at this point in the history
  • Loading branch information
secynic committed Apr 8, 2017
1 parent 4b423e4 commit 75969cd
Showing 1 changed file with 22 additions and 2 deletions.
24 changes: 22 additions & 2 deletions nfsinkhole/service.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
# POSSIBILITY OF SUCH DAMAGE.

from .tcpdump import TCPDump
from .exceptions import BinaryNotFound
from .utils import popen_wrapper
import logging
import os
Expand Down Expand Up @@ -170,6 +171,25 @@ def create_service(self):
service = open('nfsinkhole.service', "w")
with service:

fp = sys.executable

# Raise error if rsyslogd is not found
if not os.path.exists('{0}/nfsinkhole-service.py').format(fp):

if os.path.exists('/usr/local/bin/nfsinkhole-service.py'):

fp = "/usr/local/bin"

else:

log.debug('Path not found: {0}/nfsinkhole-service.py'
).format(fp)
raise BinaryNotFound('Service file was not detected.')

else:

fp = os.path.dirname(fp)

# Run pre main process execution
execstartpre = (
'-{pyfp} {fp}/nfsinkhole-service.py '
Expand All @@ -185,7 +205,7 @@ def create_service(self):
'--loglevel {loglevel} '
''.format(
pyfp=sys.executable,
fp=os.path.dirname(sys.executable),
fp=fp,
interface=self.interface,
protocol=self.protocol,
dport=self.dport,
Expand All @@ -204,7 +224,7 @@ def create_service(self):
'-{pyfp} {fp}/nfsinkhole-service.py '
'--delete --interface {interface} --loglevel {loglevel}'.format(
pyfp=sys.executable,
fp=os.path.dirname(sys.executable),
fp=fp,
interface=self.interface,
loglevel=self.loglevel
)
Expand Down

0 comments on commit 75969cd

Please sign in to comment.