/etc/rc.local

General programming chat and advice for beginners

19 posts
by Alex111 » Sun Oct 07, 2012 7:05 am
Hello,

I was trying to setup my raspberry to start a programm on system startup automatically for the last days without success.

I want to start my own program before a user logs in, i.e. this program does some network communication that should run on every boot.
I'm using the ArchLinux image and was trying to put my custom program into the rc.local file. But it seems that the rc.local is never executed.

Even a simple command like "echo "abc" > /root/abc.log" does not work -> no file was created. I already checked the execute bit on rc.local, which is fine. I have no idea who is executing the rc.local in the AchLinux environment...

Any ideas how to start a script (etc) before a user logs in???

Regards,
Alex
Posts: 29
Joined: Sun Oct 07, 2012 6:56 am
by mbramwel » Tue Oct 09, 2012 12:43 am
I also use /etc/rc.local to run some scripts as soon as the machine boots.

Some comments:
Do not assume that the script is running with a fully implemented shell. What I mean is the path statement and any other environment variables might not be available because the machine is still booting.

I suggest fully specifying the path of all commands.

examples:
Code: Select all
/bin/echo "hi" > /tmp/mytest
/usr/bin/touch /tmp/touch.me


If you do not know where something is stored, try this: which xxxxx
Where xxxxx is the command to find.

Example: which echo

Hope this helps!
Posts: 7
Joined: Mon Oct 08, 2012 2:30 pm
by bredman » Tue Oct 09, 2012 2:51 am
I agree with the previous poster, this is a very common problem.

When executing a command without logging is as a user (for example in /etc/rc.local or a cron job) you must not depend on any path or environment variables.
Posts: 1413
Joined: Tue Jan 17, 2012 2:38 pm
by Alex111 » Tue Oct 09, 2012 6:19 am
I already tried all those things without success... Even a simple echo does not work...

I'm using the latest Archlinux and it seems that it is using systemd instead of init scripts, e.g.
https://wiki.archlinux.org/index.php/Systemd

Maybe somebody can confirm this is the case? I'm really new to Linux and would like to know how to start my own executables during System Startup. My Goal is to design a dedicated device, which runs without user interaction.

Regards,

Alex
Posts: 29
Joined: Sun Oct 07, 2012 6:56 am
by Dweeber » Tue Oct 09, 2012 6:48 am
Curious... if you are new to Linux, what made you start with Archlinux instead of the better supported Raspbian (Debian) Wheezy distro?
Dweeber A.K.A. Kevin...
My RPI Info Pages including Current Setup - http://rpi.tnet.com
User avatar
Posts: 606
Joined: Fri Aug 17, 2012 3:35 am
Location: Mesa, AZ
by Alex111 » Tue Oct 09, 2012 7:08 am
I thought this distribution is low footprint and therefore ideal for a dedicated device....
Posts: 29
Joined: Sun Oct 07, 2012 6:56 am
by RaTTuS » Tue Oct 09, 2012 7:38 am
swap to latest debian - it's much more user friendly [on us also ]
http://www.catb.org/esr/faqs/smart-questions.html <- ask smart Questions
"That's not right, the badgers have moved the goalposts."
1QC43qbL5FySu2Pi51vGqKqxy3UiJgukSX - Prosliver FTW
User avatar
Posts: 5376
Joined: Tue Nov 29, 2011 11:12 am
Location: North West UK
by volender » Fri Nov 30, 2012 1:39 pm
migrating to raspbian is not a solution, because somebody may want to use ArchLinux ;).

I am forced to move to ArchLinux, because on Raspbian, Mono machine (.NET) freezes sometimes, while on ArchLinux people say doesn't.

I had a rc.local working on Raspbian,
but on ArchLinux it doesn't work, even calling from rc.local such script:
Code: Select all
#!/bin/bash

echo $RANDOM > o.txt

doesn't have any effect.


I've found that there is package "initscripts-systemd" for Arch,
but I installed it, rc.local , rc.local.shutdown etc appeared,
but I still can't call my script in rc.local.
Posts: 2
Joined: Mon Nov 19, 2012 12:34 pm
by Dweeber » Fri Nov 30, 2012 2:17 pm
Might get more attention if you post this in the Arch OS forum topic then... since this is more OS than programming related.

http://www.raspberrypi.org/phpBB3/viewforum.php?f=53
Dweeber A.K.A. Kevin...
My RPI Info Pages including Current Setup - http://rpi.tnet.com
User avatar
Posts: 606
Joined: Fri Aug 17, 2012 3:35 am
Location: Mesa, AZ
by ehrenbrav » Mon Dec 17, 2012 1:41 am
Have you tried `/bin/echo` instead of echo as the above poster suggested? And I'd suggest using just "sometext" instead of $RANDOM just to verify whether the script is even being executed...and specify the precise path of the output file you want to write to...
Posts: 1
Joined: Mon Dec 17, 2012 1:36 am
by akey » Tue Dec 25, 2012 6:34 pm
archlinux had deprecated rc.local, rc.conf, ... etc.
replace them with systemd. To use the old stuff you need to install initscripts
Posts: 2
Joined: Tue Dec 25, 2012 6:32 pm
by akey » Wed Dec 26, 2012 10:32 am
Here is what you need to get rc.local back on arch linux
0. backup your current rc.* scripts
1. install initscripts
2. install sysvinit, it will prompt you to remove systemd-sysvcompat, proceed
3. if you already have rc.local, it will be overwritten by a blank one. Pacman automatically backup the old one, but since you already have a backup, just restore the one you need.
Posts: 2
Joined: Tue Dec 25, 2012 6:32 pm
by trevstanhope » Mon Jul 15, 2013 2:25 am
Have you tried making /etc/rc.local executable?

Code: Select all
sudo chmod +x /etc/rc.local
Posts: 1
Joined: Mon Jul 15, 2013 2:24 am
by elmsley » Sat Jul 27, 2013 2:32 pm
I have the same issue, not sure what's going on. I don't see either the /etc/rc.local or /etc/init.d/rc.local running.
I feel that this is important as most hackers would like to get a module running without a keyboard/monitory.
Posts: 17
Joined: Tue Feb 05, 2013 3:23 pm
by elmsley » Sat Jul 27, 2013 3:07 pm
Actually what I'm seeing is it running for a short time but it dies.
I tried to use this in /etc/rc.local, but it still dies:
nohup myScript.pl &
Posts: 17
Joined: Tue Feb 05, 2013 3:23 pm
by elmsley » Sat Jul 27, 2013 3:33 pm
Hmm, never mind. it really was a path problem. So I guess lesson learned, make sure you fully qualify everything!
But cool, now I have my contraption working!
Posts: 17
Joined: Tue Feb 05, 2013 3:23 pm
by nigelh » Sat Oct 05, 2013 2:20 pm
Hi elmsley,
could you expand on what you found to be the problem, please - what exactly did you have to fully qualify, pathwise ??
Would be interested to hear as I'm also trying to get /etc/rc.local working on my archlinux raspberry pi !
Thanks for help
Nigel
Posts: 1
Joined: Tue Jul 23, 2013 10:49 am
by ktorn » Wed Nov 06, 2013 2:45 am
I just ran into this issue where my scripts in /etc/rc.local were not running, but works out it was a silly mistake of mine.

I added my scripts at the bottom of the file after the exit 0 line, so of course the /etc/rc.local was running but exiting before calling my scripts. :oops:

Hope this helps someone else out there.
User avatar
Posts: 14
Joined: Fri Mar 29, 2013 8:49 am
by ktorn » Wed Nov 06, 2013 2:51 am
elmsley wrote:Actually what I'm seeing is it running for a short time but it dies.
I tried to use this in /etc/rc.local, but it still dies:
nohup myScript.pl &


I use screen in most of my startup scripts. Not only it keeps the process alive, but I can resume the screen at a later time and interact with the script (if applicable).

I normally do:
Code: Select all
screen -A -m -d -S <some_screen_name> <my_script_command>

This will run <my_script_command> in a screen session.
I can log in at any time and type screen -r <some_screen_name> to pull up that screen, and afterwards Ctrl-A D to dettach the screen and leave it running in the background again.

Very useful.
User avatar
Posts: 14
Joined: Fri Mar 29, 2013 8:49 am