NextPVR Forums
  • ______
  • Home
  • New Posts
  • Wiki
  • Members
  • Help
  • Search
  • Register
  • Login
  • Home
  • Wiki
  • Members
  • Help
  • Search
NextPVR Forums Public NextPVR Support macOS v
1 2 3 4 Next »
How to run NextPVR as a process (without the terminal)

 
  • 0 Vote(s) - 0 Average
How to run NextPVR as a process (without the terminal)
Allan
Offline

Member

Canada
Posts: 109
Threads: 11
Joined: Dec 2024
#1
2025-01-21, 10:55 PM
Issue: if you run NextPVR by opening a terminal window (even if automated with a launchagent as previously posted):
  • you still have nextpvr running in a terminal window, even if the window is hidden
  • if someone quits terminal, or if nextpvr crashes or is otherwise shut down, you will miss recordings until you detect and correct the problem.

These issues are resolved by using a launchagent or launchdaemon. The following are instructions on how to do it with a launchagent:
  1. unzip and copy the attached launchagent (org.nextpvr.backend.plist) into ~/library/launchagents
  2. set the owner to your username (the name of your home folder). This can be done with this terminal command: chown <username> ~/library/launchagents/org.nextpvr.backend.plist
  3. set the file permissions to 644: chmod 644 ~/library/launchagents/org.nextpvr.backend.plist
  4. this launchagent expects your NPVR folder to be in /applications (specifically, that the path to NextPVRServer.dll is /applications/npvr/NextPVRServer.dll). If you don't want it in /applications, or you want the folder named something other than NPVR, you can edit the launchagent WorkingDirectory and ProgramArguments accordingly, but I have not tested in another directory and there may be bumps due to macOS security issues that will cause the launchagent to fail.

When the above is done, NextPVR will launch automatically when you log into your account. You can launch it by logging out and back in to your account. The keepalive key will keep NextPVR running even if it crashes, etc., until you shut it down manually (as detailed below) or you log out of your account.

You can also manually launch and stop NextPVR with the following terminal commands:
  • launchctl load ~/Library/Launchagents/org.nextpvr.backend.plist
  • launchctl unload ~/Library/Launchagents/org.nextpvr.backend.plist

Notes and Limitations:
  • A potentially significant limitation of using a launchagent instead of a launchdaemon is that a launchagent will require that a particular user be logged into the computer and stay logged in. Accordingly, booting up the computer is not enough to launch NextPVR and if, for whatever reason, the user is logged out or the computer restarts (power outage, for instance) NextPVR won't run until the user is logged in again. Also, if there is more than one user who uses the computer, NextPVR will only run when the user whose account has the launchagent is logged in. These limitations would be resolved by a launchdaemon, which has the same function as a launchagent, but runs system wide on boot up. Writing a launchdaemon that will work with NextPVR is more complicated (for me anyway) and I have not yet managed to get it to work. When I figure it out, I will update.
  • You can see the purpose of each of the keys in the launchagent by checking the manual (in terminal "man launchd.plist", or just google "man launchd.plist".


Attached Files
.zip   org.nextpvr.backend.plist.zip (Size: 1.22 KB / Downloads: 18)
mvallevand
Online

Posting Freak

Ontario Canada
Posts: 53,080
Threads: 957
Joined: May 2006
#2
2025-01-23, 01:18 AM (This post was last modified: 2025-01-23, 01:22 AM by mvallevand.)
Thanks for that I made some modifications to run with the same paths as the Linux deb installer since I am used to them (plus I don't like using npvr) and installed to /Library/LauchDaemon and it works nicely from boot and when I am logged out. I don't know enough about macOS naming conventions for the recording folders but it defaults to /var/root/recordings so I guess it is running as root

You may be missing the second environment variable to point to the user folder and it needs the trailing slash.

Code:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
    <key>PATH</key>
    <string>/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin</string>
    <key>NEXTPVR_DATADIR_USERDATA</key>
    <string>/var/opt/nextpvr/</string>
</dict>
</plist>

Martin
Allan
Offline

Member

Canada
Posts: 109
Threads: 11
Joined: Dec 2024
#3
2025-01-23, 06:54 PM (This post was last modified: 2025-01-23, 07:07 PM by Allan.)
Quote:You may be missing the second environment variable to point to the user folder and it needs the trailing slash

This is very helpful. I suspected that the problem related to the .npvr-data folder - where it was, permissions, etc., but I had to figure out how to fix it.

I don't understand what is happening with the NEXTPVR_DATADIR_USERDATA key, however, which seems to have made it work for you. Where does this variable come from?

You are also correct that the launchdaemon is running as root. All launchdaemons run as root, subject to using the UserName key, which is described as follows:
Quote:This optional key specifies the user to run the job as. This key is only applicable when launchd is running as root.

Regarding the recording directory, I have configured mine to an external drive from the web interface Recording Directory option in settings:general. I don't think I would want it in the root home directory.
mvallevand
Online

Posting Freak

Ontario Canada
Posts: 53,080
Threads: 957
Joined: May 2006
#4
2025-01-23, 07:00 PM
That is a NextPVR specific environment variable that is used to find the entire data directory.

Code:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
    <key>Label</key>
    <string>org.nextpvr.backend</string>
    <key>ProgramArguments</key>
    <array>
        <string>/usr/local/share/dotnet/dotnet</string>
        <string>/opt/nextpvr/system/NextPVRServer.dll</string>
    </array>
    <key>EnvironmentVariables</key>
    <dict>
        <key>PATH</key>
        <string>/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin</string>
        <key>NEXTPVR_DATADIR_USERDATA</key>
        <string>/var/opt/nextpvr/</string>
    </dict>
    <key>RunAtLoad</key>
    <true/>
    <key>KeepAlive</key>
    <true/>
    <key>WorkingDirectory</key>
    <string>/opt/nextpvr/system/</string>
    <key>ThrottleInterval</key>
    <integer>300</integer>
    <key>ProcessType</key>
    <string>Interactive</string>
</dict>
</plist>

Martin
Allan
Offline

Member

Canada
Posts: 109
Threads: 11
Joined: Dec 2024
#5
2025-01-23, 07:14 PM (This post was last modified: 2025-01-23, 07:15 PM by Allan.)
This is great. I will try it out this weekend.

I also prefer the idea of putting the program fees in /opt, as you have, rather than /applications. Would you mind advising what user, group and permissions you are using for the program files and the user directory?
mvallevand
Online

Posting Freak

Ontario Canada
Posts: 53,080
Threads: 957
Joined: May 2006
#6
2025-01-23, 07:47 PM
I don't know enough about using macOS so I just followed your instructions except I used /Library/Launchdaemon and whatever I found while searching

Everything else standard stuff I know from Linux. For the folders I didn't give myself access to anything.

sudo mkdir -p /var/opt/nextpvr
sudo mkdir -p /opt/nextpvr/system

cd /opt/nextpvr/system
curl https://nextpvr.com/stable/mac/NPVR.zip
sudo unzip NPVR.zip

I did create /var/opt/nextpvr/scripts/PreStartup.sh with a one line sleep 2 because NextPVR loaded faster then my network.

Martin
Allan
Offline

Member

Canada
Posts: 109
Threads: 11
Joined: Dec 2024
#7
2025-01-23, 11:52 PM
It's really more Unix than MacOS, and I am sure you are much more competent than I am in that environment.

There are a couple of things that should be different with a launchdaemon (as opposed to a launchagent) that I will post when I have a chance to compose accurate instructions carefully.

I intend to follow your setup, which I feel is ideal for a backend.
Allan
Offline

Member

Canada
Posts: 109
Threads: 11
Joined: Dec 2024
#8
2025-01-25, 12:02 AM (This post was last modified: 2025-01-25, 12:03 AM by Allan.)
Well, something's wrong here. I tried the launchdaemon, but dotnet crashes as soon as it is launched:
Quote:2025-01-24 17:01:19.950699 (system/org.nextpvr.backend [229]) <Notice>: Successfully spawned dotnet[229] because speculative
2025-01-24 17:01:26.889258 (system/org.nextpvr.backend [229]) <Notice>: exited due to SIGABRT | sent by dotnet[229], ran for 7316ms
2025-01-24 17:01:26.889266 (system/org.nextpvr.backend [229]) <Notice>: service has crashed 1 times in a row (last was not dirty)
2025-01-24 17:01:26.889267 (system/org.nextpvr.backend [229]) <Notice>: service state: exited
2025-01-24 17:01:26.889270 (system/org.nextpvr.backend [229]) <Notice>: internal event: EXITED, code = 0
2025-01-24 17:01:26.889271 (system) <Notice>: service inactive: org.nextpvr.backend

I checked to make sure permissions were correct, and I think they are. All files and folders in /var/opt/nextpvr/ and /opt/nextpvr/system are owned by root:wheel. All files are 644 and folders 755.

I can (sort of) run it from 
Quote:launchctl load -w /library/launchdaemons/org.nextpvr.backend.plist
where it runs as my user and uses my old /users/me/.npvr-data folder, although I have set up the NEXTPVR_DATADIR_USERDATA variable to point to /var/opt/nextpvr/ as in your example.

Everything I try fails, notably any attempted launch as root. Knowing less than 0 about dotnet is a disadvantage.

I'm at a loss.
mvallevand
Online

Posting Freak

Ontario Canada
Posts: 53,080
Threads: 957
Joined: May 2006
#9
2025-01-25, 12:52 AM
It should be /Library/LaunchDaemons since macOS will be case sensitive. Did you enable the LaunchDaemon? I did notice that it added a Microsoft somewhere in Settings.

Also I used brew to install dotnet what did you use?

Does sudo launchctl list | grep nextpvr show anything?

Martin
Allan
Offline

Member

Canada
Posts: 109
Threads: 11
Joined: Dec 2024
#10
2025-01-27, 08:05 PM
Thanks for your response. Answering your questions:

I did not use brew. I used the https://dotnet.microsoft.com/en-us/download/dotnet/8.0 installer linked at this page: https://forums.nextpvr.com/showthread.php?tid=59395

sudo launchctl list | grep nextpvr gets:
Quote:- -6 org.nextpvr.backend

sudo launchctl list org.nextpvr.backend gets
Quote:{
"LimitLoadToSessionType" = "System";
"Label" = "org.nextpvr.backend";
"OnDemand" = false;
"LastExitStatus" = 6;
"Program" = "/usr/local/share/dotnet/dotnet";
"ProgramArguments" = (
"/usr/local/share/dotnet/dotnet";
"/opt/nextpvr/system/NextPVRServer.dll";
);
};

I should have mentioned that the log excerpt I provided earlier was from the launchd log. If I leave the launchdaemon running, it just keeps trying to spawn the backend every 5 minutes. 

I have not used the enable subcommand, if that's what you are referring to, but I don't think it is necessary when one is using "load" and, in any event, the list command shows that it is enabled. 

I also don't believe that it is case sensitive (one can set the file system on a drive to be case sensitive, but that is not the usual configuration). Nonetheless, I will rename and try. Crazier things have happened.

I feel the best clue so far is "exited due to SIGABRT | sent by dotnet" line from the launchd log.
« Next Oldest | Next Newest »

Users browsing this thread: 1 Guest(s)

Pages (3): 1 2 3 Next »


Possibly Related Threads…
Thread Author Replies Views Last Post
  NextPVR is being shut down/shutting itself down Allan 32 2,207 2025-01-16, 04:29 PM
Last Post: mvallevand
  Finding Multiple NextPVR's GlowTube 1 490 2024-11-06, 11:12 PM
Last Post: mvallevand
  Is there a "start" command that can be used in the Terminal app? Luisy44 2 630 2024-10-08, 07:56 PM
Last Post: Luisy44
  "NextPVR UI" App from Apple App Store a_yank_for_yes 3 1,647 2023-01-26, 07:25 PM
Last Post: sub
  NextPVR on M1 Mac? timbo3344 36 11,857 2022-10-17, 03:36 AM
Last Post: sub
  NextPVR SSD filling up cookrd1 2 1,751 2020-11-12, 03:05 PM
Last Post: cookrd1
  NextPVR install on a iMac running Catalina Edford 5 4,963 2020-07-31, 10:49 PM
Last Post: Edford
  Terminal Window jchhenderson 8 3,905 2019-12-04, 06:41 PM
Last Post: mvallevand

  • View a Printable Version
  • Subscribe to this thread
Forum Jump:

© Designed by D&D, modified by NextPVR - Powered by MyBB

Linear Mode
Threaded Mode