#author("2023-06-07T01:42:15+00:00","default:wikiadmin","wikiadmin") #author("2023-06-23T11:49:25+00:00","default:wikiadmin","wikiadmin") -CentOS7からサービスの管理ががらりと変わった。 *timer [#ge639949] crondの後継 https://rcmdnk.com/blog/2020/10/12/computer-raspberrypi-linux/ serviceファイルとtimerファイルを作成する -/etc/systemd/system/myjob.service [Unit] Description = My Job [Service] Type = oneshot ExecStart = /path/to/myjob [Install] WantedBy = multi-user.target -/etc/systemd/system/myjob.timer [Unit] Description = My Job Timer [Timer] OnCalendar =Sun *-*-* 15:06:00 AccuracySec = 1s [Install] WantedBy = timers.target 記述ミスがあるとreloadでは反映されずrestartが必要。 -タイマー有効化する(startしないとだめ!) sudo systemctl daemon-reload sudo systemctl enable myjob.timer sudo systemctl start myjob.timer -タイマーの状況確認(-allで無効なものも含めて表示) systemctl list-timers *systemctlコマンド [#a7b24fc5] **NW関連 [#raa50e9d] |一覧表示|nmcli d|| |dns 追加|nmcli connection modify eno16780032 ipv4.dns 192.168.11.1|| |NW再起動|systemctl restart NetworkManager|| **主要サービスの再起動 [#b12ffe30] |SSHD|systemctl restart sshd.service| |httpd|systemctl restart httpd.service| |postgres|systemctl start postgresql.service| **サービスの確認 [#zeb0637e] |systemctl status httpd| **サービスの有効化 [#x49292d5] |有効|systemctl enable sshd.service| |無効|systemctl disable sshd.service| **稼働中サービスの一覧 [#cd71b9a6] systemctl list-units --type=service **自動起動の有無 [#l21cb2c1] systemctl list-unit-files --type=service *firewall [#p33d3942] firewall-cmd --permanent --add-port=任意のポート/tcp **設定の確認 [#d9b3951e] firewall-cmd --list-all *サービスの追加 [#n46d6e51] **docker-composeをサービス化 [#v2ee00a6] -/etc/systemd/system/docker-compose-service@.service [Unit] Description=%i managed by docker-compose Requires=docker.service After=docker.service [Service] Type=simple Environment=COMPOSE_FILE=/root/infra/docker/%i/docker-compose.yml ExecStartPre=-/usr/bin/docker-compose -f ${COMPOSE_FILE} down --volumes ExecStart=/usr/bin/docker-compose -f ${COMPOSE_FILE} up ExecStop=/usr/bin/docker-compose -f ${COMPOSE_FILE} down --volumes [Install] WantedBy=multi-user.target -サービス有効化 sudo systemctl enable --now docker-compose-service@mariadb