Jellyfin not available anymore, 502 bad gateway

What app is this about, and its version: Jellyfin 10.11.8~ynh1
What YunoHost version are you running: 12.1.39 (stable)
What type of hardware are you using: Other(?)

Describe your issue

Today in the morning I got aware that jellyfin is not working anymore.

Scrolling through the recent logs I recognised that the jellyfin.service is not running properly. It is actually starting every few seconds, but never succesfully.
I tried to start it manually, no success.
I tried to restore a backup from 4 days ago, no success.
The only changes I did, have been the previous upgrades yunohost suggested me in the last couple of days. But I didn’t upgrade jellyfin itself.

Me and especially my kid (no more audiobooks playable :wink: ) highly apprecciate your help, THANKS

Share relevant logs or error messages

Hello,

Can you explain this ?

The only changes I did, have been the previous upgrades yunohost suggested me in the last couple of days. But I didn’t upgrade jellyfin itself.

The log show : Microsoft.Data.Sqlite.SqliteException (0x80004005): SQLite Error 26: **‘file is not a database’.** Maybe de data base is corrupted.

Try ton run the integrity check on the database used by Jellyfin.
You can do it this way :

root@redzic:~# cd /home/yunohost.app/jellyfin/data
root@redzic:/home/yunohost.app/jellyfin/data# ls -lh
total 31M
drwxr-xr-x  2 jellyfin jellyfin 4.0K May  9 14:45 attachments
-rw-r--r--  1 jellyfin jellyfin   35 May  9 14:45 device.txt
-rw-r--r--  1 jellyfin jellyfin  14M May  9 17:18 jellyfin.db
-rw-r--r--  1 jellyfin jellyfin  12K May  9 14:45 library.db
-rw-r--r--  1 jellyfin jellyfin  14M May  9 14:45 library.db.old
-rw-r--r--  1 jellyfin jellyfin  32K May  9 14:45 library.db-shm
-rw-r--r--  1 jellyfin jellyfin    0 May  9 14:45 library.db-wal
drwxr-xr-x  2 jellyfin jellyfin 4.0K May  9 14:45 playlists
drwxr-xr-x  2 jellyfin jellyfin 4.0K May  9 14:45 ScheduledTasks
-rw-r--r--  1 jellyfin jellyfin 3.1M May  9 14:45 splashscreen.png
drwxr-xr-x  2 jellyfin jellyfin 4.0K May  9 14:45 SQLiteBackups
drwxr-xr-x 23 jellyfin jellyfin 4.0K May  9 14:45 subtitles
root@redzic:/home/yunohost.app/jellyfin/data# sqlite3 jellyfin.db "PRAGMA integrity_check;"
ok
root@redzic:/home/yunohost.app/jellyfin/data# sqlite3 library.db "PRAGMA integrity_check;"
ok
root@redzic:/home/yunohost.app/jellyfin/data# sqlite3 library.db.old "PRAGMA integrity_check;"
ok
root@redzic:/home/yunohost.app/jellyfin/data# 

It will not solve your problem but a least you will see if the database file is healthy.

The command “sqlite3 jellyfin.db …” gets the output: Error: in prepare, file is not a database (26)

The other two commands get an “ok”

What I meant with “only changes” was: I did some system upgrades in the web-interface, but no app upgrade (either for jellyfin or any other installed app).

I assume the output “Error: in prepare, file is not a database (26)” indicates that my database is not healthy, which means, I have to reinstall jellyfin from scratch?

Thanks a lot.

In the meantime I tried a different approach:

Uninstalling Jellyfin, and installing it again (not restoring from a backup), still the same failure 502 Bad gateway and also the logs contain the same issues

The system is a Raspi 5 with 8GB RAM by the way

If the integrity check do not gives you “ok”, it means indeed that there is something wrong with your database.

Keep in mind that even if you uninstall an app, all the data will still be here.
I removed mopidy months ago but all the data is still here :

root@redzic:/home/yunohost.app/mopidy# ls -l
total 8
drwxr-x--- 3 988 www-data 4096 Feb 11  2025 cache
drwxr-x--- 6 988 www-data 4096 Nov 20  2022 data


You can uninstall jellyfin, remove the directory /home/yunohost.app/jellyfin and then reinstall the app.

NB : please note that I a not a very advance user when it comes to database thing so wait the answer from someone else. What I told is the way I would do it on my personnal machine.

Hi thanks for your help.

It seemed that also in former backups there have been some issues.

So i had to delete app and folder and start with a fresh install of the app.

Thank you for your support

@md27 Keep in mind that sometimes things can happen and databases can be corrupted. You should follow the 3-2-1 backup method and once you have your jellyfin setup the way you like it, make a fresh backup of the web and plugins folders. Make a database backup within Jellyfin UI then copy the database backup file to your backup directory and store in a compressed file in case something happens and you need to restore. This is just good practice because you never know what may happen. Just some friendly advice so you don’t lose everything in the future and have to start from scratch. Cause that sucks when you have to do it multiple times

Thanks for your reply.
I’m actually trying do backup everyday via a Cronjob following the advices on jellywatch.app

I have actually some difficulties, as far as I understood it correctly, there is no config directory of jellyfin on yunohost.

But I’m constantly backing up the whole /home/yunohost.app/jellyfin/data directory.

If you recommend something else I’m glad to hear from you.

As far as the alternative “borg backing up jellyfin” was not the best solution in the past I had to change my backup setup…

Jellyfin Watch is giving you some good information as well as the commands to complete the activity. Here is my personal strategy using the 3-2-1 backup strategy, have 3 copies of your data in at least 2 different locations with 1 copy being offline (such as an external USB drive). Make sure your media files are stored on a separate storage volume or backend. Once you have Jellyfin configured your configuration shouldn’t change all that much. I personally don’t do daily backups of JF. I do weekly backups for my primary OS and monthly backups for my apps such as JF. I also have my media storage located on a different storage backend than my primary VPS. This separation prevents you from losing or changing your media files unnecessarily in the event of a failure.

Jellyfin specifically, it is overkill to backup the entire directory and it is not good practice as native installs of Jellyfin keep different configuration files in different places. Web, database and plugin folders are usually in /var/lib/jellyfin directory while database backups and system Config files are kept in /etc/jellyfin directory. This is why it is good practice to create a restore backup once you have everything together and configured the way you like. Then as you use JF, at the end of every month you should create a new backup so you always have a recent version of new config changes. I rotate mine out every 3 months. This means that you always keep the original restore backup plus three monthly date-stamped copies. This allows you to be able to go back in time if something breaks. When you reach the 4th month of backups, then you delete the first date-stamped backup and keep rotating like that. This can also be automated using crontab, although it will take you 3 separate entries to accomplish

The bad gateway sounds like the JF services stopped for some reason and I have experienced this with other services on Yunohost platform where services don’t restart like they are suppose to on reboot. My custom solution to that issue is a crontab entry using the @reboot sleep 30 && /path to restart those services once the core system is back up and running. This way i don’t have to do it manaully in webadmin>>services. Hope this helps

As far as I can see it, there is neither a directory /var/jellyfin nor /etc/jellyfin on my yunohost server. Am I missing here something?

That’s why i choose to backup the entire directory. I may reduce from daily to weekly or even monthly.

Do you have any hints where yunohost stores jellyfin’s config files, which would be essential to backup, according to your post.

Actually jellyfin.service wasn’t able to start, whether via CLI nor via Web-Interface. My assumption was, because of the broken database.

Jellyfin doesn’t store it’s data or configuration the the typical Yunohost directory /var/www instead it uses standard native install directories.

Data Directory: /var/lib/jellyfin

Configuration: /etc/jellyfin

to access these you will have to use a terminal with the sudo command.

First, ensure you are in the root directory by using this command sudo cd /

next, change directory by sudo cd /var/lib/jellyfin

you should be able to use the lscommand to view files in the directory

repeat this process for the config directory

sudo cd /etc/jellyfin

this verifies the directories exist and then you will have the path to backup

Note: Different systems locate these files in different places. I use Debian 12 and this is accurate for that system. But other systems might locate the data directory in (for example) /home/yunohost.app/dataso you would need to determine that location. You can also look in admin section of JF and it should tell you the paths for the different file locations

You would need to look at the log file to find out why it is failing to start using this command

sudo journalctl -xe -u jellyfin.service

Thank you very much. I will try to find these directories in the next couple of days.

I’m gonna keep that in mind for the next time, actually it works.

I logged in as root via SSH and could not find any of your two written directories.

But a look in the admin section showed me the JF directories.

Program files (in German “Programmdaten”) are stored in /home/yunohost.app/jellyfin

So I assume it makes sense to backup that directory every couple of days, if I got your advices in your former posts the right way.

Thanks a lot for your help

I’ve not read everything but to be clear:

Before latest version, Jellyfin was installed via .deb in different locations than the usual YunoHost ones.

Latest version 10.11.8~ynh1 installs Jellyfin in /var/www/jellyfin and the data directory is /home/yunohost.app/jellyfin

Thanks a lot. So it makes sense to backup the whole directory.

Thank you very much