Is /etc/rc.local obsolete? [Solved]

Kernels & Hardware, configuring network, installing services

Is /etc/rc.local obsolete? [Solved]

Postby G-Known » 2015-09-17 04:00

I"ve tried running scripts inside that file but it doesn't work, so then I moved my script file to /etc/init.d and after a restart, the script worked. Does that mean rc.local is obsolete?
Last edited by G-Known on 2015-10-04 02:21, edited 1 time in total.
Debian Jessie
Asus Zenbook UX305FA-ASM1
Intel Core M 5Y10; Intel HD Graphics 5300
User avatar
G-Known
 
Posts: 178
Joined: 2012-10-26 04:59
Location: Brooklyn, New York

Re: Is /etc/rc.local obsolete?

Postby GarryRicketson » 2015-09-17 05:05

No it is not "obsolete" , it has it's place, and it'uses ,..
Does that mean rc.local is obsolete?

http://unix.stackexchange.com/questions/49626/purpose-and-typical-usage-of-etc-rc-local
Some people, seem to feel it is obsolete. But that would depend on what version of Debian you are using, what kind of script it is, and if the script is "called" correctly.
so many other details, none of which you have given.
Why didn't you just copy and paste the question into a search engine, Like "startpage.com" ?
Copy and paste , :
Is /etc/rc.local obsolete?
into https://startpage.com/do/metasearch.pl
-----------------------
I guess the script you wrote, is the kind of script that needs to be run from init.d
Try
Code: Select all
 man bash

Is DOS obsolete ? many people would say yes, I would say no, cause I still use it,
Same applies to /etc/rc.local , it has it's uses, but if the person does not know how to use it, then it is "obsolete".
"What we expect you have already Done"

Before doing anything, read the Debian documentation:
Debian Documentation
How to ask the smart way
Debian Foro Español
======================
For the Birds
User avatar
GarryRicketson
 
Posts: 4366
Joined: 2015-01-20 22:16
Location: Durango, Mexico

Re: Is /etc/rc.local obsolete?

Postby WingedFrog » 2015-09-17 11:00

G-Known wrote:I"ve tried running scripts inside that file but it doesn't work, so then I moved my script file to /etc/init.d and after a restart, the script worked. Does that mean rc.local is obsolete?


No, not obsolete. It is provided for the use of the system administrator and compatibility reasons. Posts that insist it should never be used are just plain wrong.

I run hdparm -B 254 /dev/sdX from /etc/rc.local to kill head parking on my HGST drives at startup. I also kill display power management and launch the fancontrol script from /etc/rc.local.

As would be expected, rc.local has to be enabled in systemd. I am on Stretch which I installed with the testing network installer. As far as I can recall, enabled was the default. The Stretch systemd rc.local settings are a little different than those in Arch, (as referenced by those earlier links), so it may not be wise to rely on directly copying Arch stuff in this case.

Code: Select all
#  This file is part of systemd.
#
#  systemd is free software; you can redistribute it and/or modify it
#  under the terms of the GNU Lesser General Public License as published by
#  the Free Software Foundation; either version 2.1 of the License, or
#  (at your option) any later version.

# This unit gets pulled automatically into multi-user.target by
# systemd-rc-local-generator if /etc/rc.local is executable.
[Unit]
Description=/etc/rc.local Compatibility
ConditionFileIsExecutable=/etc/rc.local
After=network.target

[Service]
Type=forking
ExecStart=/etc/rc.local start
TimeoutSec=0
RemainAfterExit=yes


Lastly, anything that isn't a simple, quick command has to be forked in rc.local. Anything that returns an error will immediately terminate rc.local and subsequent entries will not be executed.
WingedFrog
 
Posts: 34
Joined: 2015-08-26 11:31

Re: Is /etc/rc.local obsolete?

Postby G-Known » 2015-09-18 00:25

I'm trying to run this script:

Code: Select all
#!/bin/bash
 while true
    do
        export DISPLAY=:0.0
        battery_level=`acpi -b | grep -P -o '[0-9]+(?=%)'`
        if on_ac_power; then
            if [ $battery_level -ge 80 ]; then
                notify-send "Battery charging above 80%. Please unplug your AC adapter!" "Charging: ${battery_level}% "
                sleep 20
                if on_ac_power; then
                    gnome-screensaver-command -l   ## lock the screen if you don't unplug AC adapter after 20 seconds
                fi
             fi
        else
             if [ $battery_level -le 35 ]; then
                notify-send "Battery is lower 35%. Need to charging! Please plug your AC adapter." "Charging: ${battery_level}%"
                sleep 20
                if ! on_ac_power; then
                    gnome-screensaver-command -l   ## lock the screen if you don't plug AC adapter after 20 seconds
                fi
             fi
        fi

        sleep 300 # 300 seconds or 5 minutes
done


I've inputted it into init.d directory but it doesn't seem to run. I've made it executable and used the update-rc.d 'script.sh' default command.

I've used the rc.local file before and I know its basic functions. But lately, even if I put an input command like: nmcli radio wifi off, the command won't get executed. I don't know how to diagnose this error but generally the command is prior 'exit 0'. My current file reads:

Code: Select all
#!/bin/sh -e
#
# rc.local
#
# This script is executed at the end of each multiuser runlevel.
# Make sure that the script will "exit 0" on success or any other
# value on error.
#
# In order to enable or disable this script just change the execution
# bits.
#
# By default this script does nothing.
nmcli radio wifi off
ethtool -s eth0 wol d
exit 0
Last edited by G-Known on 2015-09-19 12:35, edited 1 time in total.
Debian Jessie
Asus Zenbook UX305FA-ASM1
Intel Core M 5Y10; Intel HD Graphics 5300
User avatar
G-Known
 
Posts: 178
Joined: 2012-10-26 04:59
Location: Brooklyn, New York

Re: Is /etc/rc.local obsolete?

Postby WingedFrog » 2015-09-18 14:24

First, make sure rc.local is running.

Code: Select all
$ systemctl list-units | grep rc-local
rc-local.service                                              loaded active running   /etc/rc.local Compatibility


Then try this.

Code: Select all
# By default this script does nothing.
nmcli radio wifi off &
ethtool -s eth0 wol d &
exit 0


I did not look at the bash script you posted. I am far from a bash expert, and I don't have the time to try and dig through it. I also did not verify the correctness of your nmcli and ethtool usage.
WingedFrog
 
Posts: 34
Joined: 2015-08-26 11:31

Re: Is /etc/rc.local obsolete?

Postby kiyop » 2015-09-19 01:01

Are you sure that there is "done" after the last "fi" in the script? ;)
If there is not, the script has a BUG, and so it is not executed because of error. ;)
Refer, for example, http://tldp.org/LDP/Bash-Beginners-Guid ... 09_02.html
If there is, read below.

How do you confirm that the script is not executed?
Execute
Code: Select all
ps auwwx

and find the script or "sleep 300".

G-Known wrote:
Code: Select all
 while true
    do
(snip by kiyop)
        if on_ac_power; then
            if [ $battery_level -ge 80 ]; then
(snip by kiyop)
           fi
        fi

        sleep 300 # 300 seconds or 5 minutes

Are you sure that in your debian, command "on_ac_power" exist?
Code: Select all
on_ac_power

Are you sure that in your debian, the variable $battery_level has some value?
Code: Select all
echo $battery_level

Sometimes, the current (working) directory and the current $PATH variable and the current user (root or the ordinary user) cause problems.
Openbox, JWM: Jessie, Sid, Arch / Win XP (on VirtualBox), 10
http://kiyoandkei.bbs.fc2.com/
User avatar
kiyop
 
Posts: 3984
Joined: 2011-05-05 15:16
Location: Where persons without desire to improve themselves fear to tread, in Japan

Re: Is /etc/rc.local obsolete?

Postby G-Known » 2015-09-19 12:16

I know that the script works because if I run it manually, it'll work. I'll double check the script soundness.

pgrep -fl will return to me the script that it's running.

UPDATE: The done was placed at the end after the 'sleep' statement. I believed I didn't paste that part in.
Last edited by G-Known on 2015-09-19 12:36, edited 2 times in total.
Debian Jessie
Asus Zenbook UX305FA-ASM1
Intel Core M 5Y10; Intel HD Graphics 5300
User avatar
G-Known
 
Posts: 178
Joined: 2012-10-26 04:59
Location: Brooklyn, New York

Re: Is /etc/rc.local obsolete?

Postby G-Known » 2015-09-19 12:34

WingedFrog wrote:First, make sure rc.local is running.

Code: Select all
$ systemctl list-units | grep rc-local
rc-local.service                                              loaded active running   /etc/rc.local Compatibility


The command returns:

Code: Select all
rc-local.service                                                                         loaded active     exited          /etc/rc.local Compatibility


Which I assume that it's loaded and exits after it's done executing.
Debian Jessie
Asus Zenbook UX305FA-ASM1
Intel Core M 5Y10; Intel HD Graphics 5300
User avatar
G-Known
 
Posts: 178
Joined: 2012-10-26 04:59
Location: Brooklyn, New York

Re: Is /etc/rc.local obsolete?

Postby kiyop » 2015-09-19 13:28

G-Known wrote:UPDATE: The done was placed at the end after the 'sleep' statement. I believed I didn't paste that part in.

G-Known added
G-Known wrote:
Code: Select all
done

to the above post of him: viewtopic.php?f=5&t=124740&p=593321#p593167
after I posted the above.

To G-Known,

G-Known wrote:pgrep -fl will return to me the script that it's running.

:?:

G-Known wrote:I know that the script works because if I run it manually, it'll work. I'll double check the script soundness.

I see. I cannot help you. Good luck :) and good-bye.
Openbox, JWM: Jessie, Sid, Arch / Win XP (on VirtualBox), 10
http://kiyoandkei.bbs.fc2.com/
User avatar
kiyop
 
Posts: 3984
Joined: 2011-05-05 15:16
Location: Where persons without desire to improve themselves fear to tread, in Japan

Re: Is /etc/rc.local obsolete? [Solved]

Postby G-Known » 2015-10-04 02:22

I did it. Unfortunately I'll have to remove the script from init.d directory; it seems root is unable to execute whilst successfully in userspace.
Debian Jessie
Asus Zenbook UX305FA-ASM1
Intel Core M 5Y10; Intel HD Graphics 5300
User avatar
G-Known
 
Posts: 178
Joined: 2012-10-26 04:59
Location: Brooklyn, New York

Re: Is /etc/rc.local obsolete? [Solved]

Postby vinyanalista » 2017-06-07 12:41

As I googled "debian 9 /etc/rc.local" and it returned me this forum page, I would like to share information about /etc/rc.local on Debian 9.0 Stretch, just in case anyone needs. This is not official information, but what happened to me and how I solved it.

I needed to run a script at my server startup. I installed Debian 9.0 Stretch RC 4 yesterday using the netinst CD image available here: https://www.debian.org/devel/debian-installer/

When I issued:

Code: Select all
# nano /etc/rc.local


I noticed nano was creating a new file. In other words, /etc/rc.local is not created by default on Debian 9.0 Stretch.

I copied the template from another Debian server I have, running Debian 8.0 Jessie:

Code: Select all
#!/bin/sh -e
#
# rc.local
#
# This script is executed at the end of each multiuser runlevel.
# Make sure that the script will "exit 0" on success or any other
# value on error.
#
# In order to enable or disable this script just change the execution
# bits.
#
# By default this script does nothing.

exit 0


And I added a call to the script before exit 0. Then, I rebooted the server, the script was not executed. I thought /etc/rc.local was not used on Debian 9.0 anymore, so I googled and came to this page.

Then, reading the post and the replies, I followed their directions:

Code: Select all
# systemctl list-units | grep rc-local <-- (empty output)
# systemctl start rc-local
# systemctl status rc-local
● rc-local.service - /etc/rc.local Compatibility
   Loaded: loaded (/lib/systemd/system/rc-local.service; static; vendor preset: enabled)
  Drop-In: /lib/systemd/system/rc-local.service.d
           └─debian.conf
   Active: inactive (dead)
Condition: start condition failed at Wed 2017-06-07 09:54:07 -03; 3s ago
           └─ ConditionFileIsExecutable=/etc/rc.local was not met


Besides manually creating /etc/rc.local, I should have made it executable, so I did it and rebooted the server:

Code: Select all
# chmod +x /etc/rc.local
# reboot


That time, the script was called during startup.
vinyanalista
 
Posts: 5
Joined: 2016-06-30 22:07

Re: Is /etc/rc.local obsolete? [Solved]

Postby mfamatute » 2017-09-05 21:15

Exists but is inactive, here explain how to activate it
https://www.linuxbabe.com/linux-server/ ... th-systemd
mfamatute
 
Posts: 1
Joined: 2017-09-05 21:10


Return to System configuration

Who is online

Users browsing this forum: No registered users and 8 guests

fashionable