Linux OS Notes - robbiehume/CS-Notes GitHub Wiki
- systemctl: using systemctl to manage systems services
- systemd:
- puppet / facter
- https://unix.stackexchange.com/questions/268766/what-exactly-happens-when-i-execute-a-file-in-my-shell
- How a Unix / Linux shell script is executed
- Common Directories Explained
- FHS (Filesystem Hierarchy Standard)
-
/bin
: essential user binaries (programs); important system programs and utilities-
/usr/bin
: non-essential command binaries
-
-
/sbin
: similar to /bin; contains essential binaries generally intended to be run by root for sysadmin stuff-
/usr/sbin
: non-essential system administration binaries
-
-
/lib
: libraries essential for binaries in /bin and /sbin -
/etc
: contains system-wide configuration files -
/opt
: contains subdirectories for optional software packages- Commonly used by proprietary software that doesn't obey the standard file system hierarchy
-
/proc
: contains special files that represent system / kernel and process information -
/tmp
: used by applications to store temporary files. The files are generally deleted whenever the system is restarted -
/usr
: contains apps and files used by users, as opposed to by the system- Holds things that are read-only in normal operation
-
/usr/local
: where locally compiled apps install to by default -
/var
: contains variable files, i.e. files whose content is expected to continually change during normal operation of the system, such as logs and temporary e-mail files
- systemctl vs service command
- systemd service unit configuration
- systemd service execution environment config
- systemd unit configuration files (drop-in directory)
- using systemctl to manage systems services
- Service application actions
- Status:
sudo systemctl status <application>
; Starting:sudo systemctl start <application>
; Stopping:sudo systemctl stop <application>
; Start on boot:sudo systemctl enable <application>
// run disable to no longer start at boot; Restart:sudo systemctl restart <application>
- Reload:
sudo systemctl reload <application>
- Reload config w/o restarting if possible, if not then restart:
sudo systemctl reload-or-restart <application>
- Some services don't support reload, so this is a good command if you're not sure if it does or doesn't
- Status:
- Can do similar commands as systemctl^ (start, stop, restart, try-restart, reload, force-reload, status)
- Syntax is
sudo service <application> <command>
- systemd essentials
- understanding systems units and unit files (more recently updated)
- systemd service unit files
- The .service file goes in
/etc/systemd/system/<service_name>.service
- Enable on startup:
sudo systemctl enable <service_name>
- Environment variables for service: look at sample_systemd.service
- Run script before starting:
ExecStartPre
; link
Processes
-
ps aux
: see list of all running processes
Jobs
-
jobs
: see list of current jobs - Jobs have three possible states in Linux: foreground, background, and stopped Processes
- Should use copytruncate instead of (or with?) create so that the programs writing to the file don't potentially get thrown off with a file descriptor change
- https://www.digitalocean.com/community/tutorials/how-to-manage-logfiles-with-logrotate-on-ubuntu-20-04
- For a sample file look at: /misc/sample_logrotate
- The file goes in /etc/logrotate.d and need to set permissions to 644