Score:1

cannot get rc.local to work with simple chown script on ubuntu 20.04

ee flag

I am a bit of a noob and I have been following this tutorial to setup rc.local on ubuntu 20.04 as I want to change ownership of folder on boot.

The script is saved in chownscript.sh and it is:

#!/bin/bash
chown -R 1001:1001 /opt/redis
exit 0

When I run it as sudo ./chownscript.sh it works fine.

My rc.local file is

#!/bin/sh -e
# rc.local
#
# This script is executed at the end of each multiuser runlevel.
# Ensure that the script will "exit 0" on success or any other
# value on error.
#
# To enable or disable this script, just change the execution
# bits.
#
# By default, this script does nothing.

sh /opt/chownscript.sh

exit 0

My /etc/systemd/system/rc-local.service file is

[Unit]
Description=/etc/rc.local Compatibility
ConditionPathExists=/etc/rc.local

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

[Install]
WantedBy=multi-user.targ[Unit]
Description=/etc/rc.local Compatibility
ConditionPathExists=/etc/rc.local

[Service]
Type=forking

when i run systemctl status rc-local.service i get

● rc-local.service - /etc/rc.local Compatibility
     Loaded: loaded (/etc/systemd/system/rc-local.service; enabled; vendor preset: enabled)
    Drop-In: /usr/lib/systemd/system/rc-local.service.d
             └─debian.conf
     Active: active (exited) since Wed 2023-03-29 19:55:53 UTC; 16min ago
    Process: 651 ExecStart=/etc/rc.local start (code=exited, status=0/SUCCESS)
        CPU: 24ms

Mar 29 19:55:53 ubuntu-server-2 systemd[1]: Starting /etc/rc.local Compatibility...
Mar 29 19:55:53 ubuntu-server-2 sudo[653]:     root : PWD=/ ; USER=root ; COMMAND=/usr/bin/chown -R 1001:1001 /opt/redis
Mar 29 19:55:53 ubuntu-server-2 sudo[653]: pam_unix(sudo:session): session opened for user root(uid=0) by (uid=0)
Mar 29 19:55:53 ubuntu-server-2 sudo[653]: pam_unix(sudo:session): session closed for user root
Mar 29 19:55:53 ubuntu-server-2 systemd[1]: Started /etc/rc.local Compatibility.

However when I check folder permisions nothing has changed. Any suggestions on what I am doing wrong?

petep avatar
in flag
I would try using /bin/bash instead of sh shell
ezzys avatar
ee flag
Updated script to bin/bash. It works if I run "bash -x /etc/rc.local", but does not appear to work on reboot.
petep avatar
in flag
Why do you have "sudo chown", when rc.local is run as root anyway? Try including full path to chown in script.
ezzys avatar
ee flag
I only used sudo when trying to run the script myself to check it worked. The rc.local file does not have sudo in it. The script does not have sudo in it either.
I sit in a Tesla and translated this thread with Ai:

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.