public_html/ being recreated automatically via non-interactive shell?

Zbx3x4UyxPy7Ty2

Registered
Feb 24, 2014
4
0
1
cPanel Access Level
Root Administrator
I am deploying an application using a tool like Capistrano, sending individual commands to the server via a non-interactive shell.

public_html/ for the cPanel account is configured as a symlink, pointing to a path like

Code:
/home/acctname/public_html -> /home/acctname/app/revisions/201402221245
When sending 2 commands back to back to 1) remove the existing symlink or the default directory cPanel created and then 2) create a new symlink

Code:
rm -rf /home/acctname/public_html
ln -fs /home/acctname/app/revisions/201402221245 /home/acctname/public_html
Instead of seeing the symlink I expect

Code:
/home/acctname/public_html -> /home/acctname/app/revisions/201402221245
I see the following

Code:
/home/acctname/public_html/201402221245 -> /home/acctname/app/revisions/201402221245
It seems when the non-interactive shell connection is established to send the command creating the symlink, something is noticing the public_html/ directory no longer exists and is recreating it.

I've checked thoroughly to make sure none of my application code or deployment code is doing this, so I'm wondering: what is causing this behavior?
 

Zbx3x4UyxPy7Ty2

Registered
Feb 24, 2014
4
0
1
cPanel Access Level
Root Administrator
It looks like /etc/bashrc has the following, which is most definitely the source of my problem

Code:
if [ ! -e ~/public_html/cgi-bin ]; then
    mkdir -p ~/public_html/cgi-bin
fi
 

vanessa

Well-Known Member
PartnerNOC
Sep 26, 2006
833
28
178
Virginia Beach, VA
cPanel Access Level
DataCenter Provider
First, can you clarity what 'non-interactive' shell you are using? There are a couple scripts that will recreate docroots, but it's possible perhaps the public_htm isn't actually getting removed in the first place. I'm curious though - why do an rm -rf instead of an unlink? Unlink is safer for symlinks:

Code:
unlink /home/acctname/public_html
ln -fs /home/acctname/app/revisions/201402221245 /home/acctname/public_html
 

Zbx3x4UyxPy7Ty2

Registered
Feb 24, 2014
4
0
1
cPanel Access Level
Root Administrator
public_html/ is definitely getting removed.

I say "non-interactive" because I have mostly default ssh settings for Capistrano, and it's docs say it assigns a non-login,
/http://capistranorb.com/documentation/faq/why-does-something-work-in-my-ssh-session-but-not-in-capistrano/

I am not an expert in which startup files are included for login/non-login & interactive/non-interactive shells, but so far /etc/bashrc is the only one I've come across which is definitely trying to recreate the public_html/ directory.

Thank you for your tip about using unlink.

A follow-up question I have is: will /etc/bashrc be reset by cPanel when cPanel updates are performed?
 

cPanelMichael

Administrator
Staff member
Apr 11, 2011
47,911
2,234
363
Manually modifications to /etc/bashrc should not be overwritten by cPanel updates. It's often done to prevent the automatic creation of the cgi-bin directory.

Thank you.
 

oldchili

Member
Mar 18, 2014
5
0
1
cPanel Access Level
Root Administrator
Have you tried executing in succession?

Code:
rm -rf /home/acctname/public_html && ln -fs /home/acctname/app/revisions/201402221245 /home/acctname/public_html
I had the same issue when developing my Capistrano deployment scripts. The above solved my problem.