Running as root. How do I change this?

Need help? Post your questions here.

Moderator: moderators

Running as root. How do I change this?

Postby fr3d » Fri Jun 04, 2010 6:22 pm

Hi,
First off.. I love the application.

However I noticed that the uploaded files are owned by root. I guess Subsonic is running as root. Is there any way to change this?

I would like it to run automatically as it is now but as user "subsonic". Then I can manage the file and folder permissions better.
I did find a thread talking about it last week but I could not see a conclusion and I cant find it again to post on it.!!

I installed with the Ubuntu link from the download page on to Linux Mint 9 and access it over the network with any PC. Works a treat. I guess I'll be donating soon :-)

Thanks,

Fred.
It is we who live that the music may play.
fr3d
 
Posts: 23
Joined: Fri Jun 04, 2010 8:04 am
Location: Ireland

Postby ccandreva » Fri Jun 04, 2010 6:53 pm

It is possible, I modified the startup scripts to do just this. This was done from the Fedora RPM package, so specifics may need to change for your distribution.

1) Create your subsonic user. I used user/group subsonic, with home directory of /var/subsonic

2) Change owenership of any directories (and everything in them) used to be owned by subsonic. For me this was /var/subsonic and /tmp/subsonic

3) Add this to /etc/sysconfig/subsonic:
Code: Select all
RUNAS_USER=subsonic

This allows you to change the user subsonic runs as from the sysconfig file.

4) Modify the do_start function in /etc/init.d/subsonic to look like this:
Code: Select all
#
# Function that starts the daemon/service
#
do_start()
{
    # Check if daemon is already running.
    if [ -e $PIDFILE ]
    then
        ps -p $(cat $PIDFILE) > /dev/null
        [ "$?" = 0 ] && return 1
    fi

    touch $PIDFILE
    chown $RUNAS_USER $PIDFILE

    echo $"Starting $NAME ..."
    su -c "$DAEMON $DAEMON_ARGS" $RUNAS_USER
    RETVAL=$?
    echo
    [ $RETVAL -eq 0 ] && touch $LOCKFILE
    return $RETVAL
}


5) Make sure all your media files can be read by the subsonic user.

Note this was a hack for my own use. There should prbably be checking to make sure RUNAS_USER is in fact set.
Last edited by ccandreva on Sat Jun 05, 2010 12:30 am, edited 2 times in total.
User avatar
ccandreva
 
Posts: 104
Joined: Fri May 28, 2010 8:22 pm

Postby fr3d » Fri Jun 04, 2010 7:18 pm

Awesome.
Thanks ccandreva. I only posted a moment ago :-)
I guess others will use this too so if there are any improvements anyone can suggest please bring it on.
Perhaps an Ubuntu specific one for unsure Linux users like me.

Thanks again ccandreva. I'll have a careful go.
It is we who live that the music may play.
fr3d
 
Posts: 23
Joined: Fri Jun 04, 2010 8:04 am
Location: Ireland

Postby ccandreva » Sat Jun 05, 2010 2:47 pm

Two things I discovered after I posted.

1) Your Playlists directory needs to be writeable by the subsonic user.

2) If you want to use Jukebox mode, the audio device also needs to be writeable by the subsonic user. In my case I added the subsonic user to group audio (in /etc/groups )

Audio can be tricky. My subsonic is running on a machine that is just a server, so it isn't running X or pulseaudio, just ALSA. Things may be different if pulseaudio is involved.
User avatar
ccandreva
 
Posts: 104
Joined: Fri May 28, 2010 8:22 pm

Postby lavamind » Sun Jun 06, 2010 4:08 pm

I think this should really be changed in the packaging. Running a network-facing application as root goes against every network security principles...
lavamind
 
Posts: 6
Joined: Sun Sep 27, 2009 11:45 pm

Postby fr3d » Sun Jun 06, 2010 7:56 pm

I have been thinking about it a little.
It might be a good compromise to get all the read and write actions to be executed as user "subsonic" then the app can stay running as root but the disk access is restricted and manageable.
Unfortunately I dont know my way around enough to do more than a few copy past type scripts.
Other applications do install themselves and create special users for themselves don't they.. Like virtual box and samba.
Anyway for the moment I'll have to play with ccandrevas script so I can manage the way files are accessed and created.

A 10 cnet question about development.
Is there only one developer or a few?
It a fantastic application so I was wondering if a sponsorship rally would make sense for raising funds to finance more development.
Perhaps if a few specific developments (like running as a user perhaps) were pinpointed we would donate funds towards that group of work.
Then the devs can feel more comfortable spending time doing that thing they do so well :-)
It is we who live that the music may play.
fr3d
 
Posts: 23
Joined: Fri Jun 04, 2010 8:04 am
Location: Ireland

Postby ralyon » Thu Sep 09, 2010 1:45 pm

I followed the suggestions in here, except for as noted below, but I couldn't get subsonic to start. Looking through the logs I found that there was a subsonic folder under tmp that couldn't be accessed. I removed the folder and I was finally able to run it as user subsonic.

I did modify the init.d script a little differently as I noticed ccandreva's modification was quite different then what was originally there.
Code: Select all
+    touch $PIDFILE
+    chown $RUNAS_USER $PIDFILE
-    start-stop-daemon --start --pidfile $PIDFILE --exec $DAEMON -- $DAEMON_ARGS || return 2
+    start-stop-daemon --start --chuid $RUNAS_USER --pidfile $PIDFILE --exec $DAEMON -- $DAEMON_ARGS || return 2


Other than that I modified everything else the way ccandreva suggested. Does this look good or are there problems that might come from doing it this way?

ralyon
ralyon
 
Posts: 4
Joined: Thu Sep 09, 2010 1:09 pm


Return to Help

Who is online

Users browsing this forum: No registered users and 15 guests