first version
This commit is contained in:
parent
c1cbcdb7d7
commit
88673ba2c2
44
bin/check_service
Normal file
44
bin/check_service
Normal file
@ -0,0 +1,44 @@
|
||||
#!/usr/bin/env python3
|
||||
|
||||
import argparse
|
||||
import os
|
||||
import subprocess
|
||||
import sys
|
||||
|
||||
OK=0
|
||||
WARN=1
|
||||
FAIL=2
|
||||
|
||||
def get_status_cmd(daemon):
|
||||
testpath = '/usr/sbin/service'
|
||||
if os.path.isfile(testpath) and os.access(testpath, os.X_OK):
|
||||
return [testpath, daemon, 'status']
|
||||
testpath = '/sbin/rc-service'
|
||||
if os.path.isfile(testpath) and os.access(testpath, os.X_OK):
|
||||
return [testpath, daemon, 'status']
|
||||
print('No service command found')
|
||||
sys.exit(FAIL)
|
||||
|
||||
def main():
|
||||
parser = argparse.ArgumentParser(description='Check if a service is running')
|
||||
parser.add_argument('daemon', nargs=1, help='Service name to test')
|
||||
args = parser.parse_args()
|
||||
|
||||
daemon = args.daemon[0]
|
||||
cmd = get_status_cmd(daemon)
|
||||
proc = subprocess.Popen(
|
||||
cmd,
|
||||
stdout=subprocess.PIPE,
|
||||
stderr=subprocess.PIPE)
|
||||
(out, err) = proc.communicate()
|
||||
|
||||
if proc.returncode == OK and not err:
|
||||
print(out.decode('utf8'))
|
||||
return OK
|
||||
print("'{}' returned {}".format(' '.join(cmd), proc.returncode))
|
||||
print("\nstdout: {}\nstderr: {}".format(out.decode('utf8'), err.decode('utf8')))
|
||||
return FAIL
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
sys.exit(main())
|
26
setup.py
Executable file
26
setup.py
Executable file
@ -0,0 +1,26 @@
|
||||
#!/usr/bin/env python3
|
||||
from os import environ
|
||||
|
||||
from setuptools import setup, find_packages
|
||||
|
||||
setup(
|
||||
name='check_service',
|
||||
version='0.0.1',
|
||||
description='Ichinga/Nagios check for running services',
|
||||
author='Feffe',
|
||||
author_email='feffe@fulh.ax',
|
||||
url='https://gitea.fulh.ax/feffe/check_service',
|
||||
platforms=['FreeBSD', 'Linux'],
|
||||
license='BSD',
|
||||
packages=find_packages(),
|
||||
classifiers=[
|
||||
'Development Status :: 4 - Beta',
|
||||
'Environment :: Console',
|
||||
'Intended Audience :: System Administrators',
|
||||
'Programming Language :: Python :: 3',
|
||||
'Topic :: Utilities',
|
||||
],
|
||||
keywords='auto-update',
|
||||
install_requires=[],
|
||||
scripts=['bin/check_service']
|
||||
)
|
Loading…
Reference in New Issue
Block a user