Autostart issues...

This forum is for discussion about general software issues.

Autostart issues...

Postby odinb » Wed Jan 29, 2014 1:47 am

Hi!

Trying to autostart a pyhon script, and have tried all sorts of things, but cannot get it to work.
https://github.com/iBaa/PlexConnect

Current status:

Have put PlexConnect in this path: /home/PlexConnect-master

I then created a systemd service file like this (located in /etc/systemd/system/PlexConnect.service):

$this->bbcode_second_pass_code('', '[Unit]
Description=PlexConnect service
# Make sure we have functional network and logging available
After=syslog.target
After=network.target
After=default.target

[Service]
# Allow process forking or oneshot
ExecStart=/home/PlexConnect-master/PlexConnect.sh start
Type=forking
RemainAfterExit=yes
# Give a reasonable amount of time for the server to start up/shut down
TimeoutSec=10

[Install]
WantedBy=multi-user.target')

To make it start on boot, I used:
$this->bbcode_second_pass_code('', 'systemctl enable PlexConnect')

The PlexConnect.sh file is set to 755, and contains:
$this->bbcode_second_pass_code('', '#!/bin/bash

/home/PlexConnect-master/PlexConnect.py')

If I run it from the terminal, it works just fine:
$this->bbcode_second_pass_code('', '[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 try to run it using sysctl it fails:
$this->bbcode_second_pass_code('', '[root@alarm PlexConnect-master]# systemctl status PlexConnect.service
PlexConnect.service - PlexConnect service
Loaded: loaded (/etc/systemd/system/PlexConnect.service; enabled)
Active: failed (Result: timeout) since Tue 2014-01-28 19:44:30 CST; 22s ago
Process: 295 ExecStart=/home/PlexConnect-master/PlexConnect.sh (code=killed, signal=TERM)

Jan 28 19:44:22 alarm PlexConnect.sh[295]: 19:44:22 PlexConnect: ***
Jan 28 19:44:22 alarm PlexConnect.sh[295]: 19:44:22 PlexConnect: started: 19:44:22
Jan 28 19:44:22 alarm PlexConnect.sh[295]: 19:44:22 PlexConnect: Version: 0.3.1+
Jan 28 19:44:22 alarm PlexConnect.sh[295]: 19:44:22 PlexConnect: Python: 2.7.6 (default, Nov 29 2013, 11:17:54)
Jan 28 19:44:22 alarm PlexConnect.sh[295]: [GCC 4.7.2]
Jan 28 19:44:22 alarm PlexConnect.sh[295]: 19:44:22 PlexConnect: Host OS: linux2
Jan 28 19:44:22 alarm PlexConnect.sh[295]: 19:44:22 PlexConnect: IP_self: 192.168.1.96
Jan 28 19:44:30 alarm systemd[1]: PlexConnect.service operation timed out. Terminating.
Jan 28 19:44:30 alarm systemd[1]: Failed to start PlexConnect service.
Jan 28 19:44:30 alarm systemd[1]: Unit PlexConnect.service entered failed state.
[root@alarm PlexConnect-master]#')

What am I doing wrong?
odinb
 
Posts: 9
Joined: Wed Jan 29, 2014 1:27 am

Re: Autostart issues...

Postby moonman » Wed Jan 29, 2014 3:05 am

use type oneshot or simple and prefix with /usr/bin/sh
Pogoplug V4 | GoFlex Home | Raspberry Pi 4 4GB | CuBox-i4 Pro | ClearFog | BeagleBone Black | Odroid U2 | Odroid C1 | Odroid XU4
-----------------------------------------------------------------------------------------------------------------------
[armv5] Updated U-Boot | [armv5] NAND Rescue System
moonman
Developer
 
Posts: 3387
Joined: Sat Jan 15, 2011 3:36 am

Re: Autostart issues...

Postby odinb » Wed Jan 29, 2014 3:22 am

Ok, changed to:
$this->bbcode_second_pass_code('', '[Unit]
Description=PlexConnect service
# Make sure we have functional network and logging available
After=syslog.target
After=network.target
After=default.target

[Service]
# Allow process forking or oneshot
ExecStart=/usr/bin/sh /home/PlexConnect-master/PlexConnect.sh
Type=simple
RemainAfterExit=yes
# Give a reasonable amount of time for the server to start up/shut down
TimeoutSec=10

[Install]
WantedBy=multi-user.target
')

and now it starts when I do:
$this->bbcode_second_pass_code('', '[root@alarm ~]# systemctl start PlexConnect
[root@alarm ~]# ps -ef | grep Plex
root 247 1 0 21:21 ? 00:00:00 /usr/bin/sh /home/PlexConnect-master/PlexConnect.sh
root 248 247 23 21:21 ? 00:00:01 python2 ./PlexConnect.py
root 251 248 0 21:21 ? 00:00:00 python2 ./PlexConnect.py
root 252 248 1 21:21 ? 00:00:00 python2 ./PlexConnect.py
root 253 248 0 21:21 ? 00:00:00 python2 ./PlexConnect.py
root 255 240 0 21:21 pts/0 00:00:00 grep Plex
[root@alarm ~]#
')

but not after reboot:
$this->bbcode_second_pass_code('', '[root@alarm ~]# ps -ef | grep Plex
root 242 240 0 18:00 pts/0 00:00:00 grep Plex
[root@alarm ~]# systemctl status PlexConnect
PlexConnect.service - PlexConnect service
Loaded: loaded (/etc/systemd/system/PlexConnect.service; enabled)
Active: inactive (dead)

[root@alarm ~]#')
odinb
 
Posts: 9
Joined: Wed Jan 29, 2014 1:27 am

Re: Autostart issues...

Postby moonman » Wed Jan 29, 2014 5:45 am

I don't know where you got these targets (default syslog).

https://wiki.archlinux.org/index.php/Systemd#Targets

Remove all of them except for the network target.
Pogoplug V4 | GoFlex Home | Raspberry Pi 4 4GB | CuBox-i4 Pro | ClearFog | BeagleBone Black | Odroid U2 | Odroid C1 | Odroid XU4
-----------------------------------------------------------------------------------------------------------------------
[armv5] Updated U-Boot | [armv5] NAND Rescue System
moonman
Developer
 
Posts: 3387
Joined: Sat Jan 15, 2011 3:36 am

Re: Autostart issues...

Postby odinb » Thu Jan 30, 2014 3:33 am

Nope, still no go:

$this->bbcode_second_pass_code('', 'PlexConnect.service - PlexConnect service
Loaded: loaded (/etc/systemd/system/PlexConnect.service; enabled)
Active: failed (Result: exit-code) since Wed 1969-12-31 18:00:18 CST; 1min 53s ago
Process: 109 ExecStart=/usr/bin/sh /home/PlexConnect-master/PlexConnect.sh (code=exited, status=1/FAILURE)
Main PID: 109 (code=exited, status=1/FAILURE)

Dec 31 18:00:11 alarm systemd[1]: Starting PlexConnect service...
Dec 31 18:00:18 alarm sh[109]: 18:00:16 PlexConnect: ***
Dec 31 18:00:18 alarm sh[109]: 18:00:16 PlexConnect: PlexConnect
Dec 31 18:00:18 alarm sh[109]: 18:00:16 PlexConnect: Press CTRL-C to shut down.
Dec 31 18:00:18 alarm sh[109]: 18:00:16 PlexConnect: ***
Dec 31 18:00:18 alarm systemd[1]: PlexConnect.service: main process exited, code=exited, status=1/FAILURE
Dec 31 18:00:18 alarm systemd[1]: Failed to start PlexConnect service.
Dec 31 18:00:18 alarm systemd[1]: Unit PlexConnect.service entered failed state.
[root@alarm ~]#
')

File looks like this now:

$this->bbcode_second_pass_code('', '[root@alarm ~]# cat /etc/systemd/system/PlexConnect.service
[Unit]
Description=PlexConnect service
# Make sure we have functional network and logging available
After=network.target

[Service]
# Allow process forking or oneshot
ExecStart=/usr/bin/sh /home/PlexConnect-master/PlexConnect.sh
Type=oneshot
RemainAfterExit=yes
# Give a reasonable amount of time for the server to start up/shut down
TimeoutSec=20

[Install]
WantedBy=multi-user.target
[root@alarm ~]#
')
odinb
 
Posts: 9
Joined: Wed Jan 29, 2014 1:27 am

Re: Autostart issues...

Postby odinb » Thu Jan 30, 2014 3:55 am

I get the feeling it is something with the network, I think it bails because the network is still coming up.

Unsuccesful boot:
$this->bbcode_second_pass_code('', '[root@alarm ~]# cat /home/PlexConnect-master/PlexConnect.log
18:00:17 PlexConnect: started: 18:00:17
18:00:17 PlexConnect: Version: 0.3.1+
18:00:17 PlexConnect: Python: 2.7.6 (default, Nov 29 2013, 11:17:54)
[GCC 4.7.2]
18:00:17 PlexConnect: Host OS: linux2
[root@alarm ~]# systemctl status PlexConnect
PlexConnect.service - PlexConnect service
Loaded: loaded (/etc/systemd/system/PlexConnect.service; enabled)
Active: failed (Result: exit-code) since Wed 1969-12-31 18:00:17 CST; 34s ago
Process: 109 ExecStart=/usr/bin/sh /home/PlexConnect-master/PlexConnect.sh (code=exited, status=1/FAILURE)

Dec 31 18:00:17 alarm sh[109]: 18:00:15 PlexConnect: ***
Dec 31 18:00:17 alarm sh[109]: 18:00:15 PlexConnect: PlexConnect
Dec 31 18:00:17 alarm sh[109]: 18:00:15 PlexConnect: Press CTRL-C to shut down.
Dec 31 18:00:17 alarm sh[109]: 18:00:15 PlexConnect: ***
Dec 31 18:00:17 alarm sh[109]: 18:00:17 PlexConnect: started: 18:00:17
Dec 31 18:00:17 alarm sh[109]: 18:00:17 PlexConnect: Version: 0.3.1+
Dec 31 18:00:17 alarm systemd[1]: PlexConnect.service: control process exited, code=exited status=1
Dec 31 18:00:17 alarm systemd[1]: Failed to start PlexConnect service.
Dec 31 18:00:17 alarm systemd[1]: Unit PlexConnect.service entered failed state.
[root@alarm ~]#
')

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

Current config file:
$this->bbcode_second_pass_code('', '[root@alarm ~]# cat /etc/systemd/system/PlexConnect.service
[Unit]
Description=PlexConnect service
# Make sure we have functional network and logging 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
# Give a reasonable amount of time for the server to start up/shut down
TimeoutSec=20

[Install]
WantedBy=multi-user.target
[root@alarm ~]#
')
odinb
 
Posts: 9
Joined: Wed Jan 29, 2014 1:27 am

Re: Autostart issues...

Postby moonman » Thu Jan 30, 2014 4:26 am

you could try adding Restart=always or ExecStatPre = sleep 15
Pogoplug V4 | GoFlex Home | Raspberry Pi 4 4GB | CuBox-i4 Pro | ClearFog | BeagleBone Black | Odroid U2 | Odroid C1 | Odroid XU4
-----------------------------------------------------------------------------------------------------------------------
[armv5] Updated U-Boot | [armv5] NAND Rescue System
moonman
Developer
 
Posts: 3387
Joined: Sat Jan 15, 2011 3:36 am

Re: Autostart issues...

Postby odinb » Thu Jan 30, 2014 4:59 am

This time it works for about a minute and a half, then it shuts down. I set logging to high:
$this->bbcode_second_pass_code('', '[root@alarm ~]# systemctl status PlexConnect
PlexConnect.service - PlexConnect service
Loaded: loaded (/etc/systemd/system/PlexConnect.service; enabled)
Active: activating (auto-restart) (Result: exit-code) since Wed 1969-12-31 18:00:17 CST; 47s ago
Process: 108 ExecStart=/usr/bin/sh /home/PlexConnect-master/PlexConnect.sh (code=exited, status=1/FAILURE)

Dec 31 18:00:17 alarm systemd[1]: Failed to start PlexConnect service.
Dec 31 18:00:17 alarm systemd[1]: Unit PlexConnect.service entered failed state.
[root@alarm ~]# cat /home/PlexConnect-master/PlexConnect.log
18:00:16 PlexConnect: started: 18:00:16
18:00:16 PlexConnect: Version: 0.3.1+
18:00:16 PlexConnect: Python: 2.7.6 (default, Nov 29 2013, 11:17:54)
[GCC 4.7.2]
18:00:16 PlexConnect: Host OS: linux2
18:00:16 Settings: getsetting enable_plexconnect_autodetect=True
[root@alarm ~]# date
Wed Dec 31 18:01:42 CST 1969
[root@alarm ~]# systemctl status PlexConnect
PlexConnect.service - PlexConnect service
Loaded: loaded (/etc/systemd/system/PlexConnect.service; enabled)
Active: activating (start) since Wed 1969-12-31 18:01:17 CST; 30s ago
Control: 253 (sh)
CGroup: /system.slice/PlexConnect.service
├─253 /usr/bin/sh /home/PlexConnect-master/PlexConnect.sh
├─254 python2 ./PlexConnect.py
├─257 python2 ./PlexConnect.py
├─258 python2 ./PlexConnect.py
└─259 python2 ./PlexConnect.py

Dec 31 18:01:18 alarm sh[253]: 18:01:18 PlexConnect: ***
Dec 31 18:01:18 alarm sh[253]: 18:01:18 PlexConnect: PlexConnect
Dec 31 18:01:18 alarm sh[253]: 18:01:18 PlexConnect: Press CTRL-C to shut down.
Dec 31 18:01:18 alarm sh[253]: 18:01:18 PlexConnect: ***
Dec 31 18:01:18 alarm sh[253]: 18:01:18 PlexConnect: started: 18:01:18
Dec 31 18:01:18 alarm sh[253]: 18:01:18 PlexConnect: Version: 0.3.1+
Dec 31 18:01:18 alarm sh[253]: 18:01:18 PlexConnect: Python: 2.7.6 (default, Nov 29 2013, 11:17:54)
Dec 31 18:01:18 alarm sh[253]: [GCC 4.7.2]
Dec 31 18:01:18 alarm sh[253]: 18:01:18 PlexConnect: Host OS: linux2
Dec 31 18:01:18 alarm sh[253]: 18:01:18 PlexConnect: IP_self: 192.168.1.96
[root@alarm ~]# cat /home/PlexConnect-master/PlexConnect.log
18:01:18 PlexConnect: started: 18:01:18
18:01:18 PlexConnect: Version: 0.3.1+
18:01:18 PlexConnect: Python: 2.7.6 (default, Nov 29 2013, 11:17:54)
[GCC 4.7.2]
18:01:18 PlexConnect: Host OS: linux2
18:01:18 Settings: getsetting enable_plexconnect_autodetect=True
18:01:18 PlexConnect: IP_self: 192.168.1.96
18:01:18 Settings: getsetting hosttointercept=trailers.apple.com
18:01:18 Settings: getsetting port_webserver=80
18:01:18 Settings: getsetting enable_dnsserver=True
18:01:18 DNSServer: started: 18:01:18
18:01:18 Settings: getsetting port_dnsserver=53
18:01:18 Settings: getsetting ip_dnsmaster=8.8.8.8
18:01:18 Settings: getsetting prevent_atv_update=True
18:01:18 DNSServer: ***
18:01:18 DNSServer: DNSServer: Serving DNS on 192.168.1.96 port 53.
18:01:18 DNSServer: intercept: ['trailers.apple.com'] => 192.168.1.96
18:01:18 DNSServer: restrain: ['mesu.apple.com', 'appldnld.apple.com', 'appldnld.apple.com.edgesuite.net'] => 127.0.0.1
18:01:18 DNSServer: forward other to higher level DNS: 8.8.8.8
18:01:18 DNSServer: ***
18:01:18 WebServer: started: 18:01:18
18:01:18 Settings: getsetting port_webserver=80
18:01:18 WebServer: ***
18:01:18 WebServer: WebServer: Serving HTTP on 192.168.1.96 port 80.
18:01:18 WebServer: ***
18:01:18 ATVSettings: init class CATVSettings
18:01:18 ATVSettings: load settings
18:01:18 Settings: getsetting enable_webserver_ssl=True
18:01:18 WebServer: started: 18:01:18
18:01:18 Settings: getsetting port_ssl=443
18:01:18 Settings: getsetting certfile=./assets/certificates/trailers.pem
18:01:18 Settings: getsetting certfile=./assets/certificates/trailers.pem
18:01:18 WebServer: ***
18:01:18 WebServer: WebServer: Serving HTTPS on 192.168.1.96 port 443.
18:01:18 WebServer: ***
[root@alarm ~]# ps -ef | grep Plex
root 253 1 0 18:01 ? 00:00:00 /usr/bin/sh /home/PlexConnect-master/PlexConnect.sh
root 254 253 1 18:01 ? 00:00:01 python2 ./PlexConnect.py
root 257 254 0 18:01 ? 00:00:00 python2 ./PlexConnect.py
root 258 254 0 18:01 ? 00:00:00 python2 ./PlexConnect.py
root 259 254 0 18:01 ? 00:00:00 python2 ./PlexConnect.py
root 266 245 0 18:02 pts/0 00:00:00 grep Plex
[root@alarm ~]# systemctl status PlexConnect
PlexConnect.service - PlexConnect service
Loaded: loaded (/etc/systemd/system/PlexConnect.service; enabled)
Active: activating (start) since Wed 1969-12-31 18:01:17 CST; 1min 26s ago
Control: 253 (sh)
CGroup: /system.slice/PlexConnect.service
├─253 /usr/bin/sh /home/PlexConnect-master/PlexConnect.sh
├─254 python2 ./PlexConnect.py
├─257 python2 ./PlexConnect.py
├─258 python2 ./PlexConnect.py
└─259 python2 ./PlexConnect.py

Dec 31 18:01:18 alarm sh[253]: 18:01:18 PlexConnect: ***
Dec 31 18:01:18 alarm sh[253]: 18:01:18 PlexConnect: PlexConnect
Dec 31 18:01:18 alarm sh[253]: 18:01:18 PlexConnect: Press CTRL-C to shut down.
Dec 31 18:01:18 alarm sh[253]: 18:01:18 PlexConnect: ***
Dec 31 18:01:18 alarm sh[253]: 18:01:18 PlexConnect: started: 18:01:18
Dec 31 18:01:18 alarm sh[253]: 18:01:18 PlexConnect: Version: 0.3.1+
Dec 31 18:01:18 alarm sh[253]: 18:01:18 PlexConnect: Python: 2.7.6 (default, Nov 29 2013, 11:17:54)
Dec 31 18:01:18 alarm sh[253]: [GCC 4.7.2]
Dec 31 18:01:18 alarm sh[253]: 18:01:18 PlexConnect: Host OS: linux2
Dec 31 18:01:18 alarm sh[253]: 18:01:18 PlexConnect: IP_self: 192.168.1.96
[root@alarm ~]# cat /home/PlexConnect-master/PlexConnect.log
18:01:18 PlexConnect: started: 18:01:18
18:01:18 PlexConnect: Version: 0.3.1+
18:01:18 PlexConnect: Python: 2.7.6 (default, Nov 29 2013, 11:17:54)
[GCC 4.7.2]
18:01:18 PlexConnect: Host OS: linux2
18:01:18 Settings: getsetting enable_plexconnect_autodetect=True
18:01:18 PlexConnect: IP_self: 192.168.1.96
18:01:18 Settings: getsetting hosttointercept=trailers.apple.com
18:01:18 Settings: getsetting port_webserver=80
18:01:18 Settings: getsetting enable_dnsserver=True
18:01:18 DNSServer: started: 18:01:18
18:01:18 Settings: getsetting port_dnsserver=53
18:01:18 Settings: getsetting ip_dnsmaster=8.8.8.8
18:01:18 Settings: getsetting prevent_atv_update=True
18:01:18 DNSServer: ***
18:01:18 DNSServer: DNSServer: Serving DNS on 192.168.1.96 port 53.
18:01:18 DNSServer: intercept: ['trailers.apple.com'] => 192.168.1.96
18:01:18 DNSServer: restrain: ['mesu.apple.com', 'appldnld.apple.com', 'appldnld.apple.com.edgesuite.net'] => 127.0.0.1
18:01:18 DNSServer: forward other to higher level DNS: 8.8.8.8
18:01:18 DNSServer: ***
18:01:18 WebServer: started: 18:01:18
18:01:18 Settings: getsetting port_webserver=80
18:01:18 WebServer: ***
18:01:18 WebServer: WebServer: Serving HTTP on 192.168.1.96 port 80.
18:01:18 WebServer: ***
18:01:18 ATVSettings: init class CATVSettings
18:01:18 ATVSettings: load settings
18:01:18 Settings: getsetting enable_webserver_ssl=True
18:01:18 WebServer: started: 18:01:18
18:01:18 Settings: getsetting port_ssl=443
18:01:18 Settings: getsetting certfile=./assets/certificates/trailers.pem
18:01:18 Settings: getsetting certfile=./assets/certificates/trailers.pem
18:01:18 WebServer: ***
18:01:18 WebServer: WebServer: Serving HTTPS on 192.168.1.96 port 443.
18:01:18 WebServer: ***
18:02:47 PlexConnect: Shutting down.
18:02:47 DNSServer: Warning: DNS error (4): Interrupted system call
18:02:47 DNSServer: Shutting down.
18:02:47 PlexConnect: Shutting down.
18:02:47 PlexConnect: Shutting down.
18:02:47 PlexConnect: Shutting down.
18:02:48 WebServer: Shutting down.
18:02:48 WebServer: Shutting down.
18:02:48 ATVSettings: save settings
18:02:48 PlexConnect: shutdown
[root@alarm ~]# systemctl status PlexConnect
PlexConnect.service - PlexConnect service
Loaded: loaded (/etc/systemd/system/PlexConnect.service; enabled)
Active: activating (auto-restart) (Result: timeout) since Wed 1969-12-31 18:02:47 CST; 32s ago
Process: 253 ExecStart=/usr/bin/sh /home/PlexConnect-master/PlexConnect.sh (code=killed, signal=TERM)

Dec 31 18:02:47 alarm systemd[1]: Failed to start PlexConnect service.
Dec 31 18:02:47 alarm systemd[1]: Unit PlexConnect.service entered failed state.
[root@alarm ~]# ps -ef | grep Plex
root 272 245 0 18:03 pts/0 00:00:00 grep Plex
[root@alarm ~]#
')

But it shuts down for some reason after 1.5 min, then starts up again:
$this->bbcode_second_pass_code('', '22:56:12 WebServer: WebServer: Serving HTTPS on 192.168.1.96 port 443.
22:56:12 WebServer: ***
22:57:40 PlexConnect: Shutting down.
22:57:40 DNSServer: Warning: DNS error (4): Interrupted system call
22:57:40 DNSServer: Shutting down.
22:57:40 PlexConnect: Shutting down.
22:57:40 PlexConnect: Shutting down.
22:57:40 PlexConnect: Shutting down.
22:57:41 WebServer: Shutting down.
22:57:41 WebServer: Shutting down.
22:57:41 ATVSettings: save settings
22:57:41 PlexConnect: shutdown
')

This behaviour seems cyclic, and does not happne if i start it maually...

Current config file:
$this->bbcode_second_pass_code('', '[root@alarm ~]# cat /etc/systemd/system/PlexConnect.service
[Unit]
Description=PlexConnect service
# Make sure we have functional network and logging 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
# Give a reasonable amount of time for the server to start up/shut down
Restart=always
RestartSec=60

[Install]
WantedBy=multi-user.target
[root@alarm ~]#
')
odinb
 
Posts: 9
Joined: Wed Jan 29, 2014 1:27 am

Re: Autostart issues...

Postby odinb » Sun Feb 02, 2014 3:19 am

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:
$this->bbcode_second_pass_code('', '[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:
$this->bbcode_second_pass_code('', '#!/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:
$this->bbcode_second_pass_code('', 'systemctl enable PlexConnect')
Then reboot your machine:
$this->bbcode_second_pass_code('', '/sbin/reboot')
After this, PlexConnect now starts at boot-up!

Useful commands to troubleshoot this are:

List active service Status:
$this->bbcode_second_pass_code('', 'systemctl list-units')
Detailed log of what happened:
$this->bbcode_second_pass_code('', 'journalctl -xn')
Last edited by odinb on Mon Feb 03, 2014 4:31 pm, edited 1 time in total.
odinb
 
Posts: 9
Joined: Wed Jan 29, 2014 1:27 am

Re: Autostart issues...

Postby moonman » Sun Feb 02, 2014 3:25 am

There is no missing environment variable. pyhon3 is the default. python 2 and 3 are not compatible, so for 2 to coexist python2 is there. Read ArchWiki python page for more info on the subject. Congrats for getting it to work
Pogoplug V4 | GoFlex Home | Raspberry Pi 4 4GB | CuBox-i4 Pro | ClearFog | BeagleBone Black | Odroid U2 | Odroid C1 | Odroid XU4
-----------------------------------------------------------------------------------------------------------------------
[armv5] Updated U-Boot | [armv5] NAND Rescue System
moonman
Developer
 
Posts: 3387
Joined: Sat Jan 15, 2011 3:36 am


Return to General

Who is online

Users browsing this forum: No registered users and 13 guests