timer

crondの後継

https://rcmdnk.com/blog/2020/10/12/computer-raspberrypi-linux/

serviceファイルとtimerファイルを作成する

[Unit]
Description = My Job
[Service]
Type = oneshot
ExecStart = /path/to/myjob
[Install]
WantedBy = multi-user.target
[Unit]
Description = My Job Timer
[Timer]
OnCalendar =Sun *-*-* 15:06:00
AccuracySec = 1s
[Install]
WantedBy = timers.target

記述ミスがあるとreloadでは反映されずrestartが必要。

sudo systemctl daemon-reload
sudo systemctl enable myjob.timer
sudo systemctl start myjob.timer
systemctl list-timers

systemctlコマンド

NW関連

一覧表示nmcli d
dns 追加nmcli connection modify eno16780032 ipv4.dns 192.168.11.1
NW再起動systemctl restart NetworkManager

主要サービスの再起動

SSHDsystemctl restart sshd.service
httpdsystemctl restart httpd.service
postgressystemctl start postgresql.service

サービスの確認

systemctl status httpd

サービスの有効化

有効systemctl enable sshd.service
無効systemctl disable sshd.service

稼働中サービスの一覧

systemctl list-units --type=service

自動起動の有無

systemctl list-unit-files --type=service

firewall

firewall-cmd --permanent --add-port=任意のポート/tcp

設定の確認

firewall-cmd --list-all

サービスの追加

docker-composeをサービス化

[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

トップ   編集 凍結 差分 履歴 添付 複製 名前変更 リロード   新規 一覧 検索 最終更新   ヘルプ   最終更新のRSS
Last-modified: 2023-06-23 (金) 20:49:25