PlexConnect on ArchLinux

Hi!

 

Anyone out there tried Plexconnect on ArchLinux?

 

Starting it manually works just fine, but getting it to autostart, that is where I fail.

 

Have put PlexConnect in this path: /home/PlexConnect-master
 
I then created a systemd service file:
[root@alarm ~]# cat /etc/systemd/system/PlexConnect.service
[Unit]
Description=PlexConnect service
# Make sure we have functional network available
Requires=network.target
After=network.target

[Service]

Allow process forking or oneshot

ExecStart=/usr/bin/sh /home/PlexConnect-master/PlexConnect.sh
Type=forking
RemainAfterExit=yes

Restart service in case it fails after a minute

Restart=always
RestartSec=60

[Install]
WantedBy=multi-user.target
[root@alarm ~]#

And activated it by doing:

systemctl enable PlexConnect

The PlexConnect.sh file is set to 755, and contains:

#!/bin/bash

/home/PlexConnect-master/PlexConnect.py

If I run it from the terminal, it works just fine:

[root@alarm PlexConnect-master]# /home/PlexConnect-master/PlexConnect.sh 
19:22:09 PlexConnect: ***
19:22:09 PlexConnect: PlexConnect
19:22:09 PlexConnect: Press CTRL-C to shut down.
19:22:09 PlexConnect: ***
19:22:09 PlexConnect: started: 19:22:09
19:22:09 PlexConnect: Version: 0.3.1+
19:22:09 PlexConnect: Python: 2.7.6 (default, Nov 29 2013, 11:17:54) 
[GCC 4.7.2]
19:22:09 PlexConnect: Host OS: linux2
19:22:09 PlexConnect: IP_self: 192.168.1.96
19:22:09 DNSServer: started: 19:22:09
19:22:09 DNSServer: ***
19:22:09 DNSServer: DNSServer: Serving DNS on 192.168.1.96 port 53.
19:22:09 DNSServer: intercept: ['trailers.apple.com'] => 192.168.1.96
19:22:09 DNSServer: restrain: ['mesu.apple.com', 'appldnld.apple.com', 'appldnld.apple.com.edgesuite.net'] => 127.0.0.1
19:22:09 DNSServer: forward other to higher level DNS: 8.8.8.8
19:22:09 DNSServer: ***
19:22:09 WebServer: started: 19:22:09
19:22:09 WebServer: ***
19:22:09 WebServer: WebServer: Serving HTTP on 192.168.1.96 port 80.
19:22:09 WebServer: ***
19:22:09 WebServer: started: 19:22:09
19:22:09 WebServer: ***
19:22:09 WebServer: WebServer: Serving HTTPS on 192.168.1.96 port 443.

But if I start the service manually:

systemctl start PlexConnect

or just reboot the server, it dies after about one and a half minute with the following log:

[root@alarm ~]# cat /home/PlexConnect-master/PlexConnect.log
20:02:50 PlexConnect: started: 20:02:50
20:02:50 PlexConnect: Version: 0.3.1+
20:02:50 PlexConnect: Python: 2.7.6 (default, Nov 29 2013, 11:17:54) 
[GCC 4.7.2]
20:02:50 PlexConnect: Host OS: linux2
20:02:50 Settings: getsetting enable_plexconnect_autodetect=True
20:02:50 PlexConnect: IP_self: 192.168.1.96
20:02:50 Settings: getsetting hosttointercept=trailers.apple.com
20:02:50 Settings: getsetting port_webserver=80
20:02:50 Settings: getsetting enable_dnsserver=True
20:02:51 DNSServer: started: 20:02:51
20:02:51 Settings: getsetting port_dnsserver=53
20:02:51 Settings: getsetting ip_dnsmaster=8.8.8.8
20:02:51 Settings: getsetting prevent_atv_update=True
20:02:51 DNSServer: ***
20:02:51 DNSServer: DNSServer: Serving DNS on 192.168.1.96 port 53.
20:02:51 DNSServer: intercept: ['trailers.apple.com'] => 192.168.1.96
20:02:51 DNSServer: restrain: ['mesu.apple.com', 'appldnld.apple.com', 'appldnld.apple.com.edgesuite.net'] => 127.0.0.1
20:02:51 DNSServer: forward other to higher level DNS: 8.8.8.8
20:02:51 DNSServer: ***
20:02:51 WebServer: started: 20:02:51
20:02:51 Settings: getsetting port_webserver=80
20:02:51 WebServer: ***
20:02:51 WebServer: WebServer: Serving HTTP on 192.168.1.96 port 80.
20:02:51 WebServer: ***
20:02:51 ATVSettings: init class CATVSettings
20:02:51 ATVSettings: load settings
20:02:51 Settings: getsetting enable_webserver_ssl=True
20:02:51 WebServer: started: 20:02:51
20:02:51 Settings: getsetting port_ssl=443
20:02:51 Settings: getsetting certfile=./assets/certificates/trailers.pem
20:02:51 Settings: getsetting certfile=./assets/certificates/trailers.pem
20:02:51 WebServer: ***
20:02:51 WebServer: WebServer: Serving HTTPS on 192.168.1.96 port 443.
20:02:51 WebServer: ***
20:04:19 PlexConnect: Shutting down.
20:04:19 DNSServer: Warning: DNS error (4): Interrupted system call
20:04:19 PlexConnect: Shutting down.
20:04:19 PlexConnect: Shutting down.
20:04:19 PlexConnect: Shutting down.
20:04:20 WebServer: Shutting down.
20:04:20 ATVSettings: save settings
20:04:20 WebServer: Shutting down.
20:04:24 DNSServer: Shutting down.
20:04:24 PlexConnect: shutdown
[root@alarm ~]# 

What is causing the service to die after that duration?

What does "DNSServer: Warning: DNS error (4): Interrupted system call" mean?

>>What does "DNSServer: Warning: DNS error (4): Interrupted system call" mean?

You pressed CTRL-C while python/your OS ran those DNS/networked handlers...

Nope, no one pressed CTRL-C, it happens "automagically" after the process has run for close to 1.5 min all the time.

That's cool...

Is there a reason you cannot use the bash daemon file on that distro?

This is what their Wiki states: https://wiki.archlinux.org/index.php/Startup_files

So therefor I used systemd as recommended. If I can get it working by other means, I would be happy to try it.

There is a daemon for Linux, the commands are:


sudo ./PlexConnect_daemon.bash start

sudo ./PlexConnect_daemon.bash status

sudo ./PlexConnect_daemon.bash stop

Well problem is that "Warning: Arch only supports systemd. Arch's old initscripts package as described on this page is obsolete and is no longer supported. All Arch users need to migrate to systemd."

https://wiki.archlinux.org/index.php/initscripts

But I gave it a spin anyways...

 I created a systemd service file:

[root@alarm ~]# cat /etc/systemd/system/PlexConnect.service
[Unit]
Description=PlexConnect service

[Service]

Allow process forking or oneshot

ExecStart=/usr/bin/sh /home/PlexConnect-master/PlexConnect_daemon.bash
Type=forking
RemainAfterExit=yes

[Install]
WantedBy=multi-user.target
[root@alarm ~]#

Then I enabled it:

systemctl enable PlexConnect

The process still does not start at bootup, and checking with "systemctl list-units", it gives me:

PlexConnect.service                                    loaded failed failed    PlexConnect service

I cannot see any new entries in "/home/PlexConnect-master/PlexConnect.log"

Trying to start it manually:

./PlexConnect_daemon.bash start

It tells me:

Starting PlexConnect...
./PlexConnect_daemon.bash: line 29: python: command not found
[root@alarm PlexConnect-master]#

Which I think corresponds to this line:

    ${PYTHON} ${PROGRAM} --pidfile ${PID_FILE}

Maybe the environment variables are not fully set up yet?

Finally found a workaround!

Seems there is some kind of resource that is needed that is not up when the service starts and it therefor fails, and it seems an environment variable was missing also.

To get it working on Archlinux as a systemd service:

Create a systemd file (/etc/systemd/system/PlexConnect.service) containing this:

[Unit]
Description=PlexConnect service

[Service]

Allow one of simple, forking, oneshot, dbus, notify or idle process

Type=oneshot
RemainAfterExit=yes
ExecStart=/usr/bin/sh /home/PlexConnect-master/PlexConnect.sh

[Install]
WantedBy=multi-user.target

"Type=oneshot" is used, since the timeout is disabled by default for this parameter.

If other type is used (simple, forking, dbus, notify or idle), the service will be killed after approximately 1.5 minute.

Create a PlexConnect.sh file (/home/PlexConnect-master/PlexConnect.sh) containing this, and set it to 755:

#!/bin/bash
sleep 5
python2 /home/PlexConnect-master/PlexConnect.py

"sleep 5" is needed in order for other process to start during boot prior to this service.

"python 2" is needed to compensate for missing env variable.

To make it start on boot, use:
systemctl enable PlexConnect

Then reboot your machine:

/sbin/reboot

After this, PlexConnect now starts at boot-up!

Useful commands to troubleshoot this are:

List active service Status:
systemctl list-units
 
Detailed log of what happened:
journalctl -xn

Interesting in OSX I used a sleep 1 string in my app OpenConnect and WebConnect in my signature to get rid the non-bash plist I was always using specifically in plexconnect.bash that waits for network readiness and then runs plexconnect.py when the network becomes available. Guess there is a timing issue with arch Linux as well. Can you try to lower the timeout to sleep 1 and see if it still works?

https://github.com/wahlmanj/PlexConnect/blob/master/update/OSX/PlexConnect.bash


You may be able to still use the bash if you include it in there similar to how I set it up for OSX.

It works with "sleep 3", but when I go to "sleep 2" it stops working. So to be safe, I left it on "sleep 5".

Interesting in OSX I used a sleep 1 string in my app OpenConnect and WebConnect in my signature to get rid the non-bash plist I was always using specifically in plexconnect.bash that waits for network readiness and then runs plexconnect.py when the network becomes available. Guess there is a timing issue with arch Linux as well. Can you try to lower the timeout to sleep 1 and see if it still works?

https://github.com/wahlmanj/PlexConnect/blob/master/update/OSX/PlexConnect.bash

You may be able to still use the bash if you include it in there similar to how I set it up for OSX.


That's because you are running a hackintosh.
The network readiness codes only kicks in if it detects you are running OSX, it does not do anything for Linux.

Would the network detection work on Linux as well? I guess it would be better to have a "real" test than just a sleep...

Hi all.

Trying to get PlexConnect running on an Arch Linux VM..

Running this command gives an error:

[root@IronicsArchVM_v4 PlexConnect]# ./PlexConnect.py
Traceback (most recent call last):
  File "./PlexConnect.py", line 18, in
    import DNSServer, WebServer
  File "/mnt/data/PlexConnect/DNSServer.py", line 116
    print "ID {0:04x}".format((ord(paket[0])<<8)+ord(paket[1]))
                     ^
SyntaxError: invalid syntax
[root@IronicsArchVM_v4 PlexConnect]# ./PlexConnect.py
Traceback (most recent call last):
  File "./PlexConnect.py", line 18, in
    import DNSServer, WebServer
  File "/mnt/data/PlexConnect/DNSServer.py", line 116
    print "ID {0:04x}".format((ord(paket[0])<<8)+ord(paket[1]))
                     ^
SyntaxError: invalid syntax
 
 
I believe I have python2 so I am not sure what the issue might be.
 
EDIT:
Turns out it was because the python script was trying to use the default python (which is 3) I updated the file a little and it started working by following this:
https://wiki.archlinux.org/index.php/python

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.