Run script on VPS start

I have a VPS, and I want to execute a script on the VPS starts. The script is located in /home/user_name/unicorn_start.sh with the following content:

#!/bin/bash
exec /etc/init.d/unicorn_appname start

As a root, I gave the permission to the script, so it can be executed: chmod +x unicorn_start.sh

Then, in /etc/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.
/home/user_name/unicorn_start.sh || exit 1
exit 0

But after I reboot the server, the script seems not to be executed.

Also, I tried to add it to crontab, by doing crongtab -e:

@reboot /home/user_name/unicorn_start.sh

But it didn't help either.

What am I doing wrong? Any help will be appreciated. Thanks.

2

1 Answer

So @Alex, you are doing a good bit wrong here... you said that you gave the "permission" to the script to be executable when in reality that means you made the script executable. You can find the actual permissions of the file by doing stat --format "%a" file_name but you were right, you need the script to be executable to run. Anyways, when you ran stat --format "%a" file_name this on your file, were the permissions 755?. If they weren't perform chmod 755 file_name, this should fix the issue(if you are still using crontab).

6

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

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

You Might Also Like