Installing Emby Server from Repository on Centos 7 / RHEL (UPDATED)

Last Updated on

For whatever line of reason, the Emby download site does not list repository options. Rather, it provides a location to manually download rpm files for local installation; for an application that is frequently (relatively) updated this is not an ideal solution.  I’ve found a method that seems to work:

1
2
3
4
5
6
7
8
9
yum install -y epel-release
cd /etc/yum.repos.d/
wget http://download.opensuse.org/repositories/home:emby/CentOS_7/home:emby.repo
yum install -y emby-server
systemctl start emby-server
systemctl enable emby-server
systemctl status emby-server
firewall-cmd --zone=public --add-port=8096/tcp --permanent
firewall-cmd --reload

So this will install emby from the command line…however, this repository is un-maintained so we must update the installation with the latest version. For whatever reason, this is the situation but there is a script that can be executed via chron to keep your install up to date written in python located here: https://github.com/doonze/EmbyUpdate

EmbyUpdate

A python script for automatically updating Emby Server to the latest version on Linux distros.

This script has been tested with python 2.7 and 3+. I suggest using python 3, it always tries python 3 commands first. If those fail it falls back to python 2 commands. In the end it doesn’t matter, it runs the same on both. However if you run it with 3 there won’t be behind the scenes exceptions happening. If you don’t have 3, or have mapped 3 to python instead of python3 you may get some chatter from the app. It was tested and developed on Debian 9. I haven’t tested it on any other distro but it should work fine on Ubuntu and Mint for sure, or any other Debian based distro. It has also been coded (but not tested) to work with several other distor’s listed below.

  • Backup your server before doing anything!! Install the Emby backup/restore plugin and get a good backup!
  • It’s possiable to loose your settings if you are switching from a repo version to the standalone version this script installs. So make sure you have that backup!
  • If switching from repo version make sure you uninstall the repo version first (apt remove emby-server or your disto’s process) or your next distro repo upgrade could switch you back to repo version. MAKE SURE YOU HAVE A BACKUP!!

I have edited line #158 of the below script to prevent yum from prompting during the upgrade process.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
#!/usr/bin/env python
# This Python file uses the following encoding: utf-8
# EmbyUpdate Version 2.2 Beta
import sys
import os
import json
import requests
import os.path
import time
import argparse
import subprocess

# First we're going to force the working path to be where the script lives
os.chdir(sys.path[0])

# Sets the version # for the conmand line -v/--version response
versionnum = "2.2 Beta"

# Just to make python happy
returncode = 0

# This sets up the comand line arguments
parser = argparse.ArgumentParser(description="An updater for Emby Media Player",prog='EmbyUpdate')
parser.add_argument('-c','--config', action='store_true', help='Runs the config updater',required=False)
parser.add_argument('-v','--version', action='version', version='%(prog)s ' + versionnum,help='Displays version number')
args = parser.parse_args()

# If the user hasn't used the -c/--config command line argument this will test to see if the config file exist. If it doesn't
# it will prompt the user to run the config tool from the command line. This only needs done once.
if args.config == False:
if not os.path.isfile("config.ini"):
print("")
print("Config file doesn't exist! Likely this is your first time running the script. You MUST run the script with option -c or --config to continue. This only has to be done once.")
print("")
sys.exit()

# Here we try python3 configparser import. If that fails it means user is running python2. So we import
# the python2 ConfigParser instead
try:
import configparser
config = configparser.ConfigParser()
python = '3'
if args.config == True:
print("")
print("Config update started....")
print("")
returncode = subprocess.call("python3 configupdate.py",shell=True)
if returncode > 1:
returncode = subprocess.call("python configupdate.py",shell=True)
except ImportError:
import ConfigParser
config = ConfigParser.ConfigParser()
python = '2'
if args.config == True:
print("")
print("Config update started....")
print("")
returncode = subprocess.call("python configupdate.py",shell=True)

# Here we test to see if the called subprocess above got a return code. If the return code is 1 then
# the entire process is exited and no updates will be installed. This is triggered by one of the two
# cancel prompts in the configupdate.py script
if returncode == 1:
sys.exit()

# Now we're going to open the config file reader
config.read('config.ini')

###############################################################################################
# This script can be used to to keep Emby servers for linux automatically up to date. #
# It is setup for the X64 and ARM versions of Debian,Ubuntu,Mint,CentOS,Fedora,Arch and #
# OpenSUSE. Most of these packages will stop/start the server as needed in the internal #
# install logic of the distro's installer. But if your distro uses systemd then this script #
# has logic that can stop and start the server if needed. If you don't have systemd then #
# if you want the server stopped and started by the script you'll need to modify the #
# commands as needed. #
# Should work with both python 2.7 and all flavors of 3. #
###############################################################################################

# Here we pull the main config parms.
if python == '3':
distro = config['DISTRO']['installdistro']
installbeta = config['DISTRO']['releaseversion']
serverstop = config['SERVER']['stopserver']
serverstart = config['SERVER']['startserver']
appupdate = config['EmbyUpdate']['autoupdate']
elif python == '2':
distro = config.get('DISTRO', 'installdistro')
installbeta = config.get('DISTRO', 'releaseversion')
serverstop = config.get('SERVER', 'stopserver')
serverstart = config.get('SERVER', 'startserver')
appupdate = config.get('EmbyUpdate', 'autoupdate')

# This is a simple timestamp function, created so each call would have a current timestamp
def timestamp():
ts = time.strftime("%x %X", time.localtime())
return ("<" + ts + "> ")

# The github API of releases for Emby Media Browser. This includes beta and production releases
url = "https://api.github.com/repos/mediabrowser/Emby.releases/releases"

# Now we're just going to see what the latest version is! If we get any funky response we'll exit the script.
try:
response = requests.get(url)
updatejson = json.loads(response.text)
# Here we search the github API response for the most recent version of beta or stable depending on what was chosen
#above.
for i, entry in enumerate(updatejson):
if installbeta == 'Beta':

if entry["prerelease"] == True:
onlineversion = entry["tag_name"]
versiontype = "Beta"
break
elif installbeta == 'Stable':

if entry["prerelease"] == False:
onlineversion = entry["tag_name"]
versiontype = "Stable"
break

else:
print("Couldn't determine release requested, value is " + installbeta)

except Exception as e:
print(timestamp() + "EmbyUpdate: We didn't get an expected response from the github api, script is exiting!")
print(timestamp() + "EmbyUpdate: Here's the error we got -- " + str(e))
sys.exit()

##########################################################################################################
# This block is just setting up the variables for your selected distro. These can be updated as needed. #
##########################################################################################################

# Debian/Ubuntu/Mint amd64 *************
if distro == "Debian X64":
downloadurl = "wget -q --show-progress https://github.com/MediaBrowser/Emby.Releases/releases/download/" + onlineversion + "/emby-server-deb_" + onlineversion + "_amd64.deb"
installfile = "dpkg -i -E emby-server-deb_" + onlineversion + "_amd64.deb"
updatefile = "emby-server-deb_" + onlineversion + "_amd64.deb"
#***************************************

# Debian/Ubuntu/Mint armhf *************
if distro == "Debian ARM":
downloadurl = "wget -q --show-progress https://github.com/MediaBrowser/Emby.Releases/releases/download/" + onlineversion + "/emby-server-deb_" + onlineversion + "_armhf.deb"
installfile = "dpkg -i emby-server-deb_" + onlineversion + "_armhf.deb"
updatefile = "emby-server-deb_" + onlineversion + "_armhf.deb"
#***************************************

# Arch Linux ***************************
if distro == "Arch":
downloadurl = "notused"
installfile = "pacman -S emby-server"
updatefile = "notused"
#***************************************

# CentOS X64 ***************************
# In Cent I think yum will handle the stop/start of the server, but change below if needed
if distro == "CentOS":
downloadurl = "yum install -y https://github.com/MediaBrowser/Emby.Releases/releases/download/" + onlineversion + "/emby-server-rpm_" + onlineversion + "_x86_64.rpm"
installfile = "notused"
updatefile = "notused"
#****************************************

# Fedora X64 ****************************
# Pretty sure dnf will stop/start the server, but change below if needed
if distro == "Fedora X64":
downloadurl = "dnf install https://github.com/MediaBrowser/Emby.Releases/releases/download/" + onlineversion + "/emby-server-rpm_" + onlineversion + "_x86_64.rpm"
installfile = "notused"
updatefile = "notused"
#***************************************

# Fedora Armv7hl ***********************
# Pretty sure dnf will stop/start the server, but change delow if needed
if distro == "Fedora ARM":
downloadurl = "dnf install https://github.com/MediaBrowser/Emby.Releases/releases/download/" + onlineversion + "/emby-server-rpm_" + onlineversion + "_armv7hl.rpm"
installfile = "notused"
updatefile = "notused"
#***************************************

# OpenSUSE X64 *************************
# Pretty sure zypper will stop/start the server, but change below as needed
if distro == "OpenSUSE X64":
downloadurl = "zypper install https://github.com/MediaBrowser/Emby.Releases/releases/download/" + onlineversion + "/emby-server-rpm_" + onlineversion + "_x86_64.rpm"
installfile = "notused"
updatefile = "notused"
#***************************************

# OpenSUSE Armv7hl *********************
# Pretty sure zypper will stop/start the server, but change below as needed
if distro == "OpenSUSE ARM":
downloadurl = "zypper install https://github.com/MediaBrowser/Emby.Releases/releases/download/" + onlineversion + "/emby-server-rpm_" + onlineversion + "_armv7hl.rpm"
installfile = "notused"
updatefile = "notused"
#**************************************

###################################################################################################
# End distro setup block. End of user configable sections. Don't change anything below this line. #
###################################################################################################

# Now were going to pull the version from the config file
if python == '3':
#This fires if user is running python3
fileversion = config['SERVER']['embyversion']
elif python == '2':
# This fires if user is running python2
fileversion = config.get('SERVER', 'embyversion')

# Ok, we've got all the info we need. Now we'll test if we even need to update or not.

onlinefileversion = (onlineversion + "-" + versiontype)

if str(onlinefileversion) in str(fileversion):
# If the latest online verson matches the last installed version then we let you know and exit
print(timestamp() + "EmbyUpdate: We're up to date! Current and Online versions are at " + onlinefileversion + ". Nothing to see here... move along. Script exiting!")
print('***')
else:
# If the online version DOESN'T match the last installed version we let you know what the versions are and start updating
print(timestamp() + "EmbyUpdate: Most recent online version is " + onlinefileversion + " and current installed version is " + fileversion + ". We're updating Emby.")
print("\n" + timestamp() + "EmbyUpdate: Starting update......")

try:
# This will stop the server on a systemd distro if it's been set to true above
if serverstop is True:
stopreturn = subprocess.call("systemctl stop emby-server",shell=True)
for i in xrange(10,0,-1):
sys.stdout.write(str(i)+' ')
sys.stdout.flush()
time.sleep(1)

if stopreturn > 0:
print("Server Stop failed! Non-critical error! Investigate if needed.")

# Here we download the package to install if used
if "notused" not in downloadurl:
downreturn = subprocess.call(downloadurl,shell=True)
if downreturn > 0:
print("Download failed!! Exiting!")
sys.exit()

# Next we install it if used
if "notused" not in installfile:
installreturn = subprocess.call(installfile,shell=True)
if installreturn > 0:
print("Install failed! Exiting!")
sys.exit()

# And to keep things nice and clean, we remove the downloaded file once installed if needed
if "notused" not in updatefile:
subprocess.call("rm -f " + updatefile,shell=True)

# This will restart the server if using systemd if set to True above
if serverstart is True:
startreturn = subprocess.call("systemctl start emby-server",shell=True)
if startreturn > 0:
print("Server start failed. Non-critical to update but server may not be running. Investigate.")

# Lastly we write the newly installed version into the config file
try:
config['SERVER']['embyversion'] = onlinefileversion
except AttributeError:
config.set('SERVER', 'embyversion', onlinefileversion)

with open('config.ini', 'w') as configfile:
config.write(configfile)
print(timestamp() + "EmbyUpdate: Updating to Emby version " + onlinefileversion + " finished! Script exiting!")
print('')
print("*****************************************************************************")
print("\n")

except Exception as e:
print(timestamp() + 'EmbyUpdate: Something failed in update. No update done, script exiting')
print(timestamp() + "EmbyUpdate: Here's the error we got -- " + str(e))

# Now well try and update the app if the user chose that option
if appupdate == 'True':
try:
returncode = subprocess.call("python3 selfupdate.py",shell=True)
if returncode != 0:
print('Python 3 was not found, falling back to python 2.')
returncode = subprocess.call("python selfupdate.py",shell=True)
except:
print("Couldn't launch Python for some reason!")

sys.exit()
Lima

About the author

Lima is the visual nautical indicator for "stop instantly."

Comments

Leave a Reply

%d bloggers like this: