{"id":1340,"date":"2018-12-31T12:32:06","date_gmt":"2018-12-31T07:02:06","guid":{"rendered":"http:\/\/jaipurhosting.com\/blog\/?p=1340"},"modified":"2019-04-27T07:32:12","modified_gmt":"2019-04-27T02:02:12","slug":"linux-service-command","status":"publish","type":"post","link":"https:\/\/www.jaipurhosting.com\/blog\/linux-service-command\/","title":{"rendered":"Linux service command"},"content":{"rendered":"\n<p>The service command lets you run a System V init script. In this tutorial, we will briefly discuss this tool using some easy to understand examples.<\/p>\n\n\n\n<p><strong>Linux service command<\/strong><\/p>\n\n\n\n<p>Here are the available syntax for the service command in Linux:<\/p>\n\n\n\n<p><em>service SCRIPT COMMAND [OPTIONS]<\/em><\/p>\n\n\n\n<p><em>service &#8211;status-all<\/em><\/p>\n\n\n\n<p><em>service &#8211;help | -h | &#8211;version<\/em><\/p>\n\n\n\n<p>And here\u2019s how the man page explains it:<\/p>\n\n\n\n<p><em>service runs a System V init script or systemd unit in as predictable an environment as possible,<br> removing most environment variables and with the current working directory set to \/.<\/em><\/p>\n\n\n\n<p><em>The SCRIPT parameter specifies a System V init script, located in \/etc\/init.d\/SCRIPT, or the name <br> of a systemd unit. The existence of a systemd unit of the same name as a script in \/etc\/init.d <br> will cause the unit to take precedence over the init.d script. The supported values of COMMAND <br> depend on the invoked script. service passes COMMAND and OPTIONS to the init script unmodified.<br> For systemd units, start, stop, status, and reload are passed through to their systemctl\/initctl <br><\/em> <em>equivalents<\/em>.<\/p>\n\n\n\n<p><em>All scripts should support at least the start and stop commands. As a special case, if COMMAND <br> is &#8211;full-restart, the script is run twice, first with the stop command, then with the start <br><\/em> <em>command<\/em>.<\/p>\n\n\n\n<p><em>service &#8211;status-all runs all init scripts, in alphabetical order, with the status command. The <br> status is [ + ] for running services, [ &#8211; ] for stopped services and [ ? ] for services <br> without a status command. This option only calls status for sysvinit jobs.<\/em><\/p>\n\n\n\n<p><strong>To use service command<\/strong><\/p>\n\n\n\n<p>The usage of the \u2018service\u2019 command line tool isn\u2019t complicated at all. Let\u2019s talk about how you can use this utility when it comes to handling scripts like httpd and sshd.<\/p>\n\n\n\n<p>Here\u2019s how you run a script using service:<\/p>\n\n\n\n<p><em>service httpd start<\/em><\/p>\n\n\n\n<p>Here\u2019s how you stop an already running script using service:<\/p>\n\n\n\n<p><em>service sshd stop<\/em><\/p>\n\n\n\n<p>Here\u2019s how you fetch status for a script:<\/p>\n\n\n\n<p><em>service httpd status<\/em><\/p>\n\n\n\n<p>Here\u2019s how you restart and already-running service:<\/p>\n\n\n\n<p><em>service sshd restart<\/em><\/p>\n\n\n\n<p><strong>Conclusion<\/strong><\/p>\n\n\n\n<p>Depending on your privileges as Linux user, you may want to run all the above examples using the \u2018sudo\u2019 command. To learn more about the \u2018service\u2019 command, head to its man page.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>The service command lets you run a System V init script. In this tutorial, we will briefly discuss this tool using some easy to understand examples. Linux service command Here are the available syntax for the service command in Linux: service SCRIPT COMMAND [OPTIONS] service &#8211;status-all service &#8211;help | -h | &#8211;version And here\u2019s how [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":1341,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-1340","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-categorized"],"_links":{"self":[{"href":"https:\/\/www.jaipurhosting.com\/blog\/wp-json\/wp\/v2\/posts\/1340","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.jaipurhosting.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.jaipurhosting.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.jaipurhosting.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.jaipurhosting.com\/blog\/wp-json\/wp\/v2\/comments?post=1340"}],"version-history":[{"count":1,"href":"https:\/\/www.jaipurhosting.com\/blog\/wp-json\/wp\/v2\/posts\/1340\/revisions"}],"predecessor-version":[{"id":1342,"href":"https:\/\/www.jaipurhosting.com\/blog\/wp-json\/wp\/v2\/posts\/1340\/revisions\/1342"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.jaipurhosting.com\/blog\/wp-json\/wp\/v2\/media\/1341"}],"wp:attachment":[{"href":"https:\/\/www.jaipurhosting.com\/blog\/wp-json\/wp\/v2\/media?parent=1340"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.jaipurhosting.com\/blog\/wp-json\/wp\/v2\/categories?post=1340"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.jaipurhosting.com\/blog\/wp-json\/wp\/v2\/tags?post=1340"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}