2

I have an issue with my rc.local, which isn't running automatically the command line contained inside, on server boot. However, running manually rc.local works fine and starts the script.

Operating System: Ubuntu 20.04.2 LTS

Here is my rc.local

#!/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.

sh '/home/[user]/azerothcore-wotlk/reboot.sh'

exit 0

And my reboot.sh

#!/bin/sh

/usr/bin/screen -AmdS world /home/[user]/azerothcore-wotlk/acore.sh run-worldserver
/usr/bin/screen -AmdS auth /home/[user]/azerothcore-wotlk/acore.sh run-authserver

Status of the rc.local service:

$ systemctl status rc-local.service
● rc-local.service - /etc/rc.local Compatibility
     Loaded: loaded (/lib/systemd/system/rc-local.service; enabled-runtime; vendor preset: enabled)
    Drop-In: /usr/lib/systemd/system/rc-local.service.d
             └─debian.conf
     Active: active (exited) since Wed 2021-05-19 22:01:41 IST; 2 days ago
       Docs: man:systemd-rc-local-generator(8)
    Process: 500 ExecStart=/etc/rc.local start (code=exited, status=0/SUCCESS)

Warning: some journal files were not opened due to insufficient permissions.

rc.local and reboot.sh both have permissions:

$ ls -l /etc/rc.local
-rwxr-xr-x 1 root root 718 May 16 01:13 /etc/rc.local
$ ls -l reboot.sh
-rwxrwxr-x 1 [user] [user] 179 May 16 01:16 reboot.sh

By the way rc.local used to work awhile ago, but suddenly stopped for an unknown reason. I'm not an experienced Linux user, so I've read a lot of posts about this problem, and the most often recommendations was to: check if the rc.local has a shebang line (check!); Set proper permissions to rc.local and the script (check!); check the status of the service (check!).

After hitting a rock with rc.local, I decided to give a try to some other methods.

I tried with crontab:

crontab -e

@reboot sh /home/[user]/azerothcore-wotlk/reboot.sh

Not starting on server boot. Starting normally if run manually.

Also tried init.d

sudo su
nano /etc/init.d/reboot

contents:

#!/bin/sh
/home/[user]/azerothcore-wotlk/reboot.sh

Then:

chmod ugo+x /etc/init.d/reboot   
update-rc.d reboot defaults

Same result - not starting on boot.

Then tried to create a service:

sudo nano /usr/bin/acore.sh

contents:

#!/bin/sh

screen -AmdS world /home/[user]/azerothcore-wotlk/acore.sh run-worldserver
screen -AmdS auth /home/[user]/azerothcore-wotlk/acore.sh run-authserver

sudo chmod +x /usr/bin/acore.sh

sudo nano /etc/systemd/system/acore.service

contents:

[Unit]
Description=My daemon

[Service]
ExecStart=/usr/bin/acore.sh
Restart=on-failure

[Install]
WantedBy=multi-user.target 

$ systemctl start acore.service

==== AUTHENTICATING FOR org.freedesktop.systemd1.manage-units ===
Authentication is required to start 'acore.service'.
Authenticating as: ,,, ([user])
Password:
==== AUTHENTICATION COMPLETE ===
systemctl enable mydaemon.service

systemctl enable acore.service

Not working either.

At this point I have absolutely no idea what to do. As I mentioned above, I'm not an experienced Linux user, so any help will be appreciated!

Thank you!

Edit: As @terdon suggested, I added the lines

/usr/bin/touch /tmp/rc.has.run

to the beginning of the rc file)

and

/usr/bin/touch /tmp/reboot.has.run

to the beginning of the reboot script

Both files have been created in the /tmp folder after rebooting the server.

Edit2: Thanks to @terdon the problem is solved by adding 'sleep 60' in the beginning of the rc.local.

9
  • Where is your screen executable? You can check with type screen. Try replacing the screen command in your script with the full path (e.g. /usr/bin/screen) and let us know if that makes any difference.
    – terdon
    May 21 at 22:14
  • screen is hashed (/usr/bin/screen). I added the screen path in the script, but still not starting after reboot.
    – lachev
    May 21 at 22:30
  • OK, please add that to your question (just edit the script and change it to use /usr/bin/screen so the next person to read it won't have the same question). Next thing to try is to add some debugging to check if the script is really not being launched. Add /usr/bin/touch /tmp/rc.has.run to the beginning of the rc file and /usr/bin/touch /tmp/reboot.has.run to the beginning of the reboot script, and then reboot and check /tmp and see if any files were created.
    – terdon
    May 21 at 22:34
  • Done. Both files are created in /tmp
    – lachev
    May 21 at 22:42
  • Ah! Now we're getting somewhere. So, we now know that both scripts are being executed. I suspect the problem might just be that they are running too soon before whatever else is needed for them to run has finished loading. So, change the rc file's command to this: sh '/home/[user]/azerothcore-wotlk/reboot.sh' 2>/tmp/reboot.error.log. That will redirect any error messages the script creates and you should be able to see what's happening.
    – terdon
    May 21 at 22:49
2

It looks like the problem isn't that the script isn't running, but that it is running too soon, before the system has finished setting everything up, and therefore fails because your machine isn't ready to run it yet. So a simple solution is to add a delay to the script so that it waits a bit before launching.

Edit your reboot.sh script, and add a sleep call:

#!/bin/sh

## wait for 60 seconds
sleep 60

/usr/bin/screen -AmdS world /home/[user]/azerothcore-wotlk/acore.sh run-worldserver
/usr/bin/screen -AmdS auth /home/[user]/azerothcore-wotlk/acore.sh run-authserver

You can experiment with the sleep value to find something that works and doesn't feel slow.

1
  • Thanks again for taking the time!
    – lachev
    May 22 at 12:04

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.