rabbit-slide-znz-debian-meeting-202104 2021.4.17.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.rabbit +1 -0
- data/README.md +24 -0
- data/Rakefile +17 -0
- data/config.yaml +23 -0
- data/debian-meeting-systemd.md +208 -0
- data/pdf/debian-meeting-202104-debian-meeting-systemd.pdf +0 -0
- metadata +65 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 3e88fb5a237aea57acf3b77a0ff5b0428abc148c28ee47866587b5e9d5190c67
|
4
|
+
data.tar.gz: 6559995b4d94199574095a0682c2efe8fcb24dee0600ce63203fdc5972cafdd7
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 15e73baab53f999f61be43e723809a59b7d555accd331d56e736c43f5711b77bdc0bb43419fc53875c461504eaae4c4ce3e520e568f452487982372d45b7097b
|
7
|
+
data.tar.gz: 38c208062c119f905ec741d9d94acdd44df5e0a1665c5a522dbdbd1c7d5e40c4c5a35858e1d0567fa9eceb74638cc96b10ad5ae87f0e623d522cf79fc9249ee8
|
data/.rabbit
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
debian-meeting-systemd.md
|
data/README.md
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
# systemd 再入門
|
2
|
+
|
3
|
+
[オンライン開催:東京エリア・関西合同Debian勉強会(2021/04/17(土))](https://debianjp.connpass.com/event/208924/)の発表資料です。
|
4
|
+
crontab の代わりに systemd-timer を使う、および user 権限での systemd の話です。
|
5
|
+
|
6
|
+
## 作者向け
|
7
|
+
|
8
|
+
### 表示
|
9
|
+
|
10
|
+
rake
|
11
|
+
|
12
|
+
### 公開
|
13
|
+
|
14
|
+
rake publish
|
15
|
+
|
16
|
+
## 閲覧者向け
|
17
|
+
|
18
|
+
### インストール
|
19
|
+
|
20
|
+
gem install rabbit-slide-znz-debian-meeting-202104
|
21
|
+
|
22
|
+
### 表示
|
23
|
+
|
24
|
+
rabbit rabbit-slide-znz-debian-meeting-202104.gem
|
data/Rakefile
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
require "rabbit/task/slide"
|
2
|
+
|
3
|
+
# Edit ./config.yaml to customize meta data
|
4
|
+
|
5
|
+
spec = nil
|
6
|
+
Rabbit::Task::Slide.new do |task|
|
7
|
+
spec = task.spec
|
8
|
+
# spec.files += Dir.glob("doc/**/*.*")
|
9
|
+
# spec.files -= Dir.glob("private/**/*.*")
|
10
|
+
# spec.add_runtime_dependency("rabbit-theme-YOUR-THEME")
|
11
|
+
end
|
12
|
+
|
13
|
+
desc "Tag #{spec.version}"
|
14
|
+
task :tag do
|
15
|
+
sh("git", "tag", "-a", spec.version.to_s, "-m", "Publish #{spec.version}")
|
16
|
+
sh("git", "push", "--tags")
|
17
|
+
end
|
data/config.yaml
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
---
|
2
|
+
id: debian-meeting-202104
|
3
|
+
base_name: debian-meeting-systemd
|
4
|
+
tags:
|
5
|
+
- linux
|
6
|
+
- systemd
|
7
|
+
presentation_date: '2021-04-17'
|
8
|
+
presentation_start_time:
|
9
|
+
presentation_end_time:
|
10
|
+
version: 2021.4.17.0
|
11
|
+
licenses: []
|
12
|
+
slideshare_id: systemd-246336275
|
13
|
+
speaker_deck_id: systemd-zai-ru-men
|
14
|
+
ustream_id:
|
15
|
+
vimeo_id:
|
16
|
+
youtube_id:
|
17
|
+
author:
|
18
|
+
markup_language: :markdown
|
19
|
+
name: Kazuhiro NISHIYAMA
|
20
|
+
email: zn@mbf.nifty.com
|
21
|
+
rubygems_user: znz
|
22
|
+
slideshare_user: znzjp
|
23
|
+
speaker_deck_user: znz
|
@@ -0,0 +1,208 @@
|
|
1
|
+
# systemd 再入門
|
2
|
+
|
3
|
+
author
|
4
|
+
: Kazuhiro NISHIYAMA
|
5
|
+
|
6
|
+
content-source
|
7
|
+
: 東京エリア・関西合同Debian勉強会
|
8
|
+
|
9
|
+
date
|
10
|
+
: 2021-04-17
|
11
|
+
|
12
|
+
institution
|
13
|
+
: 株式会社Ruby開発
|
14
|
+
|
15
|
+
allotted-time
|
16
|
+
: 40m
|
17
|
+
|
18
|
+
theme
|
19
|
+
: lightning-simple
|
20
|
+
|
21
|
+
# 自己紹介
|
22
|
+
|
23
|
+
- 西山 和広
|
24
|
+
- Ruby のコミッター
|
25
|
+
- twitter, github など: @znz
|
26
|
+
- 株式会社Ruby開発 www.ruby-dev.jp
|
27
|
+
|
28
|
+
# systemd のおすすめ資料
|
29
|
+
|
30
|
+
- systemdエッセンシャル / systemd-intro - Speaker Deck
|
31
|
+
<https://speakerdeck.com/moriwaka/systemd-intro>
|
32
|
+
|
33
|
+
# agenda
|
34
|
+
|
35
|
+
- crontab の代わりに systemd-timer
|
36
|
+
- user 権限での systemd
|
37
|
+
|
38
|
+
# systemd-timer の利点
|
39
|
+
|
40
|
+
- `systemctl start` での動作確認と `timer` での実行の環境が同じ
|
41
|
+
- `journald` に自動でログが残る
|
42
|
+
- 他の `unit` との依存関係が設定できる (DB バックアップなら DB 起動必須など)
|
43
|
+
- 時刻指定が `crontab` より柔軟
|
44
|
+
|
45
|
+
# systemd-timer の欠点
|
46
|
+
|
47
|
+
- 最低限の利用でも記述量が多い
|
48
|
+
- `service` ファイルと `timer` ファイルが必要で 1 行だけでは出来ない
|
49
|
+
- 時刻指定が独自
|
50
|
+
- kubernetes の cronjob のような新しいものでも crontab 形式の時刻指定が使われていることが多い
|
51
|
+
|
52
|
+
# シンプルな使い方
|
53
|
+
|
54
|
+
- `Type=oneshot` の `service` ユニットを作成
|
55
|
+
- 同名の `timer` ユニットを作成して `systemctl enable --now foo.timer` のように `enable` と `start` をする
|
56
|
+
- 別の名前のユニットを `start` するなら `Unit=` で指定
|
57
|
+
|
58
|
+
# enable と start
|
59
|
+
|
60
|
+
- `foo.timer` から起動する `foo.service` は `enable` しない
|
61
|
+
- `foo.timer` も `enable` を忘れるとマシンの再起動後に動いていない (service unit と同じ)
|
62
|
+
- `systemctl start foo.service` で `timer` を待たずに起動して動作確認可能
|
63
|
+
|
64
|
+
# 動作確認例
|
65
|
+
|
66
|
+
- `systemctl list-timers`
|
67
|
+
- `systemctl status systemd-tmpfiles-clean.timer`
|
68
|
+
- `systemctl status systemd-tmpfiles-clean.service`
|
69
|
+
|
70
|
+
# ログの例
|
71
|
+
|
72
|
+
- ログ表示は `systemd-journal` グループに所属するか `sudo` を使う
|
73
|
+
- `journalctl -u systemd-tmpfiles-clean.timer`
|
74
|
+
- `journalctl -u systemd-tmpfiles-clean.service`
|
75
|
+
- `Starting` が実行開始時刻で `Started` が実行終了時刻
|
76
|
+
|
77
|
+
# service 作成例
|
78
|
+
|
79
|
+
```
|
80
|
+
# /etc/systemd/system/gitlab-backup.service
|
81
|
+
[Unit]
|
82
|
+
Description=Backup gitlab
|
83
|
+
After=gitlab-runsvdir.service
|
84
|
+
Requires=gitlab-runsvdir.service
|
85
|
+
|
86
|
+
[Service]
|
87
|
+
Type=oneshot
|
88
|
+
ExecStart=/opt/gitlab/bin/gitlab-rake gitlab:backup:create CRON=1
|
89
|
+
```
|
90
|
+
|
91
|
+
# service 作成例 (解説)
|
92
|
+
|
93
|
+
- `ExecStart` が `crontab` での実行内容に相当 (`ARGV0` の部分はフルパス必須)
|
94
|
+
- `crontab` 代わりで最低限必要なのは `Type` と `ExecStart`
|
95
|
+
- `After` や `Requires` で `gitlab` の service unit が動いているときだけバックアップを実行 (runsvdir 経由なので gitlab 全体が正常に動いているかどうかは未確認)
|
96
|
+
|
97
|
+
# timer 作成例
|
98
|
+
|
99
|
+
```
|
100
|
+
# /etc/systemd/system/gitlab-backup.timer
|
101
|
+
[Unit]
|
102
|
+
Description=Backup gitlab
|
103
|
+
|
104
|
+
[Timer]
|
105
|
+
OnCalendar=*-*-* 2,14:00
|
106
|
+
Persistent=true
|
107
|
+
|
108
|
+
[Install]
|
109
|
+
WantedBy=timers.target
|
110
|
+
```
|
111
|
+
|
112
|
+
# timer 作成例 (解説)
|
113
|
+
|
114
|
+
- `Persistent=true` は `anacron` 相当
|
115
|
+
- `crontab` 代わりで最低限必要なのは `OnCalendar` と `WantedBy`
|
116
|
+
|
117
|
+
# OnCalendar
|
118
|
+
|
119
|
+
- `systemd-analyze calendar '*-*-* 2,14:00'` などで `OnCalendar` の指定内容を確認可能
|
120
|
+
- 任意の時刻を基準にするには `faketime` コマンドと組み合わせて `faketime '2021-04-17 16:00' systemd-analyze calendar '*-*-* 2,14:00'`
|
121
|
+
|
122
|
+
# at コマンド代わり
|
123
|
+
|
124
|
+
- `systemd-run --on-active=30 /bin/touch /tmp/foo` で30秒後
|
125
|
+
- `systemd-run --on-active="1h 30m" --unit foo.service` で1時間半後
|
126
|
+
- `systemd-run --on-calendar="2021-04-17 16:00" /bin/touch /tmp/foo` のように日時指定も可能
|
127
|
+
|
128
|
+
# user 権限での systemd
|
129
|
+
|
130
|
+
- 特に設定していなければ `pam_systemd.so` で `/lib/systemd/systemd --user` が起動して、ログアウト時に終了
|
131
|
+
- `systemctl --user` で操作
|
132
|
+
- `loginctl enable-linger someuser` で常に起動 (`loginctl disable-linger someuser` で戻す)
|
133
|
+
|
134
|
+
# 動作確認
|
135
|
+
|
136
|
+
- 自ユーザーなら `systemctl --user status`
|
137
|
+
- 別ユーザーなら `sudo -u someuser XDG_RUNTIME_DIR=/run/user/$(id -u someuser) systemctl --user status`
|
138
|
+
- `sudo -u someuser systemctl --user status` だけだと `Failed to connect to bus: No such file or directory`
|
139
|
+
|
140
|
+
# unit ファイルの場所
|
141
|
+
|
142
|
+
- 普通は `~/.config/systemd/user/` に置く
|
143
|
+
- 全ユーザー共通なら `/etc/systemd/user/` に置くのも可能
|
144
|
+
- 全パスは `systemd.unit(5)` 参照
|
145
|
+
|
146
|
+
# Install の WantedBy
|
147
|
+
|
148
|
+
- system の unit なら `WantedBy=multi-user.target` を使うことが多い
|
149
|
+
- user の unit は `WantedBy=default.target` を代わりに使う
|
150
|
+
|
151
|
+
# unit ファイル例
|
152
|
+
|
153
|
+
```
|
154
|
+
# /home/chatuser/.config/systemd/user/weechat.service
|
155
|
+
[Unit]
|
156
|
+
Description=A WeeChat client and relay service using Tmux
|
157
|
+
After=network.target
|
158
|
+
|
159
|
+
[Service]
|
160
|
+
Type=forking
|
161
|
+
RemainAfterExit=yes
|
162
|
+
ExecStart=/usr/bin/tmux -L weechat new -d -s weechat weechat
|
163
|
+
ExecStop=/usr/bin/tmux -L weechat kill-session -t weechat
|
164
|
+
|
165
|
+
[Install]
|
166
|
+
WantedBy=default.target
|
167
|
+
```
|
168
|
+
|
169
|
+
# unit ファイル例 (解説)
|
170
|
+
|
171
|
+
- マシン起動時に `weechat` を `tmux` の中で自動起動
|
172
|
+
- 手抜きで `tmux` を手動終了したときの処理は省略
|
173
|
+
- 終了してしまったときはマシンを再起動している
|
174
|
+
|
175
|
+
# 動作確認例
|
176
|
+
|
177
|
+
- `sudo -u chatuser XDG_RUNTIME_DIR=/run/user/$(id -u chatuser) systemctl --user status weechat`
|
178
|
+
- `sudo -u chatuser XDG_RUNTIME_DIR=/run/user/$(id -u chatuser) journalctl --user -u weechat`
|
179
|
+
|
180
|
+
# /etc にあった例
|
181
|
+
|
182
|
+
```
|
183
|
+
# ls /etc/systemd/user/sockets.target.wants/
|
184
|
+
dirmngr.socket gpg-agent-browser.socket gpg-agent-extra.socket
|
185
|
+
gpg-agent.socket gpg-agent-ssh.socket
|
186
|
+
# readlink /etc/systemd/user/sockets.target.wants/gpg-agent.socket
|
187
|
+
/usr/lib/systemd/user/gpg-agent.socket
|
188
|
+
# cat /etc/systemd/user/sockets.target.wants/gpg-agent.socket
|
189
|
+
[Unit]
|
190
|
+
Description=GnuPG cryptographic agent and passphrase cache
|
191
|
+
Documentation=man:gpg-agent(1)
|
192
|
+
|
193
|
+
[Socket]
|
194
|
+
ListenStream=%t/gnupg/S.gpg-agent
|
195
|
+
FileDescriptorName=std
|
196
|
+
SocketMode=0600
|
197
|
+
DirectoryMode=0700
|
198
|
+
|
199
|
+
[Install]
|
200
|
+
WantedBy=sockets.target
|
201
|
+
```
|
202
|
+
|
203
|
+
# まとめ
|
204
|
+
|
205
|
+
- crontab の代わりに timer unit + service unit
|
206
|
+
- systemd-run は at の代わりになる
|
207
|
+
- user 権限での systemd は `loginctl enable-linger` で常時起動
|
208
|
+
- `~/.config/systemd/user/` に unit ファイル
|
Binary file
|
metadata
ADDED
@@ -0,0 +1,65 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: rabbit-slide-znz-debian-meeting-202104
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 2021.4.17.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Kazuhiro NISHIYAMA
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2021-04-16 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: rabbit
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 2.0.2
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 2.0.2
|
27
|
+
description: |-
|
28
|
+
[オンライン開催:東京エリア・関西合同Debian勉強会(2021/04/17(土))](https://debianjp.connpass.com/event/208924/)の発表資料です。
|
29
|
+
crontab の代わりに systemd-timer を使う、および user 権限での systemd の話です。
|
30
|
+
email:
|
31
|
+
- zn@mbf.nifty.com
|
32
|
+
executables: []
|
33
|
+
extensions: []
|
34
|
+
extra_rdoc_files: []
|
35
|
+
files:
|
36
|
+
- ".rabbit"
|
37
|
+
- README.md
|
38
|
+
- Rakefile
|
39
|
+
- config.yaml
|
40
|
+
- debian-meeting-systemd.md
|
41
|
+
- pdf/debian-meeting-202104-debian-meeting-systemd.pdf
|
42
|
+
homepage: http://slide.rabbit-shocker.org/authors/znz/debian-meeting-202104/
|
43
|
+
licenses: []
|
44
|
+
metadata: {}
|
45
|
+
post_install_message:
|
46
|
+
rdoc_options: []
|
47
|
+
require_paths:
|
48
|
+
- lib
|
49
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
50
|
+
requirements:
|
51
|
+
- - ">="
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: '0'
|
54
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
55
|
+
requirements:
|
56
|
+
- - ">="
|
57
|
+
- !ruby/object:Gem::Version
|
58
|
+
version: '0'
|
59
|
+
requirements: []
|
60
|
+
rubyforge_project:
|
61
|
+
rubygems_version: 2.7.6
|
62
|
+
signing_key:
|
63
|
+
specification_version: 4
|
64
|
+
summary: systemd 再入門
|
65
|
+
test_files: []
|