Linux daemons — stand-alone services, xinetd, logging, and runlevels

Contents

  1. 1. System services (daemons)
    1. 1.1. ldd
    2. 1.2. tcp wrapper
    3. 1.3. service
    4. 1.4. chkconfig
    5. 1.5. runlevel
    6. 1.6. init
    7. 1.7. ntsysv
  2. 2. Login archives (logs)
    1. 2.1. log
    2. 2.2. level
    3. 2.3. logrotate
      1. 2.3.1. Working with syslog
    4. 2.4. depmod
    5. 2.5. lsmod
    6. 2.6. modinfo
    7. 2.7. insmod, rmmod, modprobe
    8. 2.8. rpm
    9. 2.9. yum

Notes from Bird’s Linux Private Kitchen (3rd edition), kept for quick review.

System services (daemons)

  • Modes
    • stand alone — self-started, resident in memory; /etc/init.d/* (httpd, vsftpd)
    • super daemon — xinetd stays in memory and manages others via /etc/xinetd.d/* (telnet)
      • multi-threaded — one service handles multiple programs
      • single-threaded — one at a time; extras queue
  • Services
    • signal control
    • interval control — cron and similar schedulers
  • /etc/services — records service ports
  • Super-daemon config under /etc/xinetd.d/*
    • socket_type stream: TCP; dgram: UDP; raw: talks to IP directly
    • wait yes: single-threaded control; no: multi-threaded control
    • instances — max concurrent connections
    • per_source — max connections from one IP
    • cps num1 num2 — max new connections per second; service disabled for num2 seconds if exceeded
    • redirect ip port — forward the service elsewhere
    • only-from [0.0.0.0,192.168.1.0/24,hostname,domainname] — access control
    • no-access
    • access_times [HH:MM-HH:MM] — time window

ldd

  • Inspect dynamic libraries linked by an executable

tcp wrapper

  • Programs linked with libwrap.so can use /etc/hosts.{allow,deny} (httpd typically does not)
  • Example: rsync:127.0.0.100:deny — third field defaults to deny in hosts.deny
  • Columns one and two
    • ALL — all programs or IPs
    • LOCAL — from this host
    • UNKNOWN — unresolvable IP, domain, or service
    • KNOWN — resolvable IP, domain, or service
  • Column three
    • spawn %d(hostname),%a(address),%d(daemon)
    • twist — run the following command, then drop the connection

service

  • service --status-all — all service states; same idea as netstat -anl

chkconfig

  • --list [service] — list service state
  • --add service
  • --del service
  • --level [0-6] service [on|off]
  • chkconfig --level 345 atd on — start atd in runlevels 3, 4, and 5

Run levels

  • 0 halt (power off)
  • 1 single-user mode (maintenance)
  • 2 multi-user, without NFS (like 3 but no NFS)
  • 3 full multi-user, text console with networking
  • 4 unused (reserved)
  • 5 like 3 with X Window
  • 6 reboot

Levels 0 and 6 are boot-related; do not set services on by default there.

runlevel

  • Show previous and current runlevel

init

  • N — switch runlevel

ntsysv

Login archives (logs)

vim /etc/rsyslog.conf — configure logging

log

  • cron: /var/log/cron
  • dmesg: /var/log/dmesg
  • last login per system account: /var/log/lastlog
  • mail: /var/log/maillog or /var/log/mail/*
  • system errors: /var/log/messages
  • auth failures, etc.: /var/log/secure
  • successful vs failed logins: /var/log/wtmp (last) vs faillog

level

  • info, notice, warning, err, crit, alert, emerg [debug, none]
  • . — this level and above, e.g. mail.info
  • .= — exactly the listed level
  • .! — everything except the listed level

logrotate

  • -v — verbose
  • -f — force rotate

Working with syslog

# Prevent users from tweaking the log so rsyslog can still append
chattr -a /var/log/messages

# Use prerotate/postrotate so logrotate behaves
vi /etc/logrotate.d/syslog

/var/log/messages
/var/log/secure
/var/log/maillog
/var/log/spooler
/var/log/boot.log
/var/log/cron
{
	sharedscripts
	prerotate
	/usr/bin/chattr -a /var/log/messages
	endscript

	sharedscripts
	postrotate
	/bin/kill -HUP `cat /var/run/syslogd.pid 2> /dev/null` 2> /dev/null || true
	# If you use rsyslogd.pid instead:
	/bin/kill -HUP `cat /var/run/rsyslogd.pid 2> /dev/null` 2> /dev/null || true
	/usr/bin/chattr +a /var/log/messages
	endscript
}

logrotate

  • /var/log/log_name.log — log file
  • /etc/logrotate.d/log_name — matching config

depmod

  • -A — add new modules
  • -n — dry run to stdout
  • -e — show loaded modules that cannot run

lsmod

  • List loaded kernel modules

modinfo

  • -a [module_name|filename] — authors only
  • -d — description only
  • -l — license only
  • -n — path to the module file only

insmod, rmmod, modprobe

rpm

  • rpm -ivh *.rpm — install
  • rpm -Uvh — upgrade if installed; install if missing
  • rpm -Fvh — upgrade only when already installed
  • rpm -qa — list installed packages

yum

  • yum install xxx
  • yum list xxx — package details
  • yum search rpm
  • yum update xxx
  • yum -y upgrade — upgrade
  • yum clean [packages|headers|all] — clear cached RPM data
  • yum remove xxx
  • LANG=C yum grouplist — available package groups
  • yum groupinfo group-name
  • yum groupinstall [--installroot=/path/]
  • yum groupremove group-name
  • yum repolist all — list repos
Questions? Leave a comment below or email: newbvirgil@gmail.com