понедельник, 29 октября 2018 г.

Terminal applications asciicasts and termtosvg

Иногда нужно записать работу в терминале.

С одной стороны, может оказаться вполне достаточным использование нативного приложения, которое присутствует почти во всех дистрибутивах Unix-like систем - script. Эта утилита записывает в текстовый файл ввод и вывод.

Существуют интересные альтернативы.


ASCIICASTS


Одна из них - утилита asciicasts. Эта утилита записывает не только ввод и вывод, она фактически отображает сам процесс работы с терминалом, то есть записывается в определённом формате видео работы с терминалом. Это может быть полезно если работа в режиме командной строки отображается как пример или инструкция на Youtube или другом видеохостинге, сайте.

После установки утилиты для записи терминала следует выполнить команду

asciinema rec

Для остановки записи достаточно нажать Ctrl-d.

Воспроизводится запись командой

asciinema play

Как пишут здесь, указывать можно как локальный файл, так и ссылку на сайт.



TERMTOSVG


Похожим образом работает утилита termtosvg.
Как следует из названия, утилита записывает ввод и вывод терминала в svg файл. Для установки утилиты необходим пакет Python3. Устанавливается утилита командой

pip3 install --user termtosvg

После установки для запуска в терминале выполняется команда

termtosvg

Остановить запись можно командой

exit

Вот что еще пишут в статье про эту утилиту:

Получившийся файл с анимацией по умолчанию отправится в папку /var/, но при запуске можешь указать желаемый путь и название.
Также можно указать размеры окна, добавив ключ -g, например -g 82x18. Или задать более интересную цветовую схему при помощи ключа -t. Выбрать из семи готовых вариантов поможет галерея с примерами. О том, как конвертировать из формата cast в SVG, можешь узнать в мануале.
Чтобы воспроизвести получившийся ролик, достаточно написать termtosvg <название файла> либо просто открыть его в браузере.

среда, 24 октября 2018 г.

how to work with systemd

Подсистема Systemd в современных дистрибутивах Linux используется по-умолчанию.

Есть разница между SysVinit и Systemd.

Нашёл хорошее сравнение и описание команд:


Services

Note that all recent versions of systemctl assume the '.service' if left off. So, 'systemctl start frobozz.service' is the same as 'systemctl start frobozz'

Sysvinit CommandSystemd CommandNotes
service frobozz startsystemctl start frobozzUsed to start a service (not reboot persistent)
service frobozz stopsystemctl stop frobozzUsed to stop a service (not reboot persistent)
service frobozz restartsystemctl restart frobozzUsed to stop and then start a service
service frobozz reloadsystemctl reload frobozzWhen supported, reloads the config file without interrupting pending operations.
service frobozz condrestartsystemctl condrestart frobozzRestarts if the service is already running.
service frobozz statussystemctl status frobozzTells whether a service is currently running.
ls /etc/rc.d/init.d/systemctl (or) systemctl list-unit-files --type=service (or)
ls /lib/systemd/system/*.service /etc/systemd/system/*.service
Used to list the services that can be started or stopped
Used to list all the services and other units
chkconfig frobozz onsystemctl enable frobozzTurn the service on, for start at next boot, or other trigger.
chkconfig frobozz offsystemctl disable frobozzTurn the service off for the next reboot, or any other trigger.
chkconfig frobozzsystemctl is-enabled frobozzUsed to check whether a service is configured to start or not in the current environment.
chkconfig --listsystemctl list-unit-files --type=service (or) ls /etc/systemd/system/*.wants/Print a table of services that lists which runlevels each is configured on or off
chkconfig --list | grep 5:onsystemctl list-dependencies graphical.targetPrint a table of services that will be started when booting into graphical mode
chkconfig frobozz --listls /etc/systemd/system/*.wants/frobozz.serviceUsed to list what levels this service is configured on or off
chkconfig frobozz --addsystemctl daemon-reloadUsed when you create a new service file or modify any configuration
Note that all /sbin/service and /sbin/chkconfig lines listed above continue to work on systemd, and will be translated to native equivalents as necessary. The only exception is chkconfig --list.

И ещё:

Runlevels/targets

Systemd has a concept of targets which serve a similar purpose as runlevels but act a little different. Each target is named instead of numbered and is intended to serve a specific purpose. Some targets are implemented by inheriting all of the services of another target and adding additional services to it. There are systemd targets that mimic the common sysvinit runlevels so you can still switch targets using the familiar telinit RUNLEVEL command. The runlevels that are assigned a specific purpose on vanilla Fedora installs; 0, 1, 3, 5, and 6; have a 1:1 mapping with a specific systemd target. Unfortunately, there's no good way to do the same for the user-defined runlevels like 2 and 4. If you make use of those it is suggested that you make a new named systemd target as /etc/systemd/system/$YOURTARGET that takes one of the existing runlevels as a base (you can look at /lib/systemd/system/graphical.target as an example), make a directory /etc/systemd/system/$YOURTARGET.wants, and then symlink the additional services that you want to enable into that directory. (The service unit files that you symlink live in /lib/systemd/system).
Sysvinit RunlevelSystemd TargetNotes
0runlevel0.target, poweroff.targetHalt the system.
1, s, singlerunlevel1.target, rescue.targetSingle user mode.
2, 4runlevel2.target, runlevel4.target, multi-user.targetUser-defined/Site-specific runlevels. By default, identical to 3.
3runlevel3.target, multi-user.targetMulti-user, non-graphical. Users can usually login via multiple consoles or via the network.
5runlevel5.target, graphical.targetMulti-user, graphical. Usually has all the services of runlevel 3 plus a graphical login.
6runlevel6.target, reboot.targetReboot
emergencyemergency.targetEmergency shell
Changing runlevels:
Sysvinit CommandSystemd CommandNotes
telinit 3systemctl isolate multi-user.target (OR systemctl isolate runlevel3.target OR telinit 3)Change to multi-user run level.
sed s/^id:.*:initdefault:/id:3:initdefault:/ln -sf /lib/systemd/system/multi-user.target /etc/systemd/system/default.targetSet to use multi-user runlevel on next reboot.
Kernel Options:
The above systemd targets can be used when booting. At the GRUB menu, edit the selection to add "systemd.unit=target" (without the double-quotation marks) as a kernel option where target is one of the above. (For example, "rescue.target".)
Tip: the ".target" extention is optional. The "systemd.unit=rescue" kernel option works the same as "systemd.unit=rescue.target".