{"id":10840,"date":"2024-12-14T07:08:13","date_gmt":"2024-12-14T07:08:13","guid":{"rendered":"https:\/\/blog.trustedhosting.in\/?p=10840"},"modified":"2024-12-14T07:08:13","modified_gmt":"2024-12-14T07:08:13","slug":"service-management-on-centos-6","status":"publish","type":"post","link":"https:\/\/www.webystrata.com\/blog\/service-management-on-centos-6\/","title":{"rendered":"Service Management on CentOS 6"},"content":{"rendered":"<figure id=\"attachment_10841\" aria-describedby=\"caption-attachment-10841\" style=\"width: 2215px\" class=\"wp-caption alignnone\"><a href=\"https:\/\/www.trustedhosting.in\/cpanel-hosting.html\" target=\"_blank\" rel=\"noopener\"><img loading=\"lazy\" decoding=\"async\" class=\"wp-image-10841 size-full\" title=\"Service Management on CentOS 6 \" src=\"https:\/\/blog.trustedhosting.in\/wp-content\/uploads\/2024\/12\/5665313_57828-scaled.jpg\" alt=\"Service Management on CentOS 6 \" width=\"2215\" height=\"2560\" srcset=\"https:\/\/www.webystrata.com\/blog\/wp-content\/uploads\/2024\/12\/5665313_57828-scaled.jpg 2215w, https:\/\/www.webystrata.com\/blog\/wp-content\/uploads\/2024\/12\/5665313_57828-260x300.jpg 260w, https:\/\/www.webystrata.com\/blog\/wp-content\/uploads\/2024\/12\/5665313_57828-886x1024.jpg 886w, https:\/\/www.webystrata.com\/blog\/wp-content\/uploads\/2024\/12\/5665313_57828-768x888.jpg 768w, https:\/\/www.webystrata.com\/blog\/wp-content\/uploads\/2024\/12\/5665313_57828-1329x1536.jpg 1329w, https:\/\/www.webystrata.com\/blog\/wp-content\/uploads\/2024\/12\/5665313_57828-1772x2048.jpg 1772w\" sizes=\"auto, (max-width: 2215px) 100vw, 2215px\" \/><\/a><figcaption id=\"caption-attachment-10841\" class=\"wp-caption-text\">\u00a0<\/figcaption><\/figure>\n<h1>Service Management on CentOS 6<\/h1>\n<p>On a Linux <a href=\"https:\/\/www.trustedhosting.in\/cpanel-hosting.html\" target=\"_blank\" rel=\"noopener\">server<\/a>, a service is an application that is capable of running in the background performing some task or other. This guide will detail the\u00a0<code class=\"docutils literal notranslate\"><span class=\"pre\">SysVinit<\/span><\/code>\u00a0system and how you can manage services with it.<\/p>\n<p>To keep in the scope of this tutorial as part of a\u00a0<span class=\"doc\">Linux basics<\/span>\u00a0series, we\u2019ll only be covering two of the most common services you\u2019ll come across when managing a Linux web server,\u00a0<code class=\"docutils literal notranslate\"><span class=\"pre\">Apache<\/span><\/code>\u00a0and\u00a0<code class=\"docutils literal notranslate\"><span class=\"pre\">MySQL<\/span><\/code><\/p>\n<p>Our main tool for interacting with services on Linux is fairly straight forward:\u00a0<code class=\"docutils literal notranslate\"><span class=\"pre\">service<\/span><\/code><\/p>\n<p>The syntax for common tasks is fairly self explanatory and takes the following format:<\/p>\n<div class=\"highlight-bash notranslate\">\n<div class=\"highlight\">\n<pre>service <span class=\"o\">{<\/span>servicename<span class=\"o\">}<\/span> <span class=\"o\">{<\/span>command<span class=\"o\">}<\/span>\r\n<\/pre>\n<\/div>\n<\/div>\n<p>Below are a few sections on common tasks with some examples.<\/p>\n<p>As a broad rule, all service management should be carried out as the\u00a0<code class=\"docutils literal notranslate\"><span class=\"pre\">root<\/span><\/code>\u00a0user, so make sure you\u2019re logged into that account or have access to one with\u00a0<code class=\"docutils literal notranslate\"><span class=\"pre\">sudo<\/span><\/code>.<\/p>\n<section id=\"starting-services\">\n<h2>Starting services<\/h2>\n<p>The argument to start a service is simply\u00a0<code class=\"docutils literal notranslate\"><span class=\"pre\">start<\/span><\/code>, so using the structure above with the\u00a0<code class=\"docutils literal notranslate\"><span class=\"pre\">httpd<\/span><\/code>\u00a0(Red Hat distributions use this name for Apache) we get the following command:<\/p>\n<div class=\"highlight-bash notranslate\">\n<div class=\"highlight\">\n<pre>service httpd start\r\n<\/pre>\n<\/div>\n<\/div>\n<p>This will return some content letting you know if the service started successfully or not before dropping you back to your prompt ready to enter more commands:<\/p>\n<div class=\"highlight-console notranslate\">\n<div class=\"highlight\">\n<pre><span class=\"gp\">[root@94 ~]# <\/span>service httpd start\r\n<span class=\"go\">Starting httpd:                                            [  OK  ]<\/span>\r\n<span class=\"gp\">[root@94 ~]#<\/span>\r\n<\/pre>\n<\/div>\n<\/div>\n<p>If the service failed to start, it may give you information on why it failed to start or it may simply say\u00a0<code class=\"docutils literal notranslate\"><span class=\"pre\">FAILED<\/span><\/code>:<\/p>\n<div class=\"highlight-console notranslate\">\n<div class=\"highlight\">\n<pre><span class=\"gp\">[ukfastsupport@94 ~]$ <\/span>service httpd start\r\n<span class=\"go\">Starting httpd: (13)Permission denied: make_sock: could not bind to address [::]:80<\/span>\r\n<span class=\"gp gp-VirtualEnv\">(13)<\/span><span class=\"go\">Permission denied: make_sock: could not bind to address 0.0.0.0:80<\/span>\r\n<span class=\"go\">no listening sockets available, shutting down<\/span>\r\n<span class=\"go\">Unable to open logs<\/span>\r\n<span class=\"go\">                                                            [FAILED]<\/span>\r\n<span class=\"gp\">[ukfastsupport@94 ~]$<\/span>\r\n<\/pre>\n<\/div>\n<\/div>\n<p>The above example was actually fairly descriptive, letting us know that the user we were using didn\u2019t have necessary permission to start the service, but don\u2019t be surprised if you get little to no information. Such is the joy of Linux. Learning to diagnose why services won\u2019t\/can\u2019t start is beyond the scope of this article but will be covered elsewhere in our documentation in the future.<\/p>\n<\/section>\n<section id=\"stopping-services\">\n<h2>Stopping services<\/h2>\n<p>Similar to our\u00a0<code class=\"docutils literal notranslate\"><span class=\"pre\">start<\/span><\/code>\u00a0commands above, to stop a services we can just use\u00a0<code class=\"docutils literal notranslate\"><span class=\"pre\">stop<\/span><\/code>\u00a0instead. This time we\u2019ll use MySQL in our example, which has the service name\u00a0<code class=\"docutils literal notranslate\"><span class=\"pre\">mysqld<\/span><\/code>:<\/p>\n<div class=\"highlight-bash notranslate\">\n<div class=\"highlight\">\n<pre>service mysqld stop\r\n<\/pre>\n<\/div>\n<\/div>\n<p>Again, similar to start, you\u2019ll usually get some amount of feedback to let you know that the service has stopped successfully:<\/p>\n<div class=\"highlight-console notranslate\">\n<div class=\"highlight\">\n<pre><span class=\"gp\">[root@94 ~]# <\/span>service mysqld start\r\n<span class=\"go\">Starting mysqld:                                           [  OK  ]<\/span>\r\n<span class=\"gp\">[root@94 ~]#<\/span>\r\n<\/pre>\n<\/div>\n<\/div>\n<\/section>\n<section id=\"restarting-services\">\n<h2>Restarting services<\/h2>\n<p>You may have an idea on what command will be needed to restart a service by now. We\u2019ll be needing the\u00a0<code class=\"docutils literal notranslate\"><span class=\"pre\">restart<\/span><\/code>\u00a0argument:<\/p>\n<div class=\"highlight-bash notranslate\">\n<div class=\"highlight\">\n<pre>service httpd restart\r\n<\/pre>\n<\/div>\n<\/div>\n<p>This will give a combined bit of output as it stops and then starts the service:<\/p>\n<div class=\"highlight-console notranslate\">\n<div class=\"highlight\">\n<pre><span class=\"gp\">[root@94 ~]# <\/span>service httpd restart\r\n<span class=\"go\">Stopping httpd:                                            [  OK  ]<\/span>\r\n<span class=\"go\">Starting httpd:                                            [  OK  ]<\/span>\r\n<span class=\"gp\">[root@94 ~]#<\/span>\r\n<\/pre>\n<\/div>\n<\/div>\n<\/section>\n<section id=\"checking-the-status-of-services\">\n<h2>Checking the status of services<\/h2>\n<p>It\u2019s sometimes useful to see if a service is running or not, and it may not be immediately apparent, so most (but not all) services implement the\u00a0<code class=\"docutils literal notranslate\"><span class=\"pre\">status<\/span><\/code>\u00a0argument:<\/p>\n<div class=\"highlight-console notranslate\">\n<div class=\"highlight\">\n<pre><span class=\"gp\">[root@94 ~]# <\/span>service httpd status\r\n<span class=\"go\">httpd (pid  17462) is running...<\/span>\r\n<\/pre>\n<\/div>\n<\/div>\n<p>Above, we can see that Apache is up and running quite happily (or at least the service is)<\/p>\n<div class=\"highlight-console notranslate\">\n<div class=\"highlight\">\n<pre><span class=\"gp\">[root@94 ~]# <\/span>service mysqld status\r\n<span class=\"go\">mysqld is stopped<\/span>\r\n<\/pre>\n<\/div>\n<\/div>\n<p>Whilst the output varies from service to service, it\u2019s usually fairly clear if the service is running or not.<\/p>\n<p>You can sometimes even get some information on if the service was stopped cleanly or crashed:<\/p>\n<div class=\"highlight-console notranslate\">\n<div class=\"highlight\">\n<pre><span class=\"gp\">[root@94 ~]# <\/span>service mysqld status\r\n<span class=\"go\">mysqld dead but subsys locked<\/span>\r\n<\/pre>\n<\/div>\n<\/div>\n<\/section>\n<section id=\"starting-services-on-boot\">\n<h2>Starting services on boot<\/h2>\n<p>One of the most important tasks regarding services is making sure they start automatically, as you don\u2019t want to have to log in after every reboot and start them manually.<\/p>\n<p>The command for this is\u00a0<code class=\"docutils literal notranslate\"><span class=\"pre\">chkconfig<\/span><\/code>\u00a0on Red Hat\/CentOS systems.<\/p>\n<p>Usage is fairly simple. To start Red Hat at boot, we\u2019d use the following command:<\/p>\n<div class=\"highlight-bash notranslate\">\n<div class=\"highlight\">\n<pre>chkconfig httpd on\r\n<\/pre>\n<\/div>\n<\/div>\n<p>To stop MySQL from starting at boot, we could use the inverse:<\/p>\n<div class=\"highlight-bash notranslate\">\n<div class=\"highlight\">\n<pre>chkconfig mysqld off\r\n<\/pre>\n<\/div>\n<\/div>\n<p>Unlike the\u00a0<code class=\"docutils literal notranslate\"><span class=\"pre\">service<\/span><\/code>\u00a0command above,\u00a0<code class=\"docutils literal notranslate\"><span class=\"pre\">chkconfig<\/span><\/code>\u00a0doesn\u2019t give any output to the command, but we can check what is configured to start on a normal boot using the following, slightly more convoluted, command:<\/p>\n<div class=\"highlight-bash notranslate\">\n<div class=\"highlight\">\n<pre>chkconfig --list<span class=\"p\">|<\/span>grep <span class=\"s1\">'3:on'<\/span>\r\n<\/pre>\n<\/div>\n<\/div>\n<p>This will likely generate quite a lot of output as there are a fair few services that start automatically, but looking down the left hand side you should be able to see that in the following example Red Hat is configured to start at boot but\u00a0<code class=\"docutils literal notranslate\"><span class=\"pre\">MySQL<\/span><\/code>\u00a0isn\u2019t:<\/p>\n<div class=\"highlight-console notranslate\">\n<div class=\"highlight\">\n<pre><span class=\"gp\">[root@94 ~]# <\/span>chkconfig --list<span class=\"p\">|<\/span>grep <span class=\"s1\">'3:on'<\/span>\r\n<span class=\"go\">auditd          0:off   1:off   2:on    3:on    4:on    5:on    6:off<\/span>\r\n<span class=\"go\">crond           0:off   1:off   2:on    3:on    4:on    5:on    6:off<\/span>\r\n<span class=\"go\">httpd           0:off   1:off   2:on    3:on    4:on    5:on    6:off<\/span>\r\n<span class=\"go\">ip6tables       0:off   1:off   2:on    3:on    4:on    5:on    6:off<\/span>\r\n<span class=\"go\">iptables        0:off   1:off   2:on    3:on    4:on    5:on    6:off<\/span>\r\n<span class=\"go\">lvm2-monitor    0:off   1:on    2:on    3:on    4:on    5:on    6:off<\/span>\r\n<span class=\"go\">messagebus      0:off   1:off   2:on    3:on    4:on    5:on    6:off<\/span>\r\n<span class=\"go\">netfs           0:off   1:off   2:off   3:on    4:on    5:on    6:off<\/span>\r\n<span class=\"go\">network         0:off   1:off   2:on    3:on    4:on    5:on    6:off<\/span>\r\n<span class=\"go\">rsyslog         0:off   1:off   2:on    3:on    4:on    5:on    6:off<\/span>\r\n<span class=\"go\">sendmail        0:off   1:off   2:on    3:on    4:on    5:on    6:off<\/span>\r\n<span class=\"go\">sshd            0:off   1:off   2:on    3:on    4:on    5:on    6:off<\/span>\r\n<span class=\"go\">sysstat         0:off   1:on    2:on    3:on    4:on    5:on    6:off<\/span>\r\n<span class=\"go\">udev-post       0:off   1:on    2:on    3:on    4:on    5:on    6:off<\/span><\/pre>\n<\/div>\n<\/div>\n<\/section>\n","protected":false},"excerpt":{"rendered":"<p>Service Management on CentOS 6 On a Linux server, a service is an application that is capable of running in&hellip;<\/p>\n","protected":false},"author":1,"featured_media":10841,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[9],"tags":[],"class_list":["post-10840","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-linux"],"_links":{"self":[{"href":"https:\/\/www.webystrata.com\/blog\/wp-json\/wp\/v2\/posts\/10840","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.webystrata.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.webystrata.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.webystrata.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.webystrata.com\/blog\/wp-json\/wp\/v2\/comments?post=10840"}],"version-history":[{"count":2,"href":"https:\/\/www.webystrata.com\/blog\/wp-json\/wp\/v2\/posts\/10840\/revisions"}],"predecessor-version":[{"id":10843,"href":"https:\/\/www.webystrata.com\/blog\/wp-json\/wp\/v2\/posts\/10840\/revisions\/10843"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.webystrata.com\/blog\/wp-json\/wp\/v2\/media\/10841"}],"wp:attachment":[{"href":"https:\/\/www.webystrata.com\/blog\/wp-json\/wp\/v2\/media?parent=10840"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.webystrata.com\/blog\/wp-json\/wp\/v2\/categories?post=10840"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.webystrata.com\/blog\/wp-json\/wp\/v2\/tags?post=10840"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}