Artix Linux Forum

Init systems => runit => Topic started by: dancaer69 on 16 August 2020, 09:12:35

Title: create runit service from systemd
Post by: dancaer69 on 16 August 2020, 09:12:35
I need a runit service for plex media server(from aur). The contents of systemd service are
Code: [Select]
[Unit]

Description=Plex Media Server
After=network.target

[Service]
EnvironmentFile=/etc/conf.d/plexmediaserver
ExecStart=/usr/lib/plexmediaserver/Plex\x20Media\x20Server
Type=simple
User=plex
Group=plex
Restart=on-failure
RestartSec=5
StartLimitInterval=60s
StartLimitBurst=3

[Install]
WantedBy=multi-user.targe


How to include the extra info as environmentfile/user/group etc in the runit service 



Title: Re: create runit service from systemd
Post by: Artist on 16 August 2020, 13:01:17
Hi dancaer69

For the conf file a construction like this is possible:
[ -r conf ] && . ./conf

For user/group:
exec chpst -u "$user:$groups"
Title: Re: create runit service from systemd
Post by: dancaer69 on 16 August 2020, 14:41:36
Thanks, but I don't understand how to use them. Especially the conf part, I don't know  how  modify it to point to /etc/conf.d/plexmediaserver.
About the user/group part I found a page about "chpst", so I think that in my case it will be like this:
exec chpst -u "plex.plex"

EDIT:
I found this:
https://rubyists.github.io/2011/05/02/runit-for-ruby-and-everything-else.html
So, based on above example I'm thinking this:
Code: [Select]
envfile=/etc/conf.d/plexmediaserver
exec chpst -e $envfile -u plex.plex /usr/lib/plexmediaserver/Plex\ Media\ Server
Is this correct?


Title: Re: create runit service from systemd
Post by: konimex on 18 August 2020, 03:40:48
Thanks, but I don't understand how to use them. Especially the conf part, I don't know  how  modify it to point to /etc/conf.d/plexmediaserver.
About the user/group part I found a page about "chpst", so I think that in my case it will be like this:
exec chpst -u "plex.plex"

EDIT:
I found this:
https://rubyists.github.io/2011/05/02/runit-for-ruby-and-everything-else.html
So, based on above example I'm thinking this:
Code: [Select]
envfile=/etc/conf.d/plexmediaserver
exec chpst -e $envfile -u plex.plex /usr/lib/plexmediaserver/Plex\ Media\ Server
Is this correct?

Almost.

Since /etc/conf.d/plexmediaserver is a file and not a directory, I'd put it like this:
Code: [Select]
#!/bin/sh
. /etc/conf.d/plexmediaserver
exec chpst -u plex:plex /usr/lib/plexmediaserver/Plex\ Media\ Server

(Note the : (colon) for user:group, not . (point).)
Title: Re: create runit service from systemd
Post by: dancaer69 on 18 August 2020, 07:56:47
Thanks. This should work, but the service always fail to run. If I manually run the script I get error about:
Code: [Select]
PMS: failure detected. Read/write access is required for path: /root/Library/Application Support/Plex Media Server
This directory doesn't exist. I have only in my user's home this directory(probably because I manually run it before. This happens and if I use my user' s name instead of plex. I also tried to move this directory to /root and change owner to plex. Also I gave read/write access to this dir to plex group and to anyone, but I always get the same error.
Title: Re: create runit service from systemd
Post by: ndowens on 18 August 2020, 22:32:59
Sounds like you are possibily missing an option telling which dir for the application to use or chpst not being used correct. Init services run as root, reason it is looking in /root