systemctl command with all possible options rhel7 and centos7
systemctl is a command available in new version of Linux. Systemctl is used to control the systemd and service manager. To control services we have to use lot many options along with systemctl command. It is changed dramatically in new version of Linux. In this article we are going to explore as many possible ways as to use systemctl command in Linux.
Let’s start with checking the service status.
1. Service Status Check and show service units
below is the command used to verify the service status
2. Verify service is active and enabled
If service is active it means service is running without any issues. As a example we verify web service is running OR not.
Enabling service means we are ensuring that service should start when server is rebooted. In older versions chkconfig command.
3. Start and restart service using systemctl
As simple as starting the services and restarting the services is very easy, Here we have little more than that in New version.
as we say it is more than start and restart we have systemctl try-restart now your thinking about what is the difference between restart and try-restart..?
option restart will restart the service if it is in stopped state also.
option try-restart Restart one or more units specified on the command line if the units are running. This does nothing if units are not running. Note that, for compatibility with Red Hat init scripts, condrestart is equivalent to this command.
4. Listing dependencies, jobs, sockets, unit-files and Units
Listing dependencies means what are the services we have to start before starting this required service this before version this feature was not there.
Shows required and wanted units of the specified unit. If no unit is specified, default.target is implied. Target units are recursively expanded. When –all is passed, all other units are recursively expanded as well
list-jobs will show what are jobs running currently in background
Listing installed unit files
List all available sockets
Note: because the addresses might contains spaces, this output is not suitable for programmatic consumption.
5. Setting up default target (Older version Run Level) and getting default target
We have to use set-default to set default run level and we can see default run level using get-default option as shown below example
6. Masking service ans unmasking service
What is mean by masking service, there is situation that company will have multiple administrators working together still there are times one administrator will stop the service which is not required but another administrator will start the same service unfortunately Or unknowingly , will lead to lot of problems to avoid this types of situations. We have to disable, stop the service and mask it, when other administrator try to start also the service will never start until unless explicitly unmask.
As shown in above command examples we have stopped the service, disabled the service and masked the service. Now try to start the service.
now unmask the service and start it will start
7. Reload and reset service status
Most of the administrator will still have an question that what is the difference between service reload and restart.
Service reload is used whenever we changed something to the service and we would like to push the changes to the service without interrupting the connected users. Reloading the service will never change existing PID (Process Identity)
Service restart is used to restart the service which means stop and start the service, whenever we run restart existing users will disconnect and new PID will be created. It required little downtime to the service changes.
Before reloading the service status
After reloading the service
if observe correctly PID before and after reload not changed.
Reset the “failed” state of the specified units
8. Daemon reload option
After deleting the file or directory, you should reload the systemd process so that it no longer attempts to reference these files and reverts back to using the system copies. You can do this by typing:
9. Isolating Targets using systemctl command
It is possible to start all of the units associated with a target and stop all units that are not part of the dependency tree. The command that we need to do this is called, appropriately, isolate. This is similar to changing the runlevel in other init systems.
For instance, if you are operating in a graphical environment with graphical.target active, you can shut down the graphical system and put the system into a multi-user command line state by isolating the multi-user.target. Since graphical.target depends on multi-user.target but not the other way around, all of the graphical units will be stopped.
You may wish to take a look at the dependencies of the target you are isolating before performing this procedure to ensure that you are not stopping vital services:
When you are satisfied with the units that will be kept alive, you can isolate the target by typing:
10. Create service snapshot and delete
Create a snapshot. If a snapshot name is specified, the new snapshot will be named after it. If none is specified, an automatic snapshot name is generated. In either case, the snapshot name used is printed to STDOUT, unless –quiet is specified.
A snapshot refers to a saved state of the systemd manager. It is implemented itself as a unit that is generated dynamically with this command and has dependencies on all units active at the time. At a later time, the user may return to this state by using the isolate command on the snapshot unit.
Snapshots are only useful for saving and restoring which units are running or are stopped, they do not save/restore any other state. Snapshots are dynamic and lost on reboot.
Using Shortcuts for Important Events
Conclusion
Now you know how to use some of the systemctl commands to start, stop, restart, mask , unmask and enable systemd services.
We are waiting for your valuable comments dear, Don’t wait write your feedback.
Search Engine Keywords :
systemd command in linux, systemctl command not found in linux, systemctl command in linux, systemctl command not found linux, systemctl command not found linux mint, what is systemctl command in linux, sudo systemctl command not found, ubuntu systemctl command not found, systemctl list running services, systemctl is enabled, systemctl mask, centos systemctl command not found, systemctl list services, systemctl status, install systemctl ubuntu, systemctl command not found centos, linux systemctl command, systemctl add service, systemctl start up, systemctl disable service, systemctl commands, centos 7 systemctl add service, centos 7 service command, rhel 7 systemctl, centos 7 systemctl, bash sudo not found, bash visudo command not found, bash sudo command not found, rosrun command not found, systemctl status degraded, bash systemctl command not found, systemctl command not found ubuntu, systemctl enable service, systemctl create new service, systemctl command in linux, bash command not found linux, bash open command not found, command not found bash script, install systemctl, ubuntu upstart systemd, does ubuntu use systemd, ubuntu 14.04 systemd, systemd ubuntu, systemd how to, systemctl linux, debian systemctl, centos systemctl, systemctl command not found, systemctl service file, systemctl stop iptables, systemctl remove service, systemctl stop, systemctl service file location, systemctl set default, systemctl is enabled static
No comments:
Post a Comment