夸克之书

  • 首页
  • 科普
  • 笔记
  • .NET/C#
  • 物联网
  • 算法
  • Linux
  • 树莓派
夸克之内,别有洞天
  1. 首页
  2. 默认
  3. 正文

将Emby作为Windows服务运行,并访问NAS上的媒体库

2023-06-30 10453点热度 2人点赞 0条评论

Emby运行在Windows上面的时候,存在问题:每次随用户登录之后才会启动(也是官方建议的方式)。虽然说这样不会出现什么莫名其妙的问题,但是并不方便, 每次开启还得远程去登录用户。

1、Windows服务配置

使用winsw(https://github.com/winsw/winsw)这个小工具,可以非常方便的把Emby运行为系统服务。

下载地址:https://github.com/winsw/winsw/releases。

强调一下,一定要下载3.x以上的版本。因为配置文件相对于2.x版本有比较大的变动,github主页的配置文件示例也默认是3.x版本的了(这点让我迷惑了好久,因为配置不生效)。

winsw有两种运行方式,借用官方的描述:

Use WinSW as a global tool
1.Take WinSW.exe or WinSW.zip from the distribution.
2.Write myapp.xml (see the XML config file specification and samples for more details).
3.Run winsw install myapp.xml [options] to install the service.
4.Run winsw start myapp.xml to start the service.
5.Run winsw status myapp.xml to see if your service is up and running.
Use WinSW as a bundled tool
1.Take WinSW.exe or WinSW.zip from the distribution, and rename the .exe to your taste (such as myapp.exe).
2.Write myapp.xml (see the XML config file specification and samples for more details).
3.Place those two files side by side, because that's how WinSW discovers its co-related configuration.
4.Run myapp.exe install [options] to install the service.
5.Run myapp.exe start to start the service.

简单来说,全局模式就是将winsw作为一个工具管理全部的服务,捆绑模式就是将工具自生作为服务运行。

这里采用捆绑模式。

将下载的WinSW-x64.exe重命名为emby-service.exe,并新建一个名称为emby-service.xml的配置文件,配置文件如下:

<!--
  MIT License

  Copyright (c) 2008-2020 Kohsuke Kawaguchi, Sun Microsystems, Inc., CloudBees,
  Inc., Oleg Nenashev and other contributors

  Permission is hereby granted, free of charge, to any person obtaining a copy
  of this software and associated documentation files (the "Software"), to deal
  in the Software without restriction, including without limitation the rights
  to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  copies of the Software, and to permit persons to whom the Software is
  furnished to do so, subject to the following conditions:

  The above copyright notice and this permission notice shall be included in all
  copies or substantial portions of the Software.

  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  SOFTWARE.
-->

<!--
 This is an example of a minimal Windows Service Wrapper configuration, which includes only mandatory options.
 
 This configuration file should be placed near the WinSW executable, the name should be the same.
 E.g. for myapp.exe the configuration file name should be myapp.xml
 
 You can find more information about the configuration options here: https://github.com/kohsuke/winsw/blob/master/doc/xmlConfigFile.md
 Full example: https://github.com/kohsuke/winsw/blob/master/examples/sample-allOptions.xml
-->
<service>
  <!-- ID of the service. It should be unique across the Windows system-->
  <id>emby-service</id>
  <!-- Display name of the service -->
  <name>Emby Server</name>
  <!-- Service description -->
  <description>Emby is designed to help you manage your personal media library, such as home videos and photos.</description>
  <!-- Path to the executable, which should be started -->
  <executable>%BASE%\..\system\EmbyServer.exe</executable>
  <!--
    OPTION: workingdirectory
    If specified, sets the default working directory of the executable
    Default value: Directory of the service wrapper executable.
  -->
  <workingdirectory>%BASE%\..\system</workingdirectory>
  <arguments>-service</arguments>
  <onfailure action="restart" delay="10 sec"/>
</service>

具体参数我就不一一解释了,自行参考github。

在emby server的上一级目录中新建目录service。并将emby-service.exe、emby-service.xml这两个文件放到里面。

此时的目录结构如下:

%title插图%num

这上面的目录结构下,就算每次重新安装emby的应用程序,都不会丢失数据和影响服务程序。

进入到service目录。在地址栏输入cmd,打开命令行。

%title插图%num

依次执行:

emby-service install   #安装服务
emby-service start     #启动服务
%title插图%num

成功执行之后,在服务管理管理器中将会看到已经启动的Emby服务。

%title插图%num

现在,Emby就能每次随系统启动而启动了。

2、配置访问NAS中的共享文件夹

但是还只能访问本地的数据,因为使用“本地服务”这个系统用户启动的。没有访问SMB服务的权限,如果没有访问NAS共享目录的需求,就可以不用管下面的部分了。

要想能够顺利访问NAS共享目录,就需要让启动服务的用户具有访问NAS共享目录的权限。winsw这个小工具,支持配置为特定用户启动服务。但是在配置之前,我们得先让Windows中有这个用户。

2.1、Windows用户创建

打开计算机管理,找到本地用户和组。在用户选项卡中新建用户。

%title插图%num

填写一个用户名,这里以emby为例:

%title插图%num

去勾选“用户下次登录时须更改密码”。建议勾上“密码用不过期”。

创建好用户之后,右键用户,选择“属性”

%title插图%num

然后再用户组中添加“Administrator”这个用户组,授予新建用户管理员权限。

%title插图%num

2.2、NAS用户创建

Windows中账号创建好之后,也需要在NAS中创建相同账号,并授权能访问共享目录。

这里已TrueNAS为例。我已经创建好emby这个用户,特别注意的一点就是需要勾选微软账户这个选项。

%title插图%num

这样就能用过微软账户中的emby去访问NAS中emby授权的共享文件夹了。

2.3、服务配置修改

还需要对winsw的配置进行一点点小小的修改。让服务使用指定的账户启动。在配置文件中新增:

  <serviceaccount>
    <username>.\emby</username>
    <password>123456</password>
    <allowservicelogon>true</allowservicelogon>
  </serviceaccount>

用户名就是新创建的用户名。本地账户的话,前面要加上.\。

加好之后的配置如下:

<!--
  MIT License

  Copyright (c) 2008-2020 Kohsuke Kawaguchi, Sun Microsystems, Inc., CloudBees,
  Inc., Oleg Nenashev and other contributors

  Permission is hereby granted, free of charge, to any person obtaining a copy
  of this software and associated documentation files (the "Software"), to deal
  in the Software without restriction, including without limitation the rights
  to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  copies of the Software, and to permit persons to whom the Software is
  furnished to do so, subject to the following conditions:

  The above copyright notice and this permission notice shall be included in all
  copies or substantial portions of the Software.

  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  SOFTWARE.
-->

<!--
 This is an example of a minimal Windows Service Wrapper configuration, which includes only mandatory options.
 
 This configuration file should be placed near the WinSW executable, the name should be the same.
 E.g. for myapp.exe the configuration file name should be myapp.xml
 
 You can find more information about the configuration options here: https://github.com/kohsuke/winsw/blob/master/doc/xmlConfigFile.md
 Full example: https://github.com/kohsuke/winsw/blob/master/examples/sample-allOptions.xml
-->
<service>
  <!-- ID of the service. It should be unique across the Windows system-->
  <id>emby-service</id>
  <!-- Display name of the service -->
  <name>Emby Server</name>
  <!-- Service description -->
  <description>Emby is designed to help you manage your personal media library, such as home videos and photos.</description>
  <!-- Path to the executable, which should be started -->
  <executable>%BASE%\..\system\EmbyServer.exe</executable>
  <!--
    OPTION: workingdirectory
    If specified, sets the default working directory of the executable
    Default value: Directory of the service wrapper executable.
  -->
  <workingdirectory>%BASE%\..\system</workingdirectory>
  <arguments>-service</arguments>
  <onfailure action="restart" delay="10 sec"/>
  <serviceaccount>
    <username>.\emby</username>
    <password>123456</password>
    <allowservicelogon>true</allowservicelogon>
  </serviceaccount>
</service>

重启服务。愉快的玩耍吧~

本作品采用 知识共享署名-非商业性使用 4.0 国际许可协议 进行许可
标签: 暂无
最后更新:2023-07-01

afirefish

这个人很懒,什么都没留下

打赏 点赞
< 上一篇
下一篇 >

文章评论

您需要 登录 之后才可以评论
放松一下
https://www.quarkbook.com/wp-content/uploads/2021/05/凤凰传奇-海底(Live).flac
分类
  • .NET/C#
  • Linux
  • 树莓派
  • 物联网
  • 科普
  • 笔记
  • 算法
  • 默认
最新 热点 随机
最新 热点 随机
在代码中判断龙芯新旧世界平台 Windows获取固定后缀的IPv6地址 目前为止,你可能找不到第二台支持志强的1L小主机(P350 Tiny+W-1350+ECC+双NVME+PCIE扩展)!!! iKuai(爱快)实现成都移动IPTV IPoE拨号 Linux EXT4分区误删除后数据恢复 C#连接到巴法云
在代码中判断龙芯新旧世界平台
严肃一点的排序算法(4) – 桶排序 智能语音控制中心 - 树莓派、Nanopi、Orangepi语音识别控制 OpenWrt配置SmartDNS 23种常见的设计模式(9):命令模式 解决Mysql中文乱码 树莓派.Net Core Iot入门系列篇(4):UART串口通信
最近评论
Eagle 发布于 7 个月前(10月21日) 参考博主教程成功搞定了成都移动IPTV组播转单播,电脑、手机都可以播放了。但目前有个问题,原IPTV...
rundoze 发布于 9 个月前(08月31日) 牛逼
cc21216695 发布于 2 年前(09月27日) 试了一下,加入启动项也无效,压根没有用
afirefish 发布于 3 年前(11月28日) 非常感谢,非常棒!
》随缘《 发布于 3 年前(11月20日) 最新【一键处理】方法: https://github.com/MrXhh/VSTools/rele...
书签
  • 打赏
  • 毒鸡汤
  • 米店
  • 金鱼直播间

COPYRIGHT © 2023 quarkbook.com. ALL RIGHTS RESERVED.

Theme Kratos Made By Seaton Jiang

蜀ICP备15036129号-9

登录
注册|忘记密码?