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.Runwinsw install myapp.xml [options]
to install the service.
4.Runwinsw start myapp.xml
to start the service.
5.Runwinsw 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.Runmyapp.exe install [options]
to install the service.
5.Runmyapp.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这两个文件放到里面。
此时的目录结构如下:
这上面的目录结构下,就算每次重新安装emby的应用程序,都不会丢失数据和影响服务程序。
进入到service目录。在地址栏输入cmd,打开命令行。
依次执行:
emby-service install #安装服务
emby-service start #启动服务
成功执行之后,在服务管理管理器中将会看到已经启动的Emby服务。
现在,Emby就能每次随系统启动而启动了。
2、配置访问NAS中的共享文件夹
但是还只能访问本地的数据,因为使用“本地服务”这个系统用户启动的。没有访问SMB服务的权限,如果没有访问NAS共享目录的需求,就可以不用管下面的部分了。
要想能够顺利访问NAS共享目录,就需要让启动服务的用户具有访问NAS共享目录的权限。winsw这个小工具,支持配置为特定用户启动服务。但是在配置之前,我们得先让Windows中有这个用户。
2.1、Windows用户创建
打开计算机管理,找到本地用户和组。在用户选项卡中新建用户。
填写一个用户名,这里以emby为例:
去勾选“用户下次登录时须更改密码”。建议勾上“密码用不过期”。
创建好用户之后,右键用户,选择“属性”
然后再用户组中添加“Administrator”这个用户组,授予新建用户管理员权限。
2.2、NAS用户创建
Windows中账号创建好之后,也需要在NAS中创建相同账号,并授权能访问共享目录。
这里已TrueNAS为例。我已经创建好emby这个用户,特别注意的一点就是需要勾选微软账户这个选项。
这样就能用过微软账户中的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>
重启服务。愉快的玩耍吧~
文章评论