computer tips

this is pile of tips for users and admins that work with computer systems; in no particular order.

sections
  1. automated user resource management
  2. restricting an address with postfix
  3. RT-AC68U drops connections
  4. ext4lazyinit

automated user resource management

with linux, we are able to use pam's pam_exec.so in order to execute commands on specific actions, such as when a user logs in or out, or specifically on local or remote shells. these commands are ran as root, so tread carefully! this method uses systemd's resource control, but the method should be easily adaptable to systems running other init's.

edit a pam file

/etc/pam.d/system-login

...

# place pam_exec.so above pam_systemd.so

session required pam_exec.so stdout /bin/setup-slice

session optional pam_systemd.so

...

write a script to set slice resource limits

/usr/bin/setup-slice

#!/bin/sh


if [ "$PAM_TYPE" = "open_session" ]; then


uid=$(id -u "$PAM_USER")

rm /etc/systemd/system/user-$uid.slice


echo "[Slice]" >> /etc/systemd/system/user-$uid.slice

echo "CPUQuota=150%" >> /etc/systemd/system/user-$uid.slice

echo "MemoryHigh=1G" >> /etc/systemd/system/user-$uid.slice

echo "MemorySwapMax=1G" >> /etc/systemd/system/user-$uid.slice

echo "IOReadBandwidthMax=/path 10M" >> /etc/systemd/system/user-$uid.slice

echo "IOWriteBandwidthMax=/path 10M" >> /etc/systemd/system/user-$uid.slice


systemctl daemon-reload


fi



restricting an address with postfix

to restrict the ability of an address to send and/or recieve mail, you must add or change the following in your postconf:

/etc/postfix/main.cf

smtpd_sender_restrictions =

check_sender_access hash:/etc/postfix/restricted_senders

...


smtpd_recipient_restrictions =

check_recipient_access hash:/etc/postfix/restricted_recipients

...


/etc/postfix/restricted_senders

user1@domain.link REJECT

user2@domain.link REJECT

user3@domain.link REJECT


/etc/postfix/restricted_recipients

user1@domain.link REJECT

user2@domain.link REJECT

user3@domain.link REJECT

with this configuration, the address will be unable to send mail, and any receiving mail will be bounced. both attempts will return with an error of access denied.


RT-AC68U drops connections

ASUS RT-AC68U routers running the AsusWRT-Merlin firmware may drop all connections while the system log is flooded with the following messages:

the solution is as follows:

1: read the procfs file cat /proc/sys/net/ipv4/tcp_max_tw_buckets

2: increase the value echo "8196" > /proc/sys/net/ipv4/tcp_max_tw_buckets

by default, ours was 4096. 8196 worked well to stop the connection dropping, but we opted for 12288 to be safe. this is a rather annoying issue that should've been solved quite a long time ago, but alas, if you want something done right, you gotta do it yourself.


ext4lazyinit

within linux, the ext4 filesystem features lazy initialization, which is aimed at speeding up the formatting of partitions. it does so by writing a partition's (sector's) inodes and journal gradually, instead of all at once. while in principle this sounds good, in practice -- and in particular, on large storage devices and arrays -- this can lead to the ext4lazyinit process chewing up cpu cycles and, more importantly, stifling data transfer speeds. in this situation, it may be desirable to disable this lazy initialization, which can be performed with the following extended arguments:

if a partition has already been formatted and is undergoing a lazy initialization, and you wish to speed it up, the following mount option can be passed:

example 1

[user@host ~]$ lsblk

NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINTS

sda 8:0 0 1T 0 disk

└─sda1 8:1 0 1T 0 part

[user@host ~]$ sudo mkfs.ext4 -E lazy_itable_init=0,lazy_journal_init=0 /dev/sda1


example 2

[user@host ~]$ lsblk

NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINTS

sda 8:0 0 1T 0 disk

└─sda1 8:1 0 1T 0 part

[user@host ~]$ sudo mount -o init_itable=0 /dev/sda1 /mnt/aux/