Search code examples
bashrpmrpm-spec

rpm -U removes a symlink unless I use --force


I am trying using the following code in my spec file, I am installing my application as a standalone tomcat instance.

# Symlink $CATALINA_BASE/logs to /var/log/$SERVICE_NAME.
# If it's already there, we'll get rid of it and make a new symlink.
if [ -h "$RPM_INSTALL_PREFIX/logs" ]; then
    # It's a symlink, so just remove it.
    rm -f $RPM_INSTALL_PREFIX/logs
fi
# If it's still there, and it's a directory, see if we can rmdir it.
if [ -d "$RPM_INSTALL_PREFIX/logs" ]; then
    rmdir $RPM_INSTALL_PREFIX/logs >/dev/null 2>&1 || :
fi
if [ -e "$RPM_INSTALL_PREFIX/logs" ]; then
    # It's probably either a file or a dir, so we'll move it.
    mv $RPM_INSTALL_PREFIX/logs $RPM_INSTALL_PREFIX/logs.rpmsave || :
fi
ln -s /var/log/$SERVICE_NAME $RPM_INSTALL_PREFIX/logs || :

When this code runs with -i it creates and leaves the symlink there.

When I run a new version of the rpm with -U it executes this code and the symlink gets created correctly but when the rpm command exits the symlink gets deleted.

If I run -U --force a second time then the symlink stays.

How do I get the -U to stay without having to use --force?


Solution

  • This was resolved by adding a file in with the name logs as part of the update file list of the RPM and it stopped deleting the symlink automatically because it now thinks it is was there all along.