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 startAs 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 0But 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.shBut it didn't help either.
What am I doing wrong? Any help will be appreciated. Thanks.
21 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).