揮発性のメモ2

http://d.hatena.ne.jp/iww/

rebootコマンドはsystemctlへのシンボリックリンク

イマドキのrebootコマンドはsystemctlへのシンボリックリンクになってた。知らなかった

Debian 10(buster)

# which reboot
/usr/sbin/reboot

# file /usr/sbin/reboot
/usr/sbin/reboot: symbolic link to /bin/systemctl

# ls -l /usr/sbin/reboot
lrwxrwxrwx 1 root root 14  319 04:59 /usr/sbin/reboot -> /bin/systemctl


昔は halt へのシンボリックリンクだったけど、systemdの頃から変わったらしい。

Debian 3(woody)

# which reboot
/sbin/reboot

# ls -l /sbin/reboot
lrwxrwxrwx  1 root root 4 Jul 16  2006 /sbin/reboot -> halt


rebootサービスは普段は動いていない(当たり前だ)

# systemctl status reboot
● reboot.service
   Loaded: masked (Reason: Unit reboot.service is masked.)
   Active: inactive (dead)

reboot.target を見たらなんか知らん変数があった

[Unit]
Description=Reboot
Documentation=man:systemd.special(7)
DefaultDependencies=no
Requires=systemd-reboot.service
After=systemd-reboot.service
AllowIsolate=yes
JobTimeoutSec=30min    ★1
JobTimeoutAction=reboot-force    ★2

[Install]
Alias=ctrl-alt-del.target

30分待っても再起動が完了しなかったら、reboot-forceするらしい。

reboot-force causes a forced reboot which will terminate all processes forcibly
but should cause no dirty file systems on reboot (i.e. equivalent to systemctl reboot -f)

and reboot-immediate causes immediate execution of the reboot(2) system call,
which might result in data loss.

systemd service automatic restart after StartLimitInterval - Server Fault

reboot-force は一応ファイルシステムのダーティキャッシュが無い状態にするけど、reboot-immediate はrebootシステムコールをすぐ呼ぶからデータは無くなっちゃうよ ということらしい。


これをいじれば、なにか深刻な問題が起きた時に30分待たずに強制再起動とかできそう

Debianで、メタパッケージの情報を見る

# apt search ssh
(中略)
ssh/stable,now 1:7.9p1-10+deb10u2 all [インストール済み]
  secure shell クライアントおよびサーバ (メタパッケージ)

このメタパッケージをインストールしたら結局何がインストールされるん? というとき
apt show で見ることができる

# apt show ssh
Package: ssh
Version: 1:7.9p1-10+deb10u2
Priority: optional
Section: net
Source: openssh
Maintainer: Debian OpenSSH Maintainers <debian-ssh@lists.debian.org>
Installed-Size: 220 kB
Pre-Depends: dpkg (>= 1.17.5)
Depends: openssh-client (>= 1:7.9p1-10+deb10u2), openssh-server (>= 1:7.9p1-10+deb10u2)
(後略)

ファイルサイズが大きいファイルの一覧を作る

ファイルサイズが大きいファイル一覧の上位10件を表示

# find / -xdev -type f | xargs du -x -h 2>/dev/null | sort -hr | head -n 10

42M     /usr/lib/arm-linux-gnueabihf/libLLVM-6.0.so.1
36M     /var/cache/ti-pru-cgt-installer/ti_cgt_pru_2.1.5_armlinuxa8hf_busybox_installer.sh
27M     /var/cache/apt/srcpkgcache.bin
27M     /var/cache/apt/pkgcache.bin
25M     /usr/lib/arm-linux-gnueabihf/libicudata.so.57.1
23M     /usr/lib/python3.5/config-3.5m-arm-linux-gnueabihf/libpython3.5m-pic.a
22M     /usr/lib/python3.5/config-3.5m-arm-linux-gnueabihf/libpython3.5m.a
21M     /usr/share/ti/opencl/dsp.out
21M     /lib/firmware/dra7-dsp2-fw.xe66
21M     /lib/firmware/dra7-dsp1-fw.xe66


ディレクトリとか全部ひっくるめて見たいときは
sortコマンドで 16Mや255Kなど ヒューマンに優しい数値をソートする - 揮発性のメモ2

nginxでリバースプロキシの設定

VPN越しにルータのWEB管理画面を参照したかったので、nginxでリバースプロキシの設定をした

    +----+     VPN        +------+                +--------+
    | PC +----------------+ 装置 +----------------+ ルータ |
    +----+            tap +------+ eth1           +--------+
192.168.36.x    192.168.36.5   192.168.10.x      192.168.10.1


http://192.168.36.5:8001/
           ↓
http://192.168.10.1/


/etc/nginx/conf.d/proxy.conf を追加し、nginxを再起動

server {
    listen  8001;
    proxy_set_header Host $proxy_host;   # ←無くてもいい

    location / {
        proxy_pass http://192.168.0.1;
        proxy_redirect default;
    }
}
続きを読む

bashで whileの中でevalを使う

for文で出来る

for x in A=hoge B=piyo; do
    eval $x
done

echo A=$A
echo B=$B
A=hogeA
B=hogeB

while文でこう書くとアウト

echo -e "A=hoge\nB=piyo" | while read x; do
    eval $x
done
A=
B=

なぜなら、パイプを使っているから。
サブシェルになるので変数はどっか行ってしまう

while文でやりたいときは、どうにかパイプを使わずに直接食わせれば良い

while read x; do
    eval $x
done < <(echo -e "A=hoge\nB=piyo")
while read x; do
    eval $x
done << __EOF__
A=hoge
B=piyo
__EOF__


参照:
bash - Why can't I eval inside a while loop? - Stack Overflow
eval でハマった話 : ミヤタ コウヘイ@エンジニア | PRESS [プレス] : Instagram [インスタグラム] を利用したブログサービス
shell - While-loop subshell dilemma in Bash - Stack Overflow
シェルスクリプトのwhile文の中の変数を外で使う方法 - Qiita