Ubuntu下Twonky Server通过systemd自启动的权限问题及解决
I ran into a frustrating issue while setting up Twonky Server on Ubuntu recently: the server worked fine when started manually, but the custom twonkyserver.service file I created in /etc/systemd/system/ wouldn't let it auto-start with systemd. I kept getting a vague error about not being able to access the PID file /var/run/mediaserver.pid, with an exit code of 13 (that's the EACCES permission denied error) — even though the service was running as root!
The fix turned out to be simple: explicitly define the PIDFile directive in the systemd service file. This tells systemd exactly where to look for the PID file, ensuring it can properly manage the service's lifecycle and avoid permission conflicts.
Here's the working twonkyserver.service file that resolved the issue:
[Unit] Description=Twonky Server Service After=network.target [Service] Type=simple ExecStart=/usr/local/twonky/twonky.sh start ExecStop=/usr/local/twonky/twonky.sh stop ExecReload=/usr/local/twonky/twonky.sh reload ExecRestart=/usr/local/twonky/twonky.sh restart PIDFile=/var/run/mediaserver.pid Restart=on-failure [Install] WantedBy=multi-user.target
Once you've updated the service file, don't forget to reload systemd and enable the service to make sure the changes take effect:
sudo systemctl daemon-reload sudo systemctl enable twonkyserver.service
Without the PIDFile directive, systemd might not correctly track the PID file generated by Twonky's startup script, leading to unexpected permission issues even when running as root. Specifying it explicitly aligns systemd's expectations with the script's behavior, fixing the auto-start problem entirely.
内容的提问来源于stack exchange,提问作者razfaz32

