2014-11-23 23:10:41 +00:00
|
|
|
|
using MediaBrowser.Common.Net;
|
|
|
|
|
using MediaBrowser.IsoMounter;
|
|
|
|
|
using MediaBrowser.Model.Logging;
|
|
|
|
|
using MediaBrowser.Server.Mono.Networking;
|
|
|
|
|
using MediaBrowser.Server.Startup.Common;
|
|
|
|
|
using Mono.Unix.Native;
|
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Reflection;
|
|
|
|
|
using System.Text.RegularExpressions;
|
2016-01-21 17:29:14 +00:00
|
|
|
|
using MediaBrowser.Controller.Power;
|
2016-06-23 17:04:18 +00:00
|
|
|
|
using MediaBrowser.Model.System;
|
2016-05-01 21:48:37 +00:00
|
|
|
|
using MediaBrowser.Server.Implementations.Persistence;
|
2016-04-02 04:29:48 +00:00
|
|
|
|
using MediaBrowser.Server.Startup.Common.FFMpeg;
|
|
|
|
|
using OperatingSystem = MediaBrowser.Server.Startup.Common.OperatingSystem;
|
2014-11-23 23:10:41 +00:00
|
|
|
|
|
|
|
|
|
namespace MediaBrowser.Server.Mono.Native
|
|
|
|
|
{
|
|
|
|
|
public abstract class BaseMonoApp : INativeApp
|
|
|
|
|
{
|
2015-10-05 16:05:08 +00:00
|
|
|
|
protected StartupOptions StartupOptions { get; private set; }
|
2016-05-01 21:48:37 +00:00
|
|
|
|
protected ILogger Logger { get; private set; }
|
|
|
|
|
|
|
|
|
|
protected BaseMonoApp(StartupOptions startupOptions, ILogger logger)
|
2015-10-05 16:05:08 +00:00
|
|
|
|
{
|
|
|
|
|
StartupOptions = startupOptions;
|
2016-05-01 21:48:37 +00:00
|
|
|
|
Logger = logger;
|
2015-10-05 16:05:08 +00:00
|
|
|
|
}
|
|
|
|
|
|
2014-11-23 23:10:41 +00:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Shutdowns this instance.
|
|
|
|
|
/// </summary>
|
|
|
|
|
public abstract void Shutdown();
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Restarts this instance.
|
|
|
|
|
/// </summary>
|
2015-06-05 14:27:01 +00:00
|
|
|
|
public virtual void Restart(StartupOptions startupOptions)
|
2014-11-23 23:10:41 +00:00
|
|
|
|
{
|
2015-05-23 22:01:13 +00:00
|
|
|
|
throw new NotImplementedException();
|
2014-11-23 23:10:41 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Determines whether this instance [can self restart].
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <returns><c>true</c> if this instance [can self restart]; otherwise, <c>false</c>.</returns>
|
2015-05-23 22:01:13 +00:00
|
|
|
|
public virtual bool CanSelfRestart
|
2014-11-23 23:10:41 +00:00
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Gets a value indicating whether this instance can self update.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <value><c>true</c> if this instance can self update; otherwise, <c>false</c>.</value>
|
|
|
|
|
public bool CanSelfUpdate
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public bool SupportsAutoRunAtStartup
|
|
|
|
|
{
|
|
|
|
|
get { return false; }
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void PreventSystemStandby()
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
2016-04-23 18:38:36 +00:00
|
|
|
|
public void AllowSystemStandby()
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
2014-11-23 23:10:41 +00:00
|
|
|
|
public List<Assembly> GetAssembliesWithParts()
|
|
|
|
|
{
|
|
|
|
|
var list = new List<Assembly>();
|
|
|
|
|
|
|
|
|
|
if (Environment.OperatingSystem == Startup.Common.OperatingSystem.Linux)
|
|
|
|
|
{
|
|
|
|
|
list.AddRange(GetLinuxAssemblies());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
list.Add(GetType().Assembly);
|
|
|
|
|
|
|
|
|
|
return list;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private IEnumerable<Assembly> GetLinuxAssemblies()
|
|
|
|
|
{
|
|
|
|
|
var list = new List<Assembly>();
|
|
|
|
|
|
|
|
|
|
list.Add(typeof(LinuxIsoManager).Assembly);
|
|
|
|
|
|
|
|
|
|
return list;
|
|
|
|
|
}
|
|
|
|
|
|
2016-03-26 17:51:27 +00:00
|
|
|
|
public void AuthorizeServer(int udpPort, int httpServerPort, int httpsPort, string applicationPath, string tempDirectory)
|
2014-11-23 23:10:41 +00:00
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private NativeEnvironment _nativeEnvironment;
|
|
|
|
|
public NativeEnvironment Environment
|
|
|
|
|
{
|
|
|
|
|
get { return _nativeEnvironment ?? (_nativeEnvironment = GetEnvironmentInfo()); }
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public bool SupportsRunningAsService
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public bool IsRunningAsService
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2015-10-03 18:13:53 +00:00
|
|
|
|
public bool SupportsLibraryMonitor
|
|
|
|
|
{
|
2015-10-05 16:05:08 +00:00
|
|
|
|
get
|
|
|
|
|
{
|
2016-01-18 02:03:34 +00:00
|
|
|
|
return Environment.OperatingSystem != Startup.Common.OperatingSystem.Osx;
|
2015-10-05 16:05:08 +00:00
|
|
|
|
}
|
2015-10-03 18:13:53 +00:00
|
|
|
|
}
|
|
|
|
|
|
2014-11-23 23:10:41 +00:00
|
|
|
|
public void ConfigureAutoRun(bool autorun)
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public INetworkManager CreateNetworkManager(ILogger logger)
|
|
|
|
|
{
|
|
|
|
|
return new NetworkManager(logger);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private NativeEnvironment GetEnvironmentInfo()
|
|
|
|
|
{
|
|
|
|
|
var info = new NativeEnvironment
|
|
|
|
|
{
|
|
|
|
|
OperatingSystem = Startup.Common.OperatingSystem.Linux
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
var uname = GetUnixName();
|
|
|
|
|
|
|
|
|
|
var sysName = uname.sysname ?? string.Empty;
|
|
|
|
|
|
|
|
|
|
if (string.Equals(sysName, "Darwin", StringComparison.OrdinalIgnoreCase))
|
|
|
|
|
{
|
|
|
|
|
info.OperatingSystem = Startup.Common.OperatingSystem.Osx;
|
|
|
|
|
}
|
|
|
|
|
else if (string.Equals(sysName, "Linux", StringComparison.OrdinalIgnoreCase))
|
|
|
|
|
{
|
|
|
|
|
info.OperatingSystem = Startup.Common.OperatingSystem.Linux;
|
|
|
|
|
}
|
|
|
|
|
else if (string.Equals(sysName, "BSD", StringComparison.OrdinalIgnoreCase))
|
|
|
|
|
{
|
|
|
|
|
info.OperatingSystem = Startup.Common.OperatingSystem.Bsd;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var archX86 = new Regex("(i|I)[3-6]86");
|
|
|
|
|
|
|
|
|
|
if (archX86.IsMatch(uname.machine))
|
|
|
|
|
{
|
|
|
|
|
info.SystemArchitecture = Architecture.X86;
|
|
|
|
|
}
|
|
|
|
|
else if (string.Equals(uname.machine, "x86_64", StringComparison.OrdinalIgnoreCase))
|
|
|
|
|
{
|
2016-06-23 17:04:18 +00:00
|
|
|
|
info.SystemArchitecture = Architecture.X64;
|
2014-11-23 23:10:41 +00:00
|
|
|
|
}
|
|
|
|
|
else if (uname.machine.StartsWith("arm", StringComparison.OrdinalIgnoreCase))
|
|
|
|
|
{
|
|
|
|
|
info.SystemArchitecture = Architecture.Arm;
|
|
|
|
|
}
|
2016-07-05 04:16:03 +00:00
|
|
|
|
else if (System.Environment.Is64BitOperatingSystem)
|
|
|
|
|
{
|
|
|
|
|
info.SystemArchitecture = Architecture.X64;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
info.SystemArchitecture = Architecture.X86;
|
|
|
|
|
}
|
2014-11-23 23:10:41 +00:00
|
|
|
|
|
|
|
|
|
info.OperatingSystemVersionString = string.IsNullOrWhiteSpace(sysName) ?
|
|
|
|
|
System.Environment.OSVersion.VersionString :
|
|
|
|
|
sysName;
|
|
|
|
|
|
|
|
|
|
return info;
|
|
|
|
|
}
|
|
|
|
|
|
2014-11-26 04:12:29 +00:00
|
|
|
|
private Uname _unixName;
|
2015-10-05 16:05:08 +00:00
|
|
|
|
|
2014-11-26 04:12:29 +00:00
|
|
|
|
private Uname GetUnixName()
|
2014-11-23 23:10:41 +00:00
|
|
|
|
{
|
|
|
|
|
if (_unixName == null)
|
|
|
|
|
{
|
2014-11-26 04:12:29 +00:00
|
|
|
|
var uname = new Uname();
|
2016-07-05 04:16:03 +00:00
|
|
|
|
try
|
2014-11-23 23:10:41 +00:00
|
|
|
|
{
|
2016-07-05 04:16:03 +00:00
|
|
|
|
Utsname utsname;
|
|
|
|
|
var callResult = Syscall.uname(out utsname);
|
|
|
|
|
if (callResult == 0)
|
|
|
|
|
{
|
|
|
|
|
uname.sysname = utsname.sysname ?? string.Empty;
|
|
|
|
|
uname.machine = utsname.machine ?? string.Empty;
|
|
|
|
|
}
|
2014-11-23 23:10:41 +00:00
|
|
|
|
|
2016-07-05 04:16:03 +00:00
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
Logger.ErrorException("Error getting unix name", ex);
|
|
|
|
|
}
|
2014-11-23 23:10:41 +00:00
|
|
|
|
_unixName = uname;
|
|
|
|
|
}
|
|
|
|
|
return _unixName;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public class Uname
|
|
|
|
|
{
|
|
|
|
|
public string sysname = string.Empty;
|
|
|
|
|
public string machine = string.Empty;
|
|
|
|
|
}
|
2016-01-21 17:29:14 +00:00
|
|
|
|
|
|
|
|
|
public IPowerManagement GetPowerManagement()
|
|
|
|
|
{
|
|
|
|
|
return new NullPowerManagement();
|
|
|
|
|
}
|
2016-04-02 04:29:48 +00:00
|
|
|
|
|
|
|
|
|
public FFMpegInstallInfo GetFfmpegInstallInfo()
|
|
|
|
|
{
|
|
|
|
|
return GetInfo(Environment);
|
|
|
|
|
}
|
|
|
|
|
|
2016-04-24 03:03:49 +00:00
|
|
|
|
public void LaunchUrl(string url)
|
|
|
|
|
{
|
|
|
|
|
throw new NotImplementedException();
|
|
|
|
|
}
|
|
|
|
|
|
2016-05-01 21:48:37 +00:00
|
|
|
|
public IDbConnector GetDbConnector()
|
|
|
|
|
{
|
|
|
|
|
return new DbConnector(Logger);
|
|
|
|
|
}
|
|
|
|
|
|
2016-04-02 04:29:48 +00:00
|
|
|
|
public static FFMpegInstallInfo GetInfo(NativeEnvironment environment)
|
|
|
|
|
{
|
|
|
|
|
var info = new FFMpegInstallInfo();
|
|
|
|
|
|
|
|
|
|
// Windows builds: http://ffmpeg.zeranoe.com/builds/
|
|
|
|
|
// Linux builds: http://johnvansickle.com/ffmpeg/
|
|
|
|
|
// OS X builds: http://ffmpegmac.net/
|
|
|
|
|
// OS X x64: http://www.evermeet.cx/ffmpeg/
|
|
|
|
|
|
|
|
|
|
switch (environment.OperatingSystem)
|
|
|
|
|
{
|
2016-06-29 02:45:37 +00:00
|
|
|
|
case OperatingSystem.Osx:
|
2016-04-02 04:29:48 +00:00
|
|
|
|
case OperatingSystem.Bsd:
|
|
|
|
|
break;
|
|
|
|
|
case OperatingSystem.Linux:
|
|
|
|
|
|
|
|
|
|
info.ArchiveType = "7z";
|
|
|
|
|
info.Version = "20160215";
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
info.DownloadUrls = GetDownloadUrls(environment);
|
|
|
|
|
|
|
|
|
|
return info;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private static string[] GetDownloadUrls(NativeEnvironment environment)
|
|
|
|
|
{
|
|
|
|
|
switch (environment.OperatingSystem)
|
|
|
|
|
{
|
|
|
|
|
case OperatingSystem.Linux:
|
|
|
|
|
|
|
|
|
|
switch (environment.SystemArchitecture)
|
|
|
|
|
{
|
2016-06-23 17:04:18 +00:00
|
|
|
|
case Architecture.X64:
|
2016-04-02 04:29:48 +00:00
|
|
|
|
return new[]
|
|
|
|
|
{
|
|
|
|
|
"https://github.com/MediaBrowser/Emby.Resources/raw/master/ffmpeg/linux/ffmpeg-git-20160215-64bit-static.7z"
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// No version available
|
|
|
|
|
return new string[] { };
|
|
|
|
|
}
|
|
|
|
|
|
2016-01-21 17:29:14 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public class NullPowerManagement : IPowerManagement
|
|
|
|
|
{
|
|
|
|
|
public void ScheduleWake(DateTime utcTime)
|
|
|
|
|
{
|
|
|
|
|
throw new NotImplementedException();
|
|
|
|
|
}
|
2014-11-23 23:10:41 +00:00
|
|
|
|
}
|
|
|
|
|
}
|