Linux
即使在 systemd 中使用 Restart=no,我嘗試執行的 linux 服務也不會終止並重新啟動
Jul 01 16:47:17 server start.sh[21353]: Operation successfully completed Jul 01 16:47:17 server start.sh[21353]: Saving 5 titles into directory ./raw Jul 01 17:17:48 server start.sh[21353]: 5 titles saved Jul 01 17:17:48 server start.sh[21353]: Copy complete. 5 titles saved. Jul 01 17:17:48 server start.sh[21353]: title_t00.mkv Jul 01 17:17:49 server start.sh[21353]: MOVIE Jul 01 17:17:50 server systemd[1]: Started DVD-Ripper. Jul 01 17:17:50 server start.sh[8906]: MakeMKV v1.14.4 linux(x64-release) started Jul 01 17:17:52 server start.sh[8906]: Failed to open disc Jul 01 17:17:52 server start.sh[8906]: Movie.mkv Jul 01 17:17:52 server start.sh[8906]: rm: cannot remove '*.mkv': No such file or directory
如圖所示,即使我在 .service 文件中有 Restart=no ,該服務也會繼續重新啟動:
[Unit] Description=DVD-Ripper [Service] ExecStart=/mnt/DVD/MakeMKV/start.sh KillMode=mixed SendSIGKILL=no User=root Restart=no
有誰知道為什麼會發生這種情況?
這是來自使用 journalctl -u DVD-Ripper 的日誌
Jul 01 16:46:30 server start.sh[21353]: MakeMKV v1.14.4 linux(x64-release) started Jul 01 16:46:33 server start.sh[21353]: Using direct disc access mode Jul 01 16:46:39 server start.sh[21353]: Title #1 was added (25 cell(s), 0:47:07) Jul 01 16:46:40 server start.sh[21353]: Title #1/0/1 was added (5 cell(s), 0:24:19) Jul 01 16:46:41 server start.sh[21353]: Title #1/0/2 was added (5 cell(s), 0:24:18) Jul 01 16:46:41 server start.sh[21353]: Title #2 was added (25 cell(s), 0:47:07) Jul 01 16:46:41 server start.sh[21353]: Title #3 was added (5 cell(s), 0:24:19) Jul 01 16:46:41 server start.sh[21353]: Title #4 was added (5 cell(s), 0:24:18) Jul 01 16:47:08 server start.sh[21353]: Title #7 was added (5 cell(s), 0:04:59) Jul 01 16:47:08 server start.sh[21353]: Title #8 was added (5 cell(s), 0:04:59) Jul 01 16:47:08 server start.sh[21353]: Title #9 has length of 36 seconds which is less tha Jul 01 16:47:08 server start.sh[21353]: Title #10 has length of 53 seconds which is less th Jul 01 16:47:09 server start.sh[21353]: Title #11 has length of 26 seconds which is less th Jul 01 16:47:09 server start.sh[21353]: Title #12 was added (1 cell(s), 0:02:22) Jul 01 16:47:09 server start.sh[21353]: Title #13 has length of 99 seconds which is less th Jul 01 16:47:09 server start.sh[21353]: Title #14 has length of 25 seconds which is less th Jul 01 16:47:10 server start.sh[21353]: Title #15 has length of 111 seconds which is less t Jul 01 16:47:10 server start.sh[21353]: Title #16 has length of 62 seconds which is less th Jul 01 16:47:10 server start.sh[21353]: Title #17 has length of 33 seconds which is less th Jul 01 16:47:10 server start.sh[21353]: Title 1 in VTS 3 is equal to title 4 and was skippe Jul 01 16:47:11 server start.sh[21353]: Title 2 in VTS 3 is equal to title 4 and was skippe Jul 01 16:47:11 server start.sh[21353]: Title 3 in VTS 3 is equal to title 4 and was skippe Jul 01 16:47:11 server start.sh[21353]: Title 4 in VTS 5 is equal to title 3 and was skippe Jul 01 16:47:17 server start.sh[21353]: Operation successfully completed Jul 01 16:47:17 server start.sh[21353]: Saving 5 titles into directory ./raw Jul 01 17:17:48 server start.sh[21353]: 5 titles saved Jul 01 17:17:48 server start.sh[21353]: Copy complete. 5 titles saved. Jul 01 17:17:48 server start.sh[21353]: title_t00.mkv Jul 01 17:17:49 server start.sh[21353]: MOVIE Jul 01 17:17:50 server systemd[1]: Started DVD-Ripper. Jul 01 17:17:50 server start.sh[8906]: MakeMKV v1.14.4 linux(x64-release) started Jul 01 17:17:52 server start.sh[8906]: Failed to open disc Jul 01 17:17:52 server start.sh[8906]: MOVIE.mkv Jul 01 17:17:52 server start.sh[8906]: rm: cannot remove '*.mkv': No such file or directory
這是文件中的 ExecStart:
#!/bin/bash cd /mnt/DVD/MakeMKV/ makemkvcon mkv disc:0 all ./raw cd ./raw file=$(ls -S | head -1) echo $file mv "$file" ./final rm *.mkv mv ./final/* ./ DVD_NAME=$(udevadm info -n sr1 -q property | sed -n 's/^ID_FS_LABEL=//p') echo $DVD_NAME mv ./*.mkv ./$DVD_NAME.mkv eject sr1
這是觸發器:
KERNEL=="sr1", ACTION=="change",ENV{ID_CDROM_MEDIA_DVD}="1", ENV{ID_CDROM_MEDIA_STATE}!="blank", RUN+="/mnt/DVD/MakeMKV/trigger.sh"
trigger.sh 包含:
systemctl start DVD-Ripper
編輯 - UDEV 觸發器在插入和移除時都會觸發。如何修改觸發器以僅檢查 DVD 插入?
謝謝您的幫助。我最終通過修改我的 trigger.sh 文件來解決這個問題,並使 udev 觸發器保持不變。這是 trigger.sh 中的內容:
#!/bin/bash cd /mnt/DVD/MakeMKV/ info=$(blkid -o value -s TYPE /dev/sr1) type=$(echo 'udf') echo $info echo $type if [ "$info" == "$type" ] then systemctl start DVD-Ripper fi
它檢查類型並檢查它是否是 udf。$info 如果沒有插入 dvd 則返回空白,插入時等於“udf”,因此插入時,它使 if 語句為真。
謝謝您的幫助!