I have created an init.d script to control a process as a service, in RHEL 6.x. In the script, I am using /sbin/runuser to start the process as an unprivileged user. This part of the script is working fine.
The script is operated as sudo service scriptname operation
example, sudo service httpd restart
Additionally, I want to logout the user who ran the above command. In normal bash scripts, I have used variously $USER, $SUDO_USER and $logname to get the user running the script. The same does not seem to work when the script is run using the "service" executable.
What am I missing? How can I get the name of the user running the service command inside the script being run by the service command?