styxit / HTPC-Manager

A fully responsive interface to manage all your favorite software on your Htpc.
http://htpc.io
MIT License
529 stars 183 forks source link

/libs/cherrypy/process/plugins.py can't write to PID file #249

Closed maxhan closed 10 years ago

maxhan commented 10 years ago

HTPC manager can't be run as user other than root, because pid file was created with permission 655.

2014-06-26 16:17:48 :: cherrypy.error :: ERROR :: [26/Jun/2014:16:17:48] ENGINE Error in 'start' listener <bound method PIDFile.start of <cherrypy.process.plugins.PIDFile object at 0x1398350>>
Traceback (most recent call last):
  File "/usr/share/HTPCManager/libs/cherrypy/process/wspbus.py", line 197, in publish
    output.append(listener(*args, **kwargs))
  File "/usr/share/HTPCManager/libs/cherrypy/process/plugins.py", line 409, in start
    open(self.pidfile, "wb").write(ntob("%s" % pid, 'utf8'))
IOError: [Errno 13] Permission denied: '/var/run/htpcmanager.pid'
styxit commented 10 years ago

What method are you using to start HTPC-Manager. You are using the initd file?

maxhan commented 10 years ago

Yes, here is the init file

#! /bin/sh

### BEGIN INIT INFO
# Provides:          HTPC-Manager application instance
# Required-Start:    $all
# Required-Stop:     $all
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
# Short-Description: starts instance of HTPC-Manager
# Description:       starts instance of HTPC-Manager
### END INIT INFO

# Source function library.
. /etc/init.d/functions

############### How to  ##################
#Copy this file to your /etc/init.d/htpc or whatever you would like to name it.
#Ensure file is executable "chmod +x htpc".
#Edit the fields in the EDIT ME section below for your preferences.
#Enable services at startup by "chkconfig htpc on" or "systemctl enable htpc"

############### EDIT ME ##################
# PID & Lock.  Change if you would like your lock/pid elsewhere.
PID_FILE=/var/run/htpcmanager.pid
LOCK_FILE=/var/lock/subsys/${NAME}
# path to app
APP_PATH=/usr/share/HTPCManager
# path to python bin (must be changed to python, use which python to find path)
DAEMON=/usr/bin/python
# startup args
# Script that will be ran, doesn't need to be changed
DAEMON_OPTS="Htpc.py"
# Options you wish to use, OK to change these items however PID is needed for stopping and restarting.  Leave the space at the beginning.
OPTIONS=" --daemon --pid=$PID_FILE"
# script name (doesn't need to be changed)
NAME=htpc
# app name
DESC=HTPC-Manager
# User you want to run service as
RUN_AS=media
############### END EDIT ME ##################

start() {
        echo "Starting $DESC: "
        touch ${PID_FILE}
        daemon --user=${RUN_AS} --pidfile=${PID_FILE} python ${APP_PATH}/${DAEMON_OPTS}${OPTIONS}
                RETVAL=$?
                echo
                [ $RETVAL -eq 0 ] && touch ${LOCK_FILE}
                return $RETVAL
}
stop()  {
        echo "Stopping $DESC: "
        killproc -p ${PID_FILE} python
                RETVAL=$?
                echo
                [ $RETVAL -eq 0 ] && rm -f ${LOCK_FILE}
        return $RETVAL
}

# How we will call the options
case "$1" in
  start)
        start
        ;;
  stop)
        stop
        ;;
  restart|force-reload)
        stop
        start
        ;;
  *)
        echo $"Usage: $0 {start|stop|restart|force-reload}"
        exit 2
esac

exit 0
styxit commented 10 years ago

Did you follow these steps?

  1. Copy this file to your /etc/init.d/htpc or whatever you would like to name it.
  2. Ensure file is executable "chmod +x htpc".
  3. Edit the fields in the EDIT ME section below for your preferences.
  4. Enable services at startup by "chkconfig htpc on" or "systemctl enable htpc"
styxit commented 10 years ago

Maybe the creator for this initd file can help you. @asmozre

maxhan commented 10 years ago

Yes sir, the issue is that /libs/cherrypy/process/plugins.py try to write to the pid file, however, since it has rw-r--r-- permission and owned by root, the user I am running HTPC manager as can not write to it.

asmozre commented 10 years ago

This should fix your issues.

mkdir /var/run/htpc chown user:group /var/run/htpc/

Where user:group is your user/group for the one you wish to run htpc as.

Modify the init file PID_FILE as below. PID_FILE=/var/run/htpcmanager.pid to /var/run/htpc/htpcmanager.pid

maxhan commented 10 years ago

First of all, thanks the the quickest response ever! I have tried that, however, the pid file was still created and owned by root. The same issue for SickBeard and Headphones.

IOError: [Errno 13] Permission denied: '/var/run/media/htpcmanager.pid'
asmozre commented 10 years ago

What does ls -ahl /var/run/media give you?

maxhan commented 10 years ago

You mean /var/run?

drwxr-xr-x  2 media media  4.0K Jun 26 18:09 media

I remade the folder just to show you, I tried 0777 for the folder too, no luck.

maxhan commented 10 years ago
[root@Kate max]# ls -ahl /var/run/media
total 8.0K
drwxr-xr-x  2 media media 4.0K Jun 26 18:09 .
drwxr-xr-x 17 root  root  4.0K Jun 26 18:09 ..
asmozre commented 10 years ago

If you're using user 'media' in the init file, the PID should create fine. You did modify the init file to make the PID in this media directory, correct?

There doesn't appear to be any PID files there already from what you pasted above but if they are there and just not listed above you may need to remove them before starting the service.

maxhan commented 10 years ago

Yes, the pid file is made within the media folder, but it's owned by root. After the write attempt is denied and the service startup fails, the pid file is then automatically deleted.

I should clarify, the pid file creation was not the issue, the issue is /libs/cherrypy/process/plugins.py can not write to the pid file owned by root with rw-r--r-- permission.

Is there a way to change the pid permission while it was created? Say to rw-rw-rw would probably solve the problem. And I don't know how to do that.

asmozre commented 10 years ago

Try removing the following line from the init file.

touch ${PID_FILE}

Which may be creating the file as root first and then not allowing access to it.

maxhan commented 10 years ago

No luck :/ same issue. Pid is still owned by root, 655.

  File "/usr/share/HTPCManager/libs/cherrypy/process/plugins.py", line 409, in start
    open(self.pidfile, "wb").write(ntob("%s" % pid, 'utf8'))
IOError: [Errno 13] Permission denied: '/var/run/htpcmanager.pid'
asmozre commented 10 years ago

IOError: [Errno 13] Permission denied: '/var/run/htpcmanager.pid'

Your init file needs the path to /var/run/media/htpcmanager.pid based on that error. Also you haven't messed with any file acl's have you?

maxhan commented 10 years ago

In media folder owned by media:media or not, the pid file is still owned by root and media can't write to it. I did not modify acl and selinux is off.

asmozre commented 10 years ago

You said you were having the problem with sickbeard and headphones as well?

Can you run it manually? Without using inits?

Also what are you running? cat /etc/redhat-release

maxhan commented 10 years ago

They run fine as root, I just don't want to run them as root, sickbeard and headphones both spawn 655 pid and later request to write to them as well.

[max@Kate ~]$ cat /etc/*-release
CentOS release 6.5 (Final)
asmozre commented 10 years ago

You could always just add a step as a work around in the init file to chmod 777 or even change the owner the spawned pid file just after its created. You would need to have a touch with the pid path and file then the chown or chmod. It's not pretty but it might resolve the issue for you. On Jun 26, 2014 2:47 PM, "maxhan" notifications@github.com wrote:

They run fine as root, I just don't want to run them as root, sickbeard and headphones both spawn 655 pid and later request to write to them as well.

[max@Kate ~]$ cat /etc/*-release CentOS release 6.5 (Final)

— Reply to this email directly or view it on GitHub https://github.com/styxit/HTPC-Manager/issues/249#issuecomment-47263974.

maxhan commented 10 years ago

Ok, I will give it a try. I thought there would be some trick I am missing to spawn pid with a certain permission. Thanks!

styxit commented 10 years ago

Can i close this issue?