Jump to content


Photo

Ubuntu service script


  • Please log in to reply
24 replies to this topic

#1 puithove

puithove

    Dedicated Member

  • Members
  • PipPipPip
  • 407 posts

Posted 14 May 2011 - 05:04 PM

Anybody put together a service script for Ubuntu yet?

#2 puithove

puithove

    Dedicated Member

  • Members
  • PipPipPip
  • 407 posts

Posted 14 May 2011 - 06:52 PM

Well, I learned a thing or two about "upstart" and got this config put together. It's extremely simplistic but seems to do what I was wanting. It will start and stop the PMS and it will also respawn if the process exits without issuing the stop command (such as a process crash).

do this:

sudo nano /etc/init/plexpms.conf


Paste the following into the file - you'll have to modify it with the path to wherever you put your PMS folder. Also notice at the end of the "su" line change "tvs" to the name of the user you want to execute PMS as.

# plexpms - service job file

description "Plex PMS"
author "Plex Gods"

# When to start the service
start on runlevel [2345]

# When to stop the service
stop on runlevel [016]

# Automatically restart process if crashed
respawn

# Sets nice and ionice level for job
nice -5

# What to execute
script
        cd /home/tvs/PlexMediaServer
        su -c ./start.sh tvs
end script


Now PMS will start at system boot running as user "tvs" and will be stopped prior to system shutdown.

You can stop the service manually by:
sudo service plexpms stop

or start it manually by
sudo service plexpms start

Enjoy!

#3 serak

serak

    Member

  • Members
  • PipPip
  • 18 posts

Posted 14 May 2011 - 07:31 PM

Thanks puithove, this works well. Saved me having to do look into it myself haha

#4 Fevida

Fevida

    Member

  • Members
  • PipPip
  • 56 posts
  • Location: Netherlands

Posted 14 May 2011 - 07:43 PM

Thnx for sharing, working great!

Plex Media Center on: Intel NUC with Ubuntu 13.10
Plex for iOS on: iPad & iPhone 4
Plex Media Server on: Ubuntu 13.10

all-thin-banner.jpg


#5 agentbikes

agentbikes

    Member

  • Members
  • PipPip
  • 51 posts

Posted 14 May 2011 - 07:56 PM

I'm trying to install this via SSH (terminal) from my Mac. Does anyone know how to save the script in GNU nano?

Thanks!

#6 Fevida

Fevida

    Member

  • Members
  • PipPip
  • 56 posts
  • Location: Netherlands

Posted 14 May 2011 - 07:57 PM

Ctrl + X

Plex Media Center on: Intel NUC with Ubuntu 13.10
Plex for iOS on: iPad & iPhone 4
Plex Media Server on: Ubuntu 13.10

all-thin-banner.jpg


#7 agentbikes

agentbikes

    Member

  • Members
  • PipPip
  • 51 posts

Posted 14 May 2011 - 08:08 PM

Thanks puithove the script works like a charm.
Thank you, too, Fevida for the fast reply ;)

#8 puithove

puithove

    Dedicated Member

  • Members
  • PipPipPip
  • 407 posts

Posted 14 May 2011 - 09:11 PM

Cool - glad it's helping you guys.

#9 thomashw

thomashw

    Dedicated Member

  • Members
  • PipPipPip
  • 139 posts

Posted 14 May 2011 - 11:42 PM

Thanks for the script. Works great.

Follow me on Twitter! @thomashw


#10 Alan Morgan

Alan Morgan

    Rock Star

  • Castle Keeper
  • PipPipPipPipPip
  • 770 posts

Posted 15 May 2011 - 09:17 AM

Thanks, that looks a lot cleaner than the SysV init scripts I've had to deal with in the past. Hurray for upstart!
Former member of the Plex for Roku development team

Units Owned: Roku 1 XD, Roku 2 XS

Posted Image

#11 Jamie Kirkpatrick

Jamie Kirkpatrick

    Dedicated Member

  • Members
  • PipPipPip
  • 136 posts

Posted 20 May 2011 - 06:54 AM

Good work!

#12 elan

elan

    Sheriff of Plexville

  • Sheriff Of Plexville
  • PipPipPipPipPipPip
  • 7412 posts
  • Location: Maui

Posted 20 May 2011 - 08:40 AM

Very nice, thanks!

Instagram: @elan
The Plex blog.
The wife's photography site.
The brother's photography blog.
The dog's twitter feed.


#13 puithove

puithove

    Dedicated Member

  • Members
  • PipPipPip
  • 407 posts

Posted 25 June 2011 - 01:46 PM

I decided I wanted to set a higher priority especially for the ffmpeg process for transcoding. Sure enough Upstart has the "nice" stanza. The job is then started with that priority setting and any spawned processes (including ffmpeg) inherit it. This sets the ionice priority to the same as well. Very clean and "nice"! Posted Image

I've updated the top post with the nice stanza.

On a related note I set sabnzbd which also runs on this machine to a lower priority to keep it from interfering when it's doing its par2 and unrar stuff (fairly io intensive).

#14 agentbikes

agentbikes

    Member

  • Members
  • PipPip
  • 51 posts

Posted 25 June 2011 - 02:09 PM

On a related note I set sabnzbd which also runs on this machine to a lower priority to keep it from interfering when it's doing its par2 and unrar stuff (fairly io intensive).


Does it help? If I'm watching a movie and sab starts unpacking the movie stutters like hell. :angry:
Could you also describe how I can do that?

#15 puithove

puithove

    Dedicated Member

  • Members
  • PipPipPip
  • 407 posts

Posted 25 June 2011 - 05:54 PM

Does it help? If I'm watching a movie and sab starts unpacking the movie stutters like hell. :angry:
Could you also describe how I can do that?


Yes, it definitely will help. Check out this thread over on the Sab forums: http://forums.sabnzb...hp?topic=5052.0

#16 nhix

nhix

    Member

  • Members
  • PipPip
  • 11 posts

Posted 11 July 2011 - 02:41 AM

Hey puithove, awesome upstart script. I'm having a little trouble getting plex to start up. I have no problems running the start.sh script, but when I try to run

sudo service plexmediaserver start

I'm seeing this error in syslog when I change the user in the script to a system user (in my case I created a user called plex)

plexmediaserver main process (3236) terminated with status 1

I'm seeing this error in syslog when I add my normal login to the script above (I tried this as I am able to start up plex manually with no problem)

plexmediaserver main process (3364) terminated with status 127

Any thoughts on what might be causing this? I haven't been able to find any information on upstart status codes. Thanks again!

#17 puithove

puithove

    Dedicated Member

  • Members
  • PipPipPip
  • 407 posts

Posted 13 July 2011 - 12:06 PM

Hey puithove, awesome upstart script. I'm having a little trouble getting plex to start up. I have no problems running the start.sh script, but when I try to run


I'm definitely no expert here. Let's start with the basics and get those out of the way:
  • You say you can run it manually by launching the start.sh script - what user are you logged in with when you do that? Is it the same "plex" user you're specifying in the service config file?
  • Are you able to launch the start.sh script as user "plex" - if not, what error do you get?
  • You say you then changed the config to start as your normal login - but did you leave the "cd <path>" statement pointing to the actual plexmediaserver directory?
Since it appears that you setup PMS under your normal login and then created a new "plex" user I'm thinking you've probably got a permissions issue. You need to setup PMS under the user you want to run it as and make sure it's working there before it'll be able to start as that user as a service.

#18 nhix

nhix

    Member

  • Members
  • PipPip
  • 11 posts

Posted 14 July 2011 - 03:50 AM

I think you may be correct, I am using the plex user in the script, however I'm unable to su to the plex user (because it is a system user with no shell). The upstart script probably has the same issue... it can't su to plex. I'll try a non-system user and see if that works. I'd like to avoid creating a new potential login (I thought thats how system users worked) but it may not be possible in this case??

Thanks!!

#19 puithove

puithove

    Dedicated Member

  • Members
  • PipPipPip
  • 407 posts

Posted 14 July 2011 - 03:53 PM

I think you may be correct, I am using the plex user in the script, however I'm unable to su to the plex user (because it is a system user with no shell). The upstart script probably has the same issue... it can't su to plex. I'll try a non-system user and see if that works. I'd like to avoid creating a new potential login (I thought thats how system users worked) but it may not be possible in this case??

Thanks!!


Ah, well I think that because of the way the PMS is running, it needs a real user. Get it set up and running as the user you want to run it under, and then I expect the Upstart piece will work fine for you. You won't have to be "logged in" as that user all the time, Upstart will start it as that user running as a service so it'll start when the system boots without having to log in.

#20 nhix

nhix

    Member

  • Members
  • PipPip
  • 11 posts

Posted 24 July 2011 - 09:54 PM

That did the trick, thanks puithove. I'm not a fan of these types of users being able to login to the box, so for those wondering, you can still disable login for the pms user via --disable-login or --disable-password when adding the user.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users