I have set my environment variable using /etc/profile:
export VAR=/home/userhome
Then if I do echo $VAR it shows /home/userhome
But when I put reference to this variable into the /etc/init.d/servicename file, it cannot find this variable. When I run service servicename status using /etc/init.d/servicename file with following content:
case "$1" in
status)
cd $VAR/dir
;;
esac
it says /dir: No such file or directory
But it works if I run /etc/init.d/servicename status instead of service servicename status
How can I make unix service see environment variables?
rcscript directly also does not operate that way on systemd operating systems, as all invocations of the script are turned into invocations ofsystemctlby a hidden hook.