{"id":6716,"date":"2017-05-08T14:33:18","date_gmt":"2017-05-08T06:33:18","guid":{"rendered":"http:\/\/rmohan.com\/?p=6716"},"modified":"2017-05-08T14:33:18","modified_gmt":"2017-05-08T06:33:18","slug":"centos-rhel-7-beginners-guide-to-systemd-service-units","status":"publish","type":"post","link":"https:\/\/mohan.sg\/?p=6716","title":{"rendered":"CentOS \/ RHEL 7 : Beginners guide to systemd service units"},"content":{"rendered":"<p>Previous versions of Oracle Linux use init scripts located in the \/etc\/rc.d\/init directory to start and stop services. In RHEL 7, these init scripts have been replaced with systemd service units. Service units have a .service extension. Use the systemctl command to list all loaded service units:<\/p>\n<p># systemctl list-units &#8211;type service &#8211;all<br \/>\nUNIT                                 LOAD   ACTIVE   SUB     DESCRIPTION<br \/>\nauditd.service                       loaded active   running Security Auditing Service<br \/>\navahi-daemon.service                 loaded active   running Avahi mDNS\/DNS-SD Stack<br \/>\n&#8230;..<br \/>\nHere,<br \/>\nLOAD \u2013 service load state<br \/>\nhigh-level (ACTIVE) and low-level (SUB) unit activation state<br \/>\nDESCRIPTION \u2013 description of the service unit.<\/p>\n<p>Omit the \u2013all option to list only the active service units. Use the list-unit-files option to see which service units are enabled:<\/p>\n<p># systemctl list-unit-files &#8211;type service<\/p>\n<p>Displaying status of the services<\/p>\n<p>systemd service units correspond to system services. Use the following command to display detailed information about a service unit. This example displays information about the sshd service unit.<\/p>\n<p># systemctl status sshd<\/p>\n<p>The following information is available for the specified service unit:<\/p>\n<p>Loaded: If the service is loaded, the absolute path to the service unit file, and if the<br \/>\nservice unit is enabled<br \/>\nActive: If the service unit is running and a timestamp<br \/>\nMain PID: The Process ID of the corresponding system service and the service name<br \/>\nStatus: Additional information about the corresponding system service<br \/>\nProcess: Additional information about related processes<br \/>\nCGroup: Additional information about related Control Groups<br \/>\nTo check whether a service is running (active) or not running (inactive):<\/p>\n<p># systemctl is-active sshd<br \/>\nactive<br \/>\nTo check whether a service is enabled:<\/p>\n<p># systemctl is-enabled sshd<br \/>\nenabled<br \/>\nStarting and Stopping Services<\/p>\n<p>In previous versions of RHEL, the service utility is used to stop and start services. In RHEL 7, the systemctl utility provides an equivalent set of subcommands. The table below shows a comparison of the service utility with systemctl.<\/p>\n<p>SERVICE UTILITY\tSYSTEMCTL UTILITY\tDESCRIPTION<br \/>\nservice name start\tsystemctl start name\tStarts a service<br \/>\nservice name stop\tsystemctl stop name\tStops a service<br \/>\nservice name restart\tsystemctl restart name\tRestarts a service<br \/>\nservice name condrestart\tsystemctl try- restart name\tRestarts a service only if it is running<br \/>\nservice name reload\tsystemctl reload name\tReloads a configuration<br \/>\nservice name status\tsystemctl status name\tChecks whether a service is running<br \/>\nservice \u2013status- all\tsystemctl list-units \u2013type service \u2013all\tDisplays the status of all services<br \/>\nEnabling and disabling services<\/p>\n<p>In previous versions of RHEL, the chkconfig utility is used to enable and disable services. In RHEL 7, the systemctl utility provides an equivalent set of subcommands. The table below shows a comparison of the chkconfig utility with systemctl.<\/p>\n<p>CHKCONFIG UTILITY\tSYSTEMCTL UTILITY\tDESCRIPTION<br \/>\nchkconfig name on\tsystemctl enable name\tEnables a service<br \/>\nchkconfig name off\tsystemctl disable name\tDisables a service<br \/>\nchkconfig \u2013list name\tsystemctl status name, systemctl is-enabled name\tChecks whether a service is enabled<br \/>\nchkconfig \u2013list\tsystemctl list-unit-files \u2013type service\tLists all services and checks whether they are enabled<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Previous versions of Oracle Linux use init scripts located in the \/etc\/rc.d\/init directory to start and stop services. In RHEL 7, these init scripts have been replaced with systemd service units. Service units have a .service extension. Use the systemctl command to list all loaded service units:<\/p>\n<p># systemctl list-units &#8211;type service &#8211;all UNIT LOAD [&#8230;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[73],"tags":[],"_links":{"self":[{"href":"https:\/\/mohan.sg\/index.php?rest_route=\/wp\/v2\/posts\/6716"}],"collection":[{"href":"https:\/\/mohan.sg\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/mohan.sg\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/mohan.sg\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/mohan.sg\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=6716"}],"version-history":[{"count":1,"href":"https:\/\/mohan.sg\/index.php?rest_route=\/wp\/v2\/posts\/6716\/revisions"}],"predecessor-version":[{"id":6717,"href":"https:\/\/mohan.sg\/index.php?rest_route=\/wp\/v2\/posts\/6716\/revisions\/6717"}],"wp:attachment":[{"href":"https:\/\/mohan.sg\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=6716"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/mohan.sg\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=6716"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/mohan.sg\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=6716"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}