Wednesday, December 30, 2015

RHEL7 - Comparison of the service Utility with systemctl


Comparison of the service Utility with systemctl
servicesystemctlDescription
service name start
systemctl start name.service
Starts a service.
service name stop
systemctl stop name.service
Stops a service.
service name restart
systemctl restart name.service
Restarts a service.
service name condrestart
systemctl try-restart name.service
Restarts a service only if it is running.
service name reload
systemctl reload name.service
Reloads configuration.
service name status
systemctl status name.service
systemctl is-active name.service
Checks if a service is running.
service --status-all
systemctl list-units --type service --all
Displays the status of all services.


source: https://access.redhat.com/documentation/en-US/Red_Hat_Enterprise_Linux/7/html/System_Administrators_Guide/sect-Managing_Services_with_systemd-Services.html


Comparison of the chkconfig Utility with systemctl
chkconfigsystemctlDescription
chkconfig name on
systemctl enable name.service
Enables a service.
chkconfig name off
systemctl disable name.service
Disables a service.
chkconfig --list name
systemctl status name.service
systemctl is-enabled name.service
Checks if a service is enabled.
chkconfig --list
systemctl list-unit-files --type service
Lists all services and checks if they are enabled.
chkconfig --list
systemctl list-dependencies --after
Lists services that are ordered to start before the specified unit.
chkconfig --list
systemctl list-dependencies --before
Lists services that are ordered to start after the specified unit.

Notes:

RHEL7 - Controlling Services and Daemons


Listing unit files with systemctl

List available units on your system
# systemctl -t help


1. Find the state of all unit
# systemctl

2. Find the state of all available service unit on your system.
# systemctl --type=service

3. Find the status of a service
# systemctl status sshd.service -l
–l option to gives you detail output.

=> List only failed services
# systemctl –failed –type=service

LOAD   = Reflects whether the unit definition was properly loaded.
ACTIVE = The high-level unit activation state, i.e. generalization of SUB.
SUB    = The low-level unit activation state, values depend on unit type.

4. Check if particular unit is active and enabled to start at boot time.
# systemctl is-active sshd
# systemctl is-enabled sshd

5. List the active state of all loaded units.
# sytsemctl list-units –type=service

List all inactive/inactive state of loaded units
# systemctl list-units –type=service –all

6. Find if unit is enable to start automatically up on reboot or not
# systemctl list-unit-files --type=service

state Description
------ ------------
loaded unit configuration file has been processed
active(running) Running with one or more continuing processes
active(waiting) Running but waiting for an event
active(existed) Successfully completed a one-time configuration
inactive not running
enabled will be started at boot time
disabled will not be started at boot time
static Can not be enabled, but may be started by an enabled unit automatically


Service status


1. Check the status of a service.
# systemctl status

2. Verify that the process is running.
# ps –up PID

3. Stop the service and verify the status
# systemctl stop sshd.service
# systemctl status sshd.service

4. Start the service and view the status. The process ID will change
# systemctl start sshd.service
# systemctl status sshd.service


5. Stop, then start, the service in a single command.
# systemctl restart sshd.service
# systemctl status sshd.service

6. Reload a service after config file change
# systemctl reload sshd.service
# systemcl status sshd.service

Note: When you restart, process ID  will be changed. But when you reload, it re-reads the configuration without a complete stop and start.  So the process ID remains same.

7. Find the service depencendy tree
# systemctl list-dependencies sshd.service

8. Disable the service and verify the status.
# systemctl disable sshd.service
# systemctl status sshd.service
Note that disabling a service does not stop the service. It only prevents the service from starting at the boot time.

Masking services
To prevent accidentally starting a service, we can mask the service. Basically masking will create a link in the configuration directories so that if the service is started nothing will happen.


To mask the service
# systemctl mask crond.service

# systemctl mask crond
# systemctl unmask crond

note: The disabled service does not start automatically at boot time but it can be started manually. A masked service does not start manually or automatically.

1. View the status of a service.
# systemctl status sshd.service

2. Disable the service and verify the status. Note that disabling a service does not stop the service.
# systemctl disable sshd.service
# systemctl status sshd.service

3. Enable the service and verify the status.
# systemctl enable sshd.service
# systemctl is-enable sshd.service


Cheat sheet on systemctl commands

Check the status of a service
# systemctl status service_name

Stop a service
# systemctl stop service_name

Start a service
# systemctl start service_name

Restart a service
# systemctl restart service_name

Reload a service
# systemctl reload service_name

Mask a service to prevent the change on service
# systemctl mask service_name

Enable mask service (unmask a serice)
# systemctl unmask service_name

Enable a service to start at boot time
# systemctl enable service_name

Disable a service from starting at boot time.
# systemctl disable service_name

List dependencies of a service
# systemcl list-dependencies service_name

List the all sockets units on the system,
# systemctl list-units --type=socket --all


---------------------------------------


# list failed services that are failed during boot
# systemctl --failed

check if service is enabled or not
systemctl is-enabled ssh


Reboot/poweroff
# systemctl halt/reboot/poweroff /suspend/hibernate

# journalctl --> check log

shows logs since the start of machine
# journalctl -b --> journal file/logging from this boot.

if you want to see specific unit log
Show logs for specific service unit

# journalctl -u ssh

===============

Display the status of all services
# systemctl list-units --type service --all

List all the services that will be started when booting into graphical mode.
# systemctl list-dependencies graphical.target | wc -l

===============================

List units: sockets, services and more
# systemctl list unit

get only services
# systemctl list unit | grep .service

List all the services and check if they are enabled
# systemctl list-unit-files --type service

RHEL7:- How to change graphical to multi user runlevel on Centos 7


1. Get the current run level
[root@new-host-4 ~]# runlevel
N 5
[root@new-host-4 ~]#


2. Get the default run level
[root@new-host-4 ~]# systemctl get-default
graphical.target

3. List the targets

[root@new-host-4 ~]# systemctl list-units --type=target
UNIT                   LOAD   ACTIVE SUB    DESCRIPTION
basic.target           loaded active active Basic System
cryptsetup.target      loaded active active Encrypted Volumes
getty.target           loaded active active Login Prompts
graphical.target       loaded active active Graphical Interface
local-fs-pre.target    loaded active active Local File Systems (Pre)
local-fs.target        loaded active active Local File Systems
multi-user.target      loaded active active Multi-User System
network-online.target  loaded active active Network is Online
network.target         loaded active active Network
nfs-client.target      loaded active active NFS client services
nss-user-lookup.target loaded active active User and Group Name Lookups
paths.target           loaded active active Paths
remote-fs-pre.target   loaded active active Remote File Systems (Pre)
remote-fs.target       loaded active active Remote File Systems
slices.target          loaded active active Slices
sockets.target         loaded active active Sockets
sound.target           loaded active active Sound Card
swap.target            loaded active active Swap
sysinit.target         loaded active active System Initialization
timers.target          loaded active active Timers

LOAD   = Reflects whether the unit definition was properly loaded.
ACTIVE = The high-level unit activation state, i.e. generalization of SUB.
SUB    = The low-level unit activation state, values depend on unit type.

20 loaded units listed. Pass --all to see loaded but inactive units, too.
To show all installed unit files use 'systemctl list-unit-files'.

4. Set the runlevel you like
[root@new-host-4 ~]# systemctl set-default multi-user.target
Removed symlink /etc/systemd/system/default.target.
Created symlink from /etc/systemd/system/default.target to /usr/lib/systemd/system/multi-user.target.
[root@new-host-4 ~]#


5. Verify your runlevel

[root@new-host-4 ~]# systemctl get-default
multi-user.target


Monday, November 23, 2015

RHEL7.2 - Installation

https://access.redhat.com/products/red-hat-enterprise-linux#getstarted

INSTRUCTIONS

  1. 1

    Start the system from the bootable disk and select "Install Red Hat Enterprise Linux 7.2."

  2. 2

    Customize installation options:

    • Adjust Date & Time, Keyboard, and Language Support preferences underLocalization.
    • Modify Installation Source, Software Selection, and Network Configuration options under Software.
    • Configure any additional options forStorage.
    • Click Begin Installation to start the process.
  3. 3

    Set a root password

  4. 4

    When the installation process completes, click Reboot.

    Take a break. Installing the operating system Red Hat Enterprise Linux could take the majority of the estimated 30-45 minutes.
  5. 5

    Register your system to receive updates and install additional products. 




Thursday, November 19, 2015

Windows 7 - The task image is corrupted or has been tampered with

I tried to create a job to shutdown MY pc one hour from now, I got the error :- The task image is corrupted or has been tampered with

Here is the solution, that worked with me.

Recreate the task by deleting the corrupted task
a. Click Start, type task scheduler and hit enter.
b. In the left pane, click on "Task scheduler library" and select the backup task in the middle pane and delete it.
If you’ve trouble finding the corrupted task, follow the steps mentioned below.
     i.       Click on Start; in the start search type cmd. In the programs list, right click on cmd and run as administrator.
    ii.       Now execute the following command.
schtasks /query | findstr /i


Source: http://www.thewindowsclub.com/schedule-shutdown-restarts-windows-7-task-schedular

To schedule the shutdown,

To make your computer shutdown at a particular time, 

type taskschd.msc is start search and hit Enter to open the Task Scheduler
In the right panel, click on Create Basic Task. 
Give it name and a description if you wish and click Next. 
When asked When do you want the task to start, select One time.
Select the Start date and time.
Clicking Next will bring you to the Action page. Here select Start a program and click on Next.
Here type shutdown on the Program/script space and –s –f –t 0 in the Add arguments box. If you want the shutdown to commence after say 60 sec, type 60 instead of 0 here.

Click Next to review all and finally click Finish. Your computer will shutdown at the designated day and time.

source: http://www.thewindowsclub.com/schedule-shutdown-restarts-windows-7-task-schedular