{"id":2090,"date":"2016-12-09T21:42:29","date_gmt":"2016-12-09T18:42:29","guid":{"rendered":"http:\/\/www.fatihacar.com\/blog\/?p=2090"},"modified":"2017-03-21T16:36:50","modified_gmt":"2017-03-21T13:36:50","slug":"check-service-status-with-python-on-oel-7-centos-7","status":"publish","type":"post","link":"https:\/\/www.fatihacar.com\/blog\/check-service-status-with-python-on-oel-7-centos-7\/","title":{"rendered":"Check Service Status With Python on OEL 7 \/ Centos 7"},"content":{"rendered":"<p>I write a python code to check mysql service open or close. It is simple and you can change <strong>service_name<\/strong> parameter in the code to check another services. You can download from here <a href=\"http:\/\/www.fatihacar.com\/blog\/resimler\/check_service_status.py_.zip\">check_service_status.py<\/a> Below code maybe can not run because of python language format is tab structure. You can use with download original code <a href=\"http:\/\/www.fatihacar.com\/blog\/resimler\/check_service_status.py_.zip\">check_service_status.py<\/a><\/p>\n<p><strong>Check MySQL Service Status<\/strong><\/p>\n<blockquote>\n<pre><code>\r\n#-*- coding: utf-8 -*-\r\n\r\nimport os\r\nimport commands\r\n\r\nservice_name = \"mysql\"\r\n\r\ndef check_service_status(service_name):\r\n\r\n        status = os.system('systemctl status '+service_name+ ' > \/dev\/null')\r\n        return status\r\n\r\ndef main():\r\n\r\n        if (check_service_status(service_name) == 0):\r\n                print \"Running\"\r\n        else:\r\n                print \"Stopped\"\r\nmain()\r\n\r\n<\/pre>\n<p><\/code><\/p>\n<p><a href=\"http:\/\/www.fatihacar.com\/blog\/resimler\/check_service_status.py_.zip\">Download<\/a><\/p><\/blockquote>\n<p><strong>Execute Scrip<\/strong>t<br \/>\n<!--more--><\/p>\n<blockquote><p>If service is running<br \/>\nroot@test ~]# python check_service_status.py<br \/>\nRunning<\/p>\n<p>If service is down<br \/>\nroot@test ~]# python check_service_status.py<br \/>\nStopped<\/p><\/blockquote>\n","protected":false},"excerpt":{"rendered":"<p>I write a python code to check mysql service open or close. It is simple and you can change service_name parameter in the code to check another services. You can download from here check_service_status.py Below code maybe can not run because of python language format is tab structure. You can use with download original code&#8230;<\/p>\n","protected":false},"author":37,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":true,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[18,97],"tags":[31,33,22],"class_list":["post-2090","post","type-post","status-publish","format-standard","hentry","category-linux-unix","category-python","tag-linux-administration","tag-python","tag-system-administration"],"jetpack_featured_media_url":"","jetpack_shortlink":"https:\/\/wp.me\/p39NFI-xI","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/www.fatihacar.com\/blog\/wp-json\/wp\/v2\/posts\/2090","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.fatihacar.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.fatihacar.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.fatihacar.com\/blog\/wp-json\/wp\/v2\/users\/37"}],"replies":[{"embeddable":true,"href":"https:\/\/www.fatihacar.com\/blog\/wp-json\/wp\/v2\/comments?post=2090"}],"version-history":[{"count":8,"href":"https:\/\/www.fatihacar.com\/blog\/wp-json\/wp\/v2\/posts\/2090\/revisions"}],"predecessor-version":[{"id":2123,"href":"https:\/\/www.fatihacar.com\/blog\/wp-json\/wp\/v2\/posts\/2090\/revisions\/2123"}],"wp:attachment":[{"href":"https:\/\/www.fatihacar.com\/blog\/wp-json\/wp\/v2\/media?parent=2090"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.fatihacar.com\/blog\/wp-json\/wp\/v2\/categories?post=2090"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.fatihacar.com\/blog\/wp-json\/wp\/v2\/tags?post=2090"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}