diff --git a/bin/check_service b/bin/check_service new file mode 100644 index 0000000..3d4f3c9 --- /dev/null +++ b/bin/check_service @@ -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()) diff --git a/setup.py b/setup.py new file mode 100755 index 0000000..6862f61 --- /dev/null +++ b/setup.py @@ -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'] + )