Can you please post your crontab entry here?chrisonnas wrote: ↑Sun Nov 21, 2021 5:04 pm For some reason it works from the # shell prompt and not from crontab. Any suggestions?
Check if Plex is running, restart if not?
- OneCD
- Guru
- Posts: 12155
- Joined: Sun Aug 21, 2016 10:48 am
- Location: "... there, behind that sofa!"
Re: Check if Plex is running, restart if not?
-
- Getting the hang of things
- Posts: 50
- Joined: Sat Jan 05, 2019 5:27 pm
Re: Check if Plex is running, restart if not?
Yep, here it is - set to run every 10 mins rather than 5:
This command runs as expected in a terminal window, but restarts plex every 10 mins with cron...
Code: Select all
*/10 * * * * /sbin/curl --silent --insecure --fail --max-time 10 http://127.0.0.1:32400; [[ $? -ne 22 ]] && /etc/init.d/plex.sh restart >/dev/null 2>&1
- OneCD
- Guru
- Posts: 12155
- Joined: Sun Aug 21, 2016 10:48 am
- Location: "... there, behind that sofa!"
Re: Check if Plex is running, restart if not?
Can you please confirm the exit code after running curl on an operational Plex instance?chrisonnas wrote: ↑Tue Nov 23, 2021 4:01 pm This command runs as expected in a terminal window, but restarts plex every 10 mins with cron...
Code: Select all
/sbin/curl --silent --insecure --fail --max-time 10 http://127.0.0.1:32400; echo $?
-
- Getting the hang of things
- Posts: 50
- Joined: Sat Jan 05, 2019 5:27 pm
Re: Check if Plex is running, restart if not?
Yep, sure - I just ran it (wihout "--silent") and got an error code [7] as PMS isnt running properly (confirmed with plexamp app etc):
Running the following succesfully restarted PMS:
Now PMS is running, I get the [22] code returned:
Code: Select all
curl: (7) Failed to connect to 127.0.0.1 port 32400: Connection refused
7
Code: Select all
/sbin/curl --silent --insecure --fail --max-time 10 http://127.0.0.1:32400; [[ $? -ne 22 ]] && /etc/init.d/plex.sh restart >/dev/null
Code: Select all
# /sbin/curl --silent --insecure --fail --max-time 10 http://127.0.0.1:32400; echo $?
22
- OneCD
- Guru
- Posts: 12155
- Joined: Sun Aug 21, 2016 10:48 am
- Location: "... there, behind that sofa!"
Re: Check if Plex is running, restart if not?
Do you get the same return code when using the —silent parameter?
Maybe you’ll need to increase the check frequency, like the OP of this topic did?
Maybe you’ll need to increase the check frequency, like the OP of this topic did?
-
- Getting the hang of things
- Posts: 50
- Joined: Sat Jan 05, 2019 5:27 pm
Re: Check if Plex is running, restart if not?
Yes, the return codes are working at the terminal, checked with "echo $?", but assume that cron is seeing something different. I was wondering if cron is blocked from using curl or its environment generates a different code. After PMS died yesterday and I saw that return code [7] was given, I have changed the logic in the crontab to read
Code: Select all
[[ $? = 7 ]]
If I did that with the [[ $? -ne 22 ]] then it would be restarting every 5 minutes!
-
- Easy as a breeze
- Posts: 413
- Joined: Sun Oct 20, 2013 11:45 pm
- Location: Premnitz, Germany
Re: Check if Plex is running, restart if not?
you could write the return code to a file and check this while it's running via cron, just to see if execution via cron returns something unexpected
NAS (production): TS-1635AX FW: QTS 5.1.4.2596 build 20231128
NAS (backup): TS-1635AX FW: QTS 5.1.4.2596 build 20231128
QTS (SSD): [RAID-1] 2 x 2TB Samsung Evo 860 M.2-Sata
Data (QTier): [RAID-6] 4 x 4TB Samsung 870 QVO Sata
Data (HDD): [RAID-6] 7 x 18TB Exos
RAM: 8 GB (QNAP shipped)
UPS: CyberPower CP900EPFCLCD
BACKUP: 10x4TB WD Red using a USB 3.0 Dock
Usage: SMB with rclone (encrypted)
NAS: TS-873U-RP FW: QTS 5.1.4.2596 build 20231128
Data (SSD): [RAID-10] 4 x 1TB Samsung Evo 860 Sata
RAM: 8 GB (QNAP shipped)
UPS: CyberPower PR2200ELCDRT2U
BACKUP: 4TB Synology DS214 FW: DSM 7.0.41890
Usage: SMB, Backup Domain Controller
NAS (backup): TS-1635AX FW: QTS 5.1.4.2596 build 20231128
QTS (SSD): [RAID-1] 2 x 2TB Samsung Evo 860 M.2-Sata
Data (QTier): [RAID-6] 4 x 4TB Samsung 870 QVO Sata
Data (HDD): [RAID-6] 7 x 18TB Exos
RAM: 8 GB (QNAP shipped)
UPS: CyberPower CP900EPFCLCD
BACKUP: 10x4TB WD Red using a USB 3.0 Dock
Usage: SMB with rclone (encrypted)
NAS: TS-873U-RP FW: QTS 5.1.4.2596 build 20231128
Data (SSD): [RAID-10] 4 x 1TB Samsung Evo 860 Sata
RAM: 8 GB (QNAP shipped)
UPS: CyberPower PR2200ELCDRT2U
BACKUP: 4TB Synology DS214 FW: DSM 7.0.41890
Usage: SMB, Backup Domain Controller
-
- Getting the hang of things
- Posts: 50
- Joined: Sat Jan 05, 2019 5:27 pm
Re: Check if Plex is running, restart if not?
odd. the file says 22!holger_kuehn wrote: ↑Wed Nov 24, 2021 10:39 pm you could write the return code to a file and check this while it's running via cron, just to see if execution via cron returns something unexpected
I've left my crontab entry looking for a code [7] and lets see if that picks up PMS breaking. It was happening nearly daily, so hopefully I will find out soon.