You are not logged in.

#1 2012-05-05 19:34:41

farnoy
Member
From: Poland
Registered: 2011-07-15
Posts: 11

[SOLVED] Running a script at startup

Hi,

I have a script that I've developed and I want it to run when the machine boots up. I would use gnome-session-properties, but I want it to run even if I don't log in to the machine. An additional condition is, that it should run as user, not root. It's optional but there's no reason for it to run as root.

I've tried putting it up in /etc/rc.local like this:

kuba:~$ cat /etc/rc.local
#!/bin/bash
#
# /etc/rc.local: Local multi-user startup script.
#

su -c "/home/kuba/devel/sabcommander/backend/backend.rb" - kuba &

And it actually spawns the processes:

kuba:~$ ps aux | grep sabcommander
root       648  0.0  0.0  27588  1096 ?        S    21:21   0:00 su -c /home/kuba/devel/sabcommander/backend/backend.rb - kuba
kuba      1020  0.1  0.6 106452 26280 ?        Sl   21:21   0:00 ruby /home/kuba/devel/sabcommander/backend/backend.rb

But they don't seem to work. This script connects via WebSockets to a remote server and keeps the connection, when it receives commands it executes few HTTP requests at localhost.

When I run a separate instance from the terminal, I then see that this script works, so I'm sure the one started from rc.local is not working.

Thanks

Last edited by farnoy (2012-05-08 06:26:13)

Offline

#2 2012-05-05 20:21:20

stealthy
Member
Registered: 2011-05-02
Posts: 67

Re: [SOLVED] Running a script at startup

Everything that I put into /etc/rc.local works fine, so double check the script. Looks like your running ruby, so I can't help much with the script itself.

Also check to make sure that its not missing something like #!/bin/ruby

Last edited by stealthy (2012-05-05 20:22:19)


clipodder-git A small simple cron-friendly podcast downloader, with support for arbitrary user defined media types (pdf, html, etc...)

Offline

#3 2012-05-05 23:28:05

frette
Member
Registered: 2012-05-04
Posts: 35

Re: [SOLVED] Running a script at startup

Judging by the ps aux output, the script should be executed.
Try letting the script do something simple you can check (something in the lines of touch on a file). If that works, something in your ruby script acts funky when called this way.
Maybe it needs something that isn't ready at the time it's started.

Just some vague ideas, because 1. there's very little information and 2. I have no clue concerning ruby

Offline

#4 2012-05-05 23:56:36

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

Re: [SOLVED] Running a script at startup

How are you starting your network? If the script runs before the network is fully up, it might not be able to properly bind to an interface.

Offline

#5 2012-05-06 03:40:23

funkypotatoe
Member
Registered: 2012-03-23
Posts: 47

Re: [SOLVED] Running a script at startup

Offline

#6 2012-05-06 19:50:18

farnoy
Member
From: Poland
Registered: 2011-07-15
Posts: 11

Re: [SOLVED] Running a script at startup

Thanks for replies,

I'm starting network like this:

DAEMONS=(syslog-ng dbus @net-profiles crond ...)

I'll rewrite my script to sleep for a few seconds at the beginning and then I'll post here.

Offline

#7 2012-05-06 21:36:55

funkypotatoe
Member
Registered: 2012-03-23
Posts: 47

Re: [SOLVED] Running a script at startup

farnoy wrote:

Thanks for replies,

I'm starting network like this:

DAEMONS=(syslog-ng dbus @net-profiles crond ...)

I'll rewrite my script to sleep for a few seconds at the beginning and then I'll post here.

I think to start net-profiles in the background is not the best idea.

Offline

#8 2012-05-06 22:22:45

frette
Member
Registered: 2012-05-04
Posts: 35

Re: [SOLVED] Running a script at startup

funkypotatoe wrote:
farnoy wrote:

Thanks for replies,

I'm starting network like this:

DAEMONS=(syslog-ng dbus @net-profiles crond ...)

I'll rewrite my script to sleep for a few seconds at the beginning and then I'll post here.

I think to start net-profiles in the background is not the best idea.

It most definitely isn't, if a script depending on it is to be started during the boot process  wink
I think that's the problem right there, remove the @ sign in front of network-profiles and try again.

Offline

#9 2012-05-07 19:50:05

farnoy
Member
From: Poland
Registered: 2011-07-15
Posts: 11

Re: [SOLVED] Running a script at startup

Yup, it fixed the problem, so the network was unavailable at the time and the init script was fine.

I guess i ordered it to start in the background for faster boot times, but I don't think it gave me much anyway.

Thanks everyone.

Should i put [SOLVED] in the topic name? Is that how it's done here?

Offline

#10 2012-05-07 19:52:22

Pres
Member
Registered: 2011-09-12
Posts: 423

Re: [SOLVED] Running a script at startup

Just edit your first post and add it to the title.

Offline

Board footer

Powered by FluxBB