Pages

Showing posts with label systemctl. Show all posts
Showing posts with label systemctl. Show all posts

Tuesday, September 3, 2019

Fedora 30 : Few commands for Fedora distro.

In this tutorial, I will show these commands for Fedora distro and what information can provide to users. First is lspci:
[root@desk mythcat]# lspci 
...
05:00.1 Audio device: NVIDIA Corporation High Definition Audio Controller (rev a1)
[root@desk mythcat]# echo 1 > /sys/bus/pci/devices/0000\:0
0000:00:00.0/ 0000:00:1b.0/ 0000:00:1c.4/ 0000:00:1f.2/ 0000:05:00.0/
0000:00:02.0/ 0000:00:1c.0/ 0000:00:1d.0/ 0000:00:1f.3/ 0000:05:00.1/
0000:00:16.0/ 0000:00:1c.2/ 0000:00:1e.0/ 0000:02:00.0/ 
0000:00:1a.0/ 0000:00:1c.3/ 0000:00:1f.0/ 0000:03:00.0/ 
[root@desk mythcat]# echo 1 > /sys/bus/pci/devices/0000\:05\:00.1/remove
[root@desk mythcat]# lspci 
...
05:00.0 VGA compatible controller: NVIDIA Corporation GT218 [GeForce 210] (rev a2)
[root@desk mythcat]# echo 1 > /sys/bus/pci/rescan
[root@desk mythcat]# lspci -x -s 05:00.0
05:00.0 VGA compatible controller: NVIDIA Corporation GT218 [GeForce 210] (rev a2)
00: de 10 65 0a 07 04 10 00 a2 00 00 03 01 00 80 00
10: 00 00 00 f9 0c 00 00 d0 00 00 00 00 0c 00 00 ee
20: 00 00 00 00 01 df 00 00 00 00 00 00 42 38 11 13
30: 00 00 00 00 60 00 00 00 00 00 00 00 0c 01 00 00

[root@desk mythcat]# lspci -x -s 05:00.1
05:00.1 Audio device: NVIDIA Corporation High Definition Audio Controller (rev a1)
00: de 10 e3 0b 06 00 10 00 a1 00 03 04 01 00 80 00
10: 00 00 00 fa 00 00 00 00 00 00 00 00 00 00 00 00
20: 00 00 00 00 00 00 00 00 00 00 00 00 42 38 11 13
30: 00 00 00 00 60 00 00 00 00 00 00 00 05 02 00 00
The next is dmesg: This NVIDIA Audio Controller detection has this output on dmesg:
[root@desk mythcat]# dmesg | grep 05:00.1
[    0.375902] pci 0000:05:00.1: [10de:0be3] type 00 class 0x040300
[    0.375929] pci 0000:05:00.1: reg 0x10: [mem 0xfaffc000-0xfaffffff]
[    0.376002] pci 0000:05:00.1: enabling Extended Tags
[ 2077.961694] pci 0000:05:00.1: [10de:0be3] type 00 class 0x040300
[ 2077.961730] pci 0000:05:00.1: reg 0x10: [mem 0xfaffc000-0xfaffffff]
[ 2077.962138] pci 0000:05:00.1: BAR 0: assigned [mem 0xfa000000-0xfa003fff]
[ 2423.644523] pci 0000:05:00.1: [10de:0be3] type 00 class 0x040300
[ 2423.644559] pci 0000:05:00.1: reg 0x10: [mem 0xfa000000-0xfa003fff]
[ 2423.644968] pci 0000:05:00.1: BAR 0: assigned [mem 0xfa000000-0xfa003fff]
[ 2517.259902] pci 0000:05:00.1: [10de:0be3] type 00 class 0x040300
[ 2517.259939] pci 0000:05:00.1: reg 0x10: [mem 0xfa000000-0xfa003fff]
[ 2517.260342] pci 0000:05:00.1: BAR 0: assigned [mem 0xfa000000-0xfa003fff]
The echo command can show information or set some issues :
[root@desk mythcat]# echo 1 > /sys/bus/pci/devices/0000:05:00.1/remove
[root@desk mythcat]# lspci -x -s 05:00.1
[root@desk mythcat]# 
Let's see
[root@desk mythcat]# lspci -v | grep -A7 -i "audio"
00:1b.0 Audio device: Intel Corporation 6 Series/C200 Series Chipset Family High Definition Audio 
Controller (rev 05)
        Subsystem: Gigabyte Technology Co., Ltd Device a002
        Flags: bus master, fast devsel, latency 0, IRQ 3
        Memory at fbff4000 (64-bit, non-prefetchable) [size=16K]
        Capabilities: [50] Power Management version 2
        Capabilities: [60] MSI: Enable- Count=1/1 Maskable- 64bit+
        Capabilities: [70] Express Root Complex Integrated Endpoint, MSI 00
        Capabilities: [100] Virtual Channel
--
05:00.1 Audio device: NVIDIA Corporation High Definition Audio Controller (rev a1)
        Subsystem: eVga.com. Corp. Device 1311
        Flags: bus master, fast devsel, latency 0, IRQ 5
        Memory at faffc000 (32-bit, non-prefetchable) [size=16K]
        Capabilities: [60] Power Management version 3
        Capabilities: [68] MSI: Enable- Count=1/1 Maskable- 64bit+
        Capabilities: [78] Express Endpoint, MSI 00
The systemctl can help with Fedora settings:
[root@desk mythcat]# systemctl status alsa-state.service
● alsa-state.service - Manage Sound Card State (restore and store)
   Loaded: loaded (/usr/lib/systemd/system/alsa-state.service; static; vendor preset: disabled)
   Active: inactive (dead)
[root@desk mythcat]# systemctl start alsa-state.service
[root@desk mythcat]# systemctl status alsa-state.service
● alsa-state.service - Manage Sound Card State (restore and store)
   Loaded: loaded (/usr/lib/systemd/system/alsa-state.service; static; vendor preset: disabled)
   Active: active (running) since Thu 2019-08-29 13:53:58 EEST; 1s ago
 Main PID: 2951 (alsactl)
    Tasks: 1 (limit: 1942)
   Memory: 1.3M
   CGroup: /system.slice/alsa-state.service
           └─2951 /usr/sbin/alsactl -s -n 19 -c -E ALSA_CONFIG_PATH=/etc/alsa/alsactl.conf 
--initfile=/lib/alsa/init/00main >

Aug 29 13:53:58 desk systemd[1]: Started Manage Sound Card State (restore and store).
Aug 29 13:53:58 desk alsactl[2951]: alsactl 1.1.9 daemon started
Aug 29 13:53:58 desk alsactl[2951]: /usr/sbin/alsactl: load_state:1735No soundcards found...
[root@desk mythcat]# systemctl status alsa-restore.service
● alsa-restore.service - Save/Restore Sound Card State
   Loaded: loaded (/usr/lib/systemd/system/alsa-restore.service; static; vendor preset: disabled)
   Active: inactive (dead)
[root@desk mythcat]# systemctl start alsa-restore.service
[root@desk mythcat]# systemctl status alsa-restore.service
● alsa-restore.service - Save/Restore Sound Card State
   Loaded: loaded (/usr/lib/systemd/system/alsa-restore.service; static; vendor preset: disabled)
   Active: inactive (dead)

Aug 29 13:58:53 desk systemd[1]: Condition check resulted in Save/Restore Sound Card State being skipped.
The hostnamectl command for Fedora workstations:
[root@desk mythcat]# hostnamectl set-hostname  new_hostname
The last is the common dnf command:
[root@desk mythcat]# dnf

Sunday, September 23, 2018

Fedora 28 : Start a service daemon with Python.

In this tutorial I will starting one service using systemctl , python and systemd. First, you need to create a file named testpython.service .
[mythcat@desk system]# cd /etc/systemd/system/
[root@desk system]# vim testpython.service
This file is a configuration file for this service.
[Unit]
Description=Python Service
After=multi-user.target
[Service]
Type=simple
ExecStart=/usr/bin/python /home/mythcat/test_service.py
[Install]
WantedBy=multi-user.target
Create the python file for this service. I named test_service.py .
[root@desk system]# exit
exit
[mythcat@desk system]$ cd ~
[mythcat@desk ~]$ vim test_service.py

#!/usr/bin/env python

import logging
import time

logging.basicConfig(level="INFO")

while True:
    logging.info("Hi")
    time.sleep(3)
Change permissions file for this python file and testpython.service, see:
[mythcat@desk ~]$ chmod 764 test_service.py
Because you run this service with systemd then selinux will send you error, fix that:
[mythcat@desk ~]$ chcon -t bin_t ~/test_service.py
Reload all services and start your service with this commands:
[root@desk system]# systemctl daemon-reload
[root@desk system]# systemctl start  testpython.service
[root@desk system]# systemctl status  testpython.service
● testpython.service - Python Service
   Loaded: loaded (/etc/systemd/system/testpython.service; enabled; vendor>
   Active: active (running) since Sat 2018-09-22 21:36:23 EEST; 5s ago
 Main PID: 7213 (python)
    Tasks: 1 (limit: 2102)
   Memory: 5.7M
   CGroup: /system.slice/testpython.service
           └─7213 /usr/bin/python /home/mythcat/test_service.py

Sep 22 21:36:23 desk systemd[1]: Started Python Service.
Sep 22 21:36:24 desk python[7213]: INFO:root:Hi
Sep 22 21:36:27 desk python[7213]: INFO:root:Hi
You can use the journalctl command to see the output of this service:
[root@desk system]# journalctl -u testpython.service 
-- Logs begin at Sat 2018-09-22 20:40:06 EEST, end at Sat 2018-09-22 21:31:07 EEST. --
Sep 22 20:40:06 desk python[6232]: INFO:root:Hi
Sep 22 20:40:09 desk python[6232]: INFO:root:Hi
Sep 22 20:40:12 desk python[6232]: INFO:root:Hi
Sep 22 20:40:15 desk python[6232]: INFO:root:Hi
Sep 22 20:40:18 desk python[6232]: INFO:root:Hi
Sep 22 20:40:21 desk python[6232]: INFO:root:Hi
Sep 22 20:40:24 desk python[6232]: INFO:root:Hi
Sep 22 20:40:27 desk python[6232]: INFO:root:Hi
Sep 22 20:40:30 desk python[6232]: INFO:root:Hi
Let's see the result: