start process at boot under a different username

I’m running openSuse 10.3.

How do i start a process running under a particular username at boot

Take for example. I would like to startup apache2 httpd at boot to run as username=‘wwwrun’.
I’ve created a script located at /etc/init.d/start-apache.sh
executed chmod 755 start-apache.sh
executed chkconfig start-apache.sh 5
after i rebooted the system. i executed ‘ps -Fely’. and found that httpd is assocated with a username that is my currently logged in session.

Could someone give me some pointers?

Thanks.

the content of start-apache.sh is show below:

#!/bin/bash

BEGIN INIT INFO

Provides:

Required-Start: $network $syslog

Should-Start:

Required-Stop:

Default-Start: 5

Default-Stop: 5

Short-Description: start/stop apache http server

Description: start/stop apache http server

END INIT INFO

OWNER_USER=wwwrun

start() {
su - ${OWNER_USER} -c “/usr/local/bin/apache2/bin/apachectl -k start”
return 0
}

stop() {
su - ${OWNER_USER} -c “/usr/local/bin/apache2/bin/apachectl -k stop”
return 0
}

case “$1” in
start)
start
;;
stop)
stop
;;
restart)
stop
sleep 10
start
;;
*)
echo “Usage: $0 {start|stop|restart}”
exit 1
esac

exit $?

My Apache runs is run by wwwrun. That is a normal Aoache feature.

There is a file /etc/apache2/uid.conf with contents:

# cat uid.conf
User wwwrun
Group www

This file is included in /etc/apache2/httpd.conf.

IMHO this is the deafult configuration.

I think you are misunderstanding the relationship of usernames in Linux. Certain usernames are associated with certain (types of) programs; this does not stop a human user interacting with them but limits the number of dangerous things the human user (or hacker) can do with them.

That is why you can only access these programs as a human user.

You don’t need to do anything. By default, as hcvv points out, Apache already runs as wwwrun, and this is set in its config files. This only happens when Apache starts off as root, which has the privilege to switch users in the Apache process. By trying to force it to run as a user from the script, you are interfering with the normal order of things. So put things back the way they were and sit on your hands for a while. :wink:

Thanks for the reply to date. I forgot to mention one thing. I am installing apache2 from source. ie not from the openSuse distribution DVD. Hence, i need to know how to set things up so that apache start under a different username other than root.

I hope this clarifies things s bit.

Same answer, it’s specified in Apache’s config and Apache does the setuid internally.