You are not logged in.

#1 2013-03-07 01:19:26

gdugan
Member
Registered: 2013-03-06
Posts: 4

Start a program at boot

I installed plex media server and got it to work . How can I get it to start while booting up? To start the program I go to /usr/lib/plexmediaserver/start.sh and click on start.sh.

Offline

#2 2013-03-07 02:15:56

Trilby
Forum Moderator
From: Massachusetts, USA
Registered: 2011-11-29
Posts: 14,217
Website

Re: Start a program at boot

There are many ways to do this, and even more wiki pages and forum discussions addressing this type of question.

Have you searched for them?  Have you read them?  Have you tried them?

You should.


InterrobangSlider
• How's my coding? See this page.
• How's my moderating? Feel free to email any concerns, complaints, or objections.

Offline

#3 2013-03-07 02:47:32

frank604
Member
From: BC, Canada
Registered: 2011-04-20
Posts: 1,070
Website

Re: Start a program at boot


github       bible       blog       screenshot

Offline

#4 2013-03-07 12:24:57

gdugan
Member
Registered: 2013-03-06
Posts: 4

Re: Start a program at boot

Yes i searched and nothing works. The only way I can get it to start is to click on start.sh in a file manager. I even tried a short cut on the desktop and that does not work either. I also tried systemctl (https://bbs.archlinux.org/viewtopic.php?id=154251) did not work.

Offline

#5 2013-03-07 12:38:39

Trilby
Forum Moderator
From: Massachusetts, USA
Registered: 2011-11-29
Posts: 14,217
Website

Re: Start a program at boot

"did not work" is not useful information.

*What* exactly did you try, and what was the outcome/error messages.

What file manager are you using, and what does your file manager do when you click on that start.sh?

What is in start.sh?

What happens when you run start.sh from a terminal?

Help us help you.


InterrobangSlider
• How's my coding? See this page.
• How's my moderating? Feel free to email any concerns, complaints, or objections.

Offline

#6 2013-03-07 13:33:20

tomk
Forum Fellow
From: Ireland
Registered: 2004-07-21
Posts: 9,839

Re: Start a program at boot

Assuming you installed it using the AUR package, it comes with a systemd service file. If that is not working, check your journal for clues, and if necessary report it to the maintainer.

<edit>I've just built and installed this myself, and it works fine here - run

systemctl start plexmediaserver

to start it, then

systemctl status plexmediaserver

for details.

Last edited by tomk (2013-03-07 15:16:42)

Offline

#7 2013-03-07 21:22:34

gdugan
Member
Registered: 2013-03-06
Posts: 4

Re: Start a program at boot

Here is the output systemctl start and status

[root@greg greg]# systemctl start plexmediaserver
Job for plexmediaserver.service failed. See 'systemctl status plexmediaserver.service' and 'journalctl -xn' for details.
[root@greg greg]# systemctl status plexmediaserver
plexmediaserver.service - Plex Media Server for Linux
          Loaded: loaded (/usr/lib/systemd/system/plexmediaserver.service; enabled)
          Active: failed (Result: exit-code) since Thu 2013-03-07 16:11:45 EST; 30s ago
         Process: 10101 ExecStartPre=/bin/sh -c /usr/bin/test -d "${PLEX_MEDIA_SERVER_APPLICATION_SUPPORT_DIR}" || /bin/mkdir -p "${PLEX_MEDIA_SERVER_APPLICATION_SUPPORT_DIR}" (code=exited, status=217/USER)

Mar 07 16:11:45 greg systemd[1]: Starting Plex Media Server for Linux...
Mar 07 16:11:45 greg systemd[1]: plexmediaserver.service: control process e...17
Mar 07 16:11:45 greg systemd[1]: Failed to start Plex Media Server for Linux.
Mar 07 16:11:45 greg systemd[1]: Unit plexmediaserver.service entered faile...te
[root@greg greg]# journalctl -xn
-- Logs begin at Tue 2013-03-05 13:05:35 EST, end at Thu 2013-03-07 16:11:45 EST. --
Mar 07 15:59:30 greg dbus[277]: [system] Activating via systemd: service name='org.freedesktop
Mar 07 15:59:30 greg dbus-daemon[277]: dbus[277]: [system] Activation via systemd failed for u
Mar 07 15:59:30 greg dbus[277]: [system] Activation via systemd failed for unit 'dbus-org.free
Mar 07 16:11:39 greg su[10097]: (to root) greg on /dev/pts/2
Mar 07 16:11:39 greg su[10097]: pam_unix(su:session): session opened for user root by greg(uid
Mar 07 16:11:45 greg systemd[1]: Starting Plex Media Server for Linux...
-- Subject: Unit plexmediaserver.service has begun with start-up
-- Defined-By: systemd
-- Support: http://lists.freedesktop.org/mailman/li … temd-devel
-- Documentation: http://www.freedesktop.org/wiki/Softwar … 2da4a758f6
--
-- Unit plexmediaserver.service has begun starting up.
Mar 07 16:11:45 greg systemd[10101]: Failed at step USER spawning /bin/sh: No such process
-- Subject: Process /bin/sh could not be executed
-- Defined-By: systemd
-- Support: http://lists.freedesktop.org/mailman/li … temd-devel
-- Documentation: http://www.freedesktop.org/wiki/Softwar … c1b4ec9a86
--
-- The process /bin/sh could not be executed and failed.
--
-- The error number returned while executing this process is 3.
Mar 07 16:11:45 greg systemd[1]: plexmediaserver.service: control process exited, code=exited
Mar 07 16:11:45 greg systemd[1]: Failed to start Plex Media Server for Linux.
-- Subject: Unit plexmediaserver.service has failed
-- Defined-By: systemd
-- Support: http://lists.freedesktop.org/mailman/li … temd-devel
-- Documentation: http://www.freedesktop.org/wiki/Softwar … 5d2428ba40
--
-- Unit plexmediaserver.service has failed.
--
-- The result is failed.
Mar 07 16:11:45 greg systemd[1]: Unit plexmediaserver.service entered failed state
(END)


Here is the status of journalctl

-- Logs begin at Tue 2013-03-05 13:05:35 EST, end at Thu 2013-03-07 16:11:45 EST. --
Mar 07 15:59:30 greg dbus[277]: [system] Activating via systemd: service name='org.freedesktop.NetworkManager' unit='dbus-org.freedesktop.NetworkManager.service'
Mar 07 15:59:30 greg dbus-daemon[277]: dbus[277]: [system] Activation via systemd failed for unit 'dbus-org.freedesktop.NetworkManager.service': Unit dbus-org.freedesktop.NetworkManager.service failed to load: No such file or directory.
Mar 07 15:59:30 greg dbus[277]: [system] Activation via systemd failed for unit 'dbus-org.freedesktop.NetworkManager.service': Unit dbus-org.freedesktop.NetworkManager.service failed to load: No such file or directory. See system logs an
Mar 07 16:11:39 greg su[10097]: (to root) greg on /dev/pts/2
Mar 07 16:11:39 greg su[10097]: pam_unix(su:session): session opened for user root by greg(uid=1000)
Mar 07 16:11:45 greg systemd[1]: Starting Plex Media Server for Linux...
-- Subject: Unit plexmediaserver.service has begun with start-up
-- Defined-By: systemd
-- Support: http://lists.freedesktop.org/mailman/li … temd-devel
-- Documentation: http://www.freedesktop.org/wiki/Softwar … dc7b36dcc5
--
-- Unit plexmediaserver.service has begun starting up.
Mar 07 16:11:45 greg systemd[10101]: Failed at step USER spawning /bin/sh: No such process
-- Subject: Process /bin/sh could not be executed
-- Defined-By: systemd
-- Support: http://lists.freedesktop.org/mailman/li … temd-devel
-- Documentation: http://www.freedesktop.org/wiki/Softwar … 7a40a9e1e7
--
-- The process /bin/sh could not be executed and failed.
--
-- The error number returned while executing this process is 3.
Mar 07 16:11:45 greg systemd[1]: plexmediaserver.service: control process exited, code=exited status=217
Mar 07 16:11:45 greg systemd[1]: Failed to start Plex Media Server for Linux.
-- Subject: Unit plexmediaserver.service has failed
-- Defined-By: systemd
-- Support: http://lists.freedesktop.org/mailman/li … temd-devel
-- Documentation: http://www.freedesktop.org/wiki/Softwar … e9d022f03d
--
-- Unit plexmediaserver.service has failed.
--
-- The result is failed.
Mar 07 16:11:45 greg systemd[1]: Unit plexmediaserver.service entered failed state

Offline

#8 2013-03-07 22:39:49

tomk
Forum Fellow
From: Ireland
Registered: 2004-07-21
Posts: 9,839

Re: Start a program at boot

Your plexmediaserver.service file is not the one provided by the AUR package. I recommend you remove everything, including any related files that you may have installed manually outside of pacman, and then build and install the AUR package.

Offline

#9 2013-03-08 01:02:26

gdugan
Member
Registered: 2013-03-06
Posts: 4

Re: Start a program at boot

I removed plexmediaserver and reinstalled. Everything works Thanks

Offline

#10 2013-03-08 01:06:46

Inxsible
Forum Fellow
From: Chicago
Registered: 2008-06-09
Posts: 9,079

Re: Start a program at boot

as an aside, please use [code ] tags when posting snippets


Forum Rules

There's no such thing as a stupid question, but there sure are a lot of inquisitive idiots !

Offline

#11 2013-03-09 22:27:36

homemadev
Member
Registered: 2013-01-27
Posts: 7

Re: Start a program at boot

I'm looking for the best way to run a bash script at system start.

So far, it looks like I need to hook into systemd by writing a bastardized service file... does that sound right? Or should I use the legacy compatibility of systemd somehow?

So far this is the best I've found --

http://patrakov.blogspot.com/2011/01/wr … files.html

-- so I created testboot.service (below) into /etc/systemd/system/multi-user.target.wants/

[Unit]
Description=Random Boot Scripts
After=network.target

[Service]
ExecStart=echo "Test" > /home/user1/bash-boot-test.txt

[Install]
WantedBy=multi-user.target

With the following results:

 # systemctl start testboot
Failed to issue method call: Unit testboot.service failed to load: Invalid argum
ent. See system logs and 'systemctl status testboot.service' for details.
# systemctl status testboot.service
testboot.service - Random Boot Scripts
          Loaded: error (Reason: Invalid argument)
          Active: inactive (dead)

Help?

Offline

#12 2013-03-09 22:52:59

Wittfella
Member
From: Australia
Registered: 2008-05-27
Posts: 462

Re: Start a program at boot

I think you need to specify the path for 'echo', eg. /bin/echo "blah blah"

Offline

#13 2013-03-09 23:04:12

falconindy
Developer
From: New York, USA
Registered: 2009-10-22
Posts: 4,097
Website

Re: Start a program at boot

And the '>' is meaningless. ExecStart is not a shell.

Offline

#14 2013-03-09 23:17:01

homemadev
Member
Registered: 2013-01-27
Posts: 7

Re: Start a program at boot

I take it that you agree that I'm taking a reasonable approach?

Offline

#15 2013-03-09 23:19:14

homemadev
Member
Registered: 2013-01-27
Posts: 7

Re: Start a program at boot

I tried the full path to echo --> same result. I'm a newb here-- my question is "How do you run your startup bash scripts?"

Offline

#16 2013-03-09 23:20:44

homemadev
Member
Registered: 2013-01-27
Posts: 7

Re: Start a program at boot

I had some trouble finding the relevant documentation for ExecStart.. can you point me to it?

I was looking through this:

http://0pointer.de/public/systemd-man/index.html

Offline

#17 2013-03-09 23:48:14

Raynman
Member
Registered: 2011-10-22
Posts: 1,116

Re: Start a program at boot

`man systemd.directives` will help you find the man page that describes ExecStart.

Offline

#18 2013-03-10 00:38:39

homemadev
Member
Registered: 2013-01-27
Posts: 7

Re: Start a program at boot

Ok.. from

http://0pointer.de/public/systemd-man/s … rvice.html

ExecStart=

    Commands with their arguments that are executed when this service is started. The first argument must be an absolute path name.

Which shell does ExecStart use to execute the command?

Offline

#19 2013-03-10 00:41:46

Trilby
Forum Moderator
From: Massachusetts, USA
Registered: 2011-11-29
Posts: 14,217
Website

Re: Start a program at boot

falconindy wrote:

ExecStart is not a shell.

I suspect it uses exec family function (execv is likely).  There is no shell.

Last edited by Trilby (2013-03-10 00:42:02)


InterrobangSlider
• How's my coding? See this page.
• How's my moderating? Feel free to email any concerns, complaints, or objections.

Offline

#20 2013-03-10 00:51:02

homemadev
Member
Registered: 2013-01-27
Posts: 7

Re: Start a program at boot

Reading to the bottom of ExecStart:

Note that this setting does not directly support shell command lines. If shell command lines are to be used they need to be passed explicitly to a shell implementation of some kind. Example: ExecStart=/bin/sh -c 'dmesg | tac'

So I wrote:

[Unit]
Description=Random Boot Scripts

[Service]
ExecStart=/bin/bash -c "/home/user1/testboot.sh"

[Install]
WantedBy=multi-user.target

Where testboot.sh is

echo Test on `date` > /home/user1/testboot.txt

And a get a new error:

# systemctl start testboot
Failed to issue method call: Unit testboot.service failed to load: No such file
or directory. See system logs and 'systemctl status testboot.service' for detail
s.
# systemctl status testboot
testboot.service
          Loaded: error (Reason: No such file or directory)
          Active: inactive (dead)

I wonder if there is something I'm doing wrong in the [Unit] on [Install] sections?

Offline

#21 2013-03-10 00:55:50

Trilby
Forum Moderator
From: Massachusetts, USA
Registered: 2011-11-29
Posts: 14,217
Website

Re: Start a program at boot

You're trying to access a script (and a text file) in a users home directory.  This is a bad idea, unless it is run by that user, and it is not possible if this runs before the home partition is mounted.

If this is what you actually want to do, look at systemd user sessions, otherwise, put the script somewhere else.

Also /bin/bash -c  "/path/to/script" is redundant and creates two nested shells.  Just use /path/to/testboot.sh


InterrobangSlider
• How's my coding? See this page.
• How's my moderating? Feel free to email any concerns, complaints, or objections.

Offline

#22 2013-03-10 09:51:12

Raynman
Member
Registered: 2011-10-22
Posts: 1,116

Re: Start a program at boot

Trilby wrote:

Also /bin/bash -c  "/path/to/script" is redundant and creates two nested shells.  Just use /path/to/testboot.sh

... and make sure the script is executable. Alternatively, remove the -c switch.

But I'm pretty sure the error says that systemd can't find your .service file. Where did you put it and did you double-check for typos?

Offline

#23 2013-03-10 11:40:19

Trilby
Forum Moderator
From: Massachusetts, USA
Registered: 2011-11-29
Posts: 14,217
Website

Re: Start a program at boot

Raynman wrote:

I'm pretty sure the error says that systemd can't find your .service file.

Ah, yes.  On second look I agree.  Though running something in a users home directory could still lead to antoher problem once the current one is fixed.


InterrobangSlider
• How's my coding? See this page.
• How's my moderating? Feel free to email any concerns, complaints, or objections.

Offline

#24 2013-03-10 20:00:39

homemadev
Member
Registered: 2013-01-27
Posts: 7

Re: Start a program at boot

Solved..

I moved the script to /etc/systemd/system (rather than /etc/systemd/system/multi-user.target.wants/).. I ran

# systemctl enable testboot

and it runs at startup. Thanks!

I'm still not sure this is an advisable way to do this.. And there still may be some extra chuff in the unit file.. like After and WantedBy, but anyhow, it works smile

# ls /etc/systemd/system/testboot.service
/etc/systemd/system/testboot.service
# systemctl restart testboot
# systemctl status testboot.service
testboot.service - Random Boot Scripts
          Loaded: loaded (/etc/systemd/system/testboot.service; disabled)
          Active: inactive (dead) since Sun 2013-03-10 13:51:32 MDT; 6s ago
         Process: 616 ExecStart=/usr/src/testboot.sh (code=exited, status=0/SUCC
ESS)

Mar 10 13:51:32 plugbox systemd[1]: Started Random Boot Scripts.

Which calls:

# cat /etc/systemd/system/testboot.service
[Unit]
Description=Random Boot Scripts
After=smbd.service

[Service]
Type=oneshot
ExecStart=/usr/src/testboot.sh

[Install]
WantedBy=multi-user.target

And it runs my script:

# cat /usr/src/testboot.sh
#!/bin/bash
echo `date` > /tmp/testboot.txt

Offline

Board footer

Powered by FluxBB