ããã¯ããªã«ãããããŠæžãããã®ïŒ
systemdã®ãŠãããå®çŸ©ãã¡ã€ã«ãç·šéããéã«ããµã€ãã«ãšãã£ã¿ã³ãã³ãã§çŽæ¥éããŠèšå®ãããããŠããã®ã§ããããã®ãããã®
èãæ¹ãééã£ãŠãããªã®ã§ã¡ã¢ããŠããããšã«ããŸããã
systemctl edit
ã³ãã³ãã§ç·šéããã®ãè¯ãããã§ãã
䜿çšããã³ãã³ã
systemctlã®manããŒãžã¯ãã¡ãã
Ubuntu Manpage: systemctl - Control the systemd system and service manager
ä»åæ±ãçšéãšã³ãã³ãã®å¯Ÿå¿è¡šãã以äžã«èšèŒããŸãã
çšé | 察å¿ããã³ãã³ã | åè |
---|---|---|
ãŠãããå®çŸ©ãã¡ã€ã«ã®å 容ã確èªããã | systemctl cat [ãã¿ãŒã³ïŒãŠãããåïŒ] | ãã©ã°ã¡ã³ããããããã€ã³ãå«ããŠè¡šç€ºãã |
ãŠãããå®çŸ©ãã¡ã€ã«ãç·šéãããïŒããããã€ã³ïŒ | systemctrl edit [ãŠãããå] | ããããã€ã³ãã¡ã€ã«ãäœæãç·šéãã |
ãŠãããå®çŸ©ãã¡ã€ã«ãç·šéãããïŒæ¬äœïŒ | systemctrl edit --full [ãŠãããå] | |
ãŠãããå®çŸ©ãã¡ã€ã«ãæ°èŠäœæããã | systemctrl edit --force --full [ãŠãããå] | |
ãŠãããå®çŸ©ãã¡ã€ã«ããã³ããŒå®çŸ©ã®ããŒãžã§ã³ã«æ»ããã | systemctl revert [ãŠãããå] | ããããã€ã³ãã¡ã€ã«ã¯åé€ããã |
æ°ã«ããæ¹ããããããªãã€ã³ããããã®ã§ãããããã¯ããããèŠãŠãããŸãã
ç°å¢
ä»åã®ç°å¢ã¯ããã¡ãã
$ lsb_release -a No LSB modules are available. Distributor ID: Ubuntu Description: Ubuntu 22.04.4 LTS Release: 22.04 Codename: jammy $ uname -smvrpio Linux 5.15.0-101-generic #111-Ubuntu SMP Tue Mar 5 20:16:58 UTC 2024 x86_64 x86_64 x86_64 GNU/Linux
Ubuntu Linux 22.04 LTSã§ãã
ãŸãããé¡ã®éœåäžDockerã䜿çšããŸãã
$ docker version Client: Docker Engine - Community Version: 26.0.0 API version: 1.45 Go version: go1.21.8 Git commit: 2ae903e Built: Wed Mar 20 15:17:48 2024 OS/Arch: linux/amd64 Context: default Server: Docker Engine - Community Engine: Version: 26.0.0 API version: 1.45 (minimum version 1.24) Go version: go1.21.8 Git commit: 8b79278 Built: Wed Mar 20 15:17:48 2024 OS/Arch: linux/amd64 Experimental: false containerd: Version: 1.6.28 GitCommit: ae07eda36dd25f8a1b98dfbf587313b99c0190bb runc: Version: 1.1.12 GitCommit: v1.1.12-0-g51d5e94 docker-init: Version: 0.19.0 GitCommit: de40ad0
ãé¡
Ubuntu Linux 22.04 LTSã«ã€ã³ã¹ããŒã«ããDockerã«å¯ŸããŠãç°å¢å€æ°ã§ãããã·ãèšå®ããããšãããé¡ã§ãã£ãŠã¿ãããšæããŸãã
ãªãããããã·ãµãŒããŒã«ã€ããŠã¯çç¥ããŸãããhttp://localhost:8080
ã§ã¢ã¯ã»ã¹ã§ãããã®ãšããŸãã
systemdã®ãŠãããå®çŸ©ãã¡ã€ã«ã確èªããïŒæ¬äœã®ãã¡ã€ã«ã®ã¿ïŒ
systemdã®ãŠãããå®çŸ©ãã¡ã€ã«ã¯ãsystemctl cat [ãŠãããå]
ã³ãã³ãã§ç¢ºèªã§ããŸãã管çè
æš©éã¯äžèŠã§ãã
$ systemctl cat docker # /lib/systemd/system/docker.service [Unit] Description=Docker Application Container Engine Documentation=https://docs.docker.com After=network-online.target docker.socket firewalld.service containerd.service time-set.target Wants=network-online.target containerd.service Requires=docker.socket [Service] Type=notify # the default is not to use systemd for cgroups because the delegate issues still # exists and systemd currently does not support the cgroup feature set required # for containers run by docker ExecStart=/usr/bin/dockerd -H fd:// --containerd=/run/containerd/containerd.sock ExecReload=/bin/kill -s HUP $MAINPID TimeoutStartSec=0 RestartSec=2 Restart=always # Note that StartLimit* options were moved from "Service" to "Unit" in systemd 229. # Both the old, and new location are accepted by systemd 229 and up, so using the old location # to make them work for either version of systemd. StartLimitBurst=3 # Note that StartLimitInterval was renamed to StartLimitIntervalSec in systemd 230. # Both the old, and new name are accepted by systemd 230 and up, so using the old name to make # this option work for either version of systemd. StartLimitInterval=60s # Having non-zero Limit*s causes performance problems due to accounting overhead # in the kernel. We recommend using cgroups to do container-local accounting. LimitNPROC=infinity LimitCORE=infinity # Comment TasksMax if your systemd version does not support it. # Only systemd 226 and above support this option. TasksMax=infinity # set delegate yes so that systemd does not reset the cgroups of docker containers Delegate=yes # kill only the docker process, not all processes in the cgroup KillMode=process OOMScoreAdjust=-500 [Install] WantedBy=multi-user.target
ã³ã¡ã³ãã§ããŠãããå®çŸ©ãã¡ã€ã«ã®ãã¹ãæžãããŠããŸãã
# /lib/systemd/system/docker.service
diffããšã£ãŠã¿ããšããã®ã³ã¡ã³ã以å€ã¯å 容ã¯åãã§ãã
$ diff <(systemctl cat docker) /lib/systemd/system/docker.service 1d0 < # /lib/systemd/system/docker.service
systemdã®ãŠãããå®çŸ©ãã¡ã€ã«ãç·šéããïŒããããã€ã³ãã¡ã€ã«ïŒ
次ã«ãsystemdã®ãŠãããå®çŸ©ãã¡ã€ã«ãç·šéããŠã¿ãŸãã
ãã®æããœãããŠã§ã¢ã®æäŸå
ã®ãŠãããå®çŸ©ãã¡ã€ã«ãçŽæ¥ç·šéããã®ã§ã¯ãªããããããã€ã³ãã¡ã€ã«ã§ãªãŒããŒã©ã€ãããã®ãè¯ããš
ãããŠããŸãã
ããããã€ã³ãã¡ã€ã«ãšããã®ã¯ããŠãããå®çŸ©ãfoo.service
ã ã£ãå Žåã«foo.service.d
ãã£ã¬ã¯ããªé
äžã«é
眮ãããã¡ã€ã«ã§ãã
ããã¯ãsystemctl edit [ãŠãããå]
ã§è¡ããŸãã
$ sudo systemctl edit docker
ã¡ãªã¿ã«ããã®æUbuntu Linux 22.04 LTSã ãšnanoãèµ·åããŠå°ã£ãã®ã§ãæ°ã«ãªã人ã¯ä»¥äžã®ã³ãã³ãã§å¥œã¿ã®ãšãã£ã¿ãŒãæå®ããããã«
ããŠãã ããã
$ sudo update-alternatives --config editor
systemctl edit
ãå®è¡ãããšã以äžã®ããã«ã³ã¡ã³ãã¢ãŠããããå
ã®å
容ã衚瀺ãããã®ã§ããã¡ããåèã«ããããã€ã³ãã¡ã€ã«ã
äœæããŸãããã
### Editing /etc/systemd/system/docker.service.d/override.conf ### Anything between here and the comment below will become the new contents of the file ### Lines below this comment will be discarded ### /lib/systemd/system/docker.service # [Unit] # Description=Docker Application Container Engine # Documentation=https://docs.docker.com # After=network-online.target docker.socket firewalld.service containerd.service time-set.target # Wants=network-online.target containerd.service # Requires=docker.socket # # [Service] ãçç¥ã
ä»åã¯ããããªæãã®ãã¡ã€ã«ã«ããŸããã
[Service] Environment="http_proxy=http://localhost:8080" Environment="https_proxy=http://localhost:8080"
ãã¡ã€ã«åã¯ãããã©ã«ãã§override.conf
ã«ãªããŸããä»åã¯/etc/systemd/system/docker.service.d/override.conf
ã«ãªããŸããã
ããšã¯åèµ·åããã°å€æŽãåæ ãããŸãã
$ sudo systemctl restart docker
ããã§ãsystemctl edit
ã®åŸã«systemctl daemon-reload
ã¯èŠããŸããã
ãã®æå³ã§ããsystemctl edit
ã䜿ãã¹ããªæ°ãããŸããâŠã
systemdã®ãŠãããå®çŸ©ãã¡ã€ã«ã確èªããïŒæ¬äœã®ãã¡ã€ã«ïŒããããã€ã³ãã¡ã€ã«ïŒ
ãã®ç¶æ
ã§ãsystemctl cat
ã§ç¢ºèªããŠã¿ãŸãã
$ systemctl cat docker
ããããã€ã³ãã¡ã€ã«å«ããŠè¡šç€ºãããŠããŸãã
# /lib/systemd/system/docker.service [Unit] Description=Docker Application Container Engine Documentation=https://docs.docker.com After=network-online.target docker.socket firewalld.service containerd.service time-set.target Wants=network-online.target containerd.service Requires=docker.socket [Service] Type=notify # the default is not to use systemd for cgroups because the delegate issues still # exists and systemd currently does not support the cgroup feature set required # for containers run by docker ExecStart=/usr/bin/dockerd -H fd:// --containerd=/run/containerd/containerd.sock ExecReload=/bin/kill -s HUP $MAINPID TimeoutStartSec=0 RestartSec=2 Restart=always # Note that StartLimit* options were moved from "Service" to "Unit" in systemd 229. # Both the old, and new location are accepted by systemd 229 and up, so using the old location # to make them work for either version of systemd. StartLimitBurst=3 # Note that StartLimitInterval was renamed to StartLimitIntervalSec in systemd 230. # Both the old, and new name are accepted by systemd 230 and up, so using the old name to make # this option work for either version of systemd. StartLimitInterval=60s # Having non-zero Limit*s causes performance problems due to accounting overhead # in the kernel. We recommend using cgroups to do container-local accounting. LimitNPROC=infinity LimitCORE=infinity # Comment TasksMax if your systemd version does not support it. # Only systemd 226 and above support this option. TasksMax=infinity # set delegate yes so that systemd does not reset the cgroups of docker containers Delegate=yes # kill only the docker process, not all processes in the cgroup KillMode=process OOMScoreAdjust=-500 [Install] WantedBy=multi-user.target # /etc/systemd/system/docker.service.d/override.conf [Service] Environment="http_proxy=http://localhost:8080" Environment="https_proxy=http://localhost:8080"
æ¬äœã®ãŠãããå®çŸ©ãã¡ã€ã«ãç·šéãã
次ã¯ãæ¬äœã®ãŠãããå®çŸ©ãã¡ã€ã«ãç·šéããŠã¿ãŸãã
ãŸãsystemctl edit
ã§ããããã€ã³ãã¡ã€ã«ã以äžã®ããã«å€æŽã
/etc/systemd/system/docker.service.d/override.conf
[Service] Environment="http_proxy=http://localhost:8080" #Environment="https_proxy=http://localhost:8080"
ã³ã¡ã³ãã¢ãŠãããæ¹ã¯ãæ¬äœã®ãŠãããå®çŸ©ãã¡ã€ã«ã«è¿œå ããããšã«ããŸãããã
ãã®å Žåã«äœ¿ãã³ãã³ãã¯ãsystemctl edit --full
ã§ãã
$ sudo systemctl edit --full docker
--full
ãªãã·ã§ã³ãä»ãããšãæ¬äœã®ãŠãããå®çŸ©ãã¡ã€ã«ãç·šéã§ããŸããä»åã¯ã以äžã®ããã«å€æŽã
ãçç¥ã [Service] Type=notify # the default is not to use systemd for cgroups because the delegate issues still # exists and systemd currently does not support the cgroup feature set required # for containers run by docker ExecStart=/usr/bin/dockerd -H fd:// --containerd=/run/containerd/containerd.sock ExecReload=/bin/kill -s HUP $MAINPID TimeoutStartSec=0 RestartSec=2 Restart=always Environment="https_proxy=http://localhost:8080" ãçç¥ã
ããšã¯åèµ·åããã°å€æŽãåæ ãããŸãã
$ sudo systemctl restart docker
å€æŽå 容ãå ã«æ»ã
ãããŸã§ã§ãã€ã³ã¹ããŒã«æç¹ã®ãŠãããå®çŸ©ãã¡ã€ã«ãšã¯ããã®ãããªå·®ã«ãªããŸããã
$ diff <(systemctl cat docker) /lib/systemd/system/docker.service 1d0 < # /etc/systemd/system/docker.service 18a18 > Environment="http_proxy=http://localhost:8080" 49,53d48 < < # /etc/systemd/system/docker.service.d/override.conf < [Service] < Environment="http_proxy=http://localhost:8080" < #Environment="https_proxy=http://localhost:8080"
ãããå
ã«æ»ãã«ã¯ãsystemctl revert
ãå®è¡ããŸãã
$ sudo systemctl revert docker
å®è¡ãã°ã
Removed /etc/systemd/system/docker.service.d/override.conf. Removed /etc/systemd/system/docker.service.d. Removed /etc/systemd/system/docker.service.
å·®åããªããªããŸããã
$ diff <(systemctl cat docker) /lib/systemd/system/docker.service 1d0 < # /lib/systemd/system/docker.service
æ°ãããŠãããå®çŸ©ãã¡ã€ã«ãäœæãã
systemctl
ã³ãã³ãã§æ°ãããŠãããå®çŸ©ãã¡ã€ã«ãäœæããå Žåã¯ãsystemctl edit --force --full
ã³ãã³ãã䜿ããŸãã
$ sudo systemctl edit --force --full my-service
ãã®å Žåã/etc/systemd/system
é
äžã«ãã¡ã€ã«ãäœæããããšããŸãã
èªåã§çšæãããŠãããå®çŸ©ãã¡ã€ã«ãrevertãããšïŒ
ãšããã§ãèªåã§çšæãããŠãããå®çŸ©ãã¡ã€ã«ãsystemctl revert
ãããšã©ããªãã®ã§ãããïŒ
äœæããŠã¿ãŸãã
$ sudo systemctl edit --force --full my-httpd
ãããªå 容ã«ããŠã¿ãŸããã
$ systemctl cat my-httpd # /etc/systemd/system/my-httpd.service [Unit] Description=My Simple Http Server After=networ-online.target Wants=network-online.target [Service] Type=simple ExecStart=python3 -m http.server --directory /tmp [Install] WantedBy=multi-user.target
èµ·åããããšã確èªã
$ sudo systemctl start my-httpd
systemctl revert
ããŠã¿ãŸãã
$ sudo systemctl revert my-httpd
ç¹ã«ãªã«ã衚瀺ãããŸãããsystemctl cat
ã§ãããã®ãŸãŸäžèº«ãæ®ã£ãŠããŸãã
$ systemctl cat my-httpd # /etc/systemd/system/my-httpd.service [Unit] Description=My Simple Http Server After=networ-online.target Wants=network-online.target [Service] Type=simple ExecStart=python3 -m http.server --directory /tmp [Install] WantedBy=multi-user.target
ããããã®ã¯ãã§ãmanããŒãžãèŠããšãåé€ãããªãããšæžãããŠããŸãã
Note that if a unit file has no vendor-supplied version (i.e. is only defined below /etc/systemd/system or /run/systemd/system, but not in a unit file stored below /usr/), then it is not removed. Also, if a unit is masked, it is unmasked.
Ubuntu Manpage: systemctl - Control the systemd system and service manager
ã¡ãªã¿ã«ãèªåã§çšæãããŠãããå®çŸ©ãã¡ã€ã«ã«ãsystemctl edit
ã§ããããã€ã³ãã¡ã€ã«ãäœæããããšãã§ããŸãã
ãã®ãã¿ãŒã³ã¯ããŸã䜿ããªãæ°ãããŸããã
ãããã«
systemdã®ãŠãããå®çŸ©ãã¡ã€ã«ã確èªãç·šéããããŠã€ã³ã¹ããŒã«ããæç¹ã®ãã®ã«æ»ãæ¹æ³ã調ã¹ãŠã¿ãŸããã
ä»ãŸã§ãµã€ãã«ãšãã£ã¿ãŒã§ç·šéããŠããã®ã§ããããã£ãŠã³ãã³ãã§æäœã§ããããšãç¥ããŸããã§ããâŠã
ã³ãã³ãã®manããŒãžãšãèŠãªããšãã¡ã§ããâŠã