Article View: aus.computers.linux
Article #47160Re: Setting user context
From: Sam Yusuf Abu Ismail
Date: Sat, 16 Jan 1999 00:00
Date: Sat, 16 Jan 1999 00:00
181 lines
7030 bytes
7030 bytes
--------------9F463DD49F15D9382274E5BF
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit
Adam Carter wrote:
> I have setup squid to run on my RH 5.2 machine. I need to know how to
> set it up to run under a specific user context tho. ATM i start it in
> rc.local (is that bad?), well i attempt to start it in rc.local, it
> fails because it is not running as the correct user.
>
> Adam
Hi Adam,
To start squid or any other process as a different user use the su
command
in your rc.local script as follows:
su - squid_user -c /usr/local/squid/bin/squid
or something similarn (where squid_user is the username you want to
run squid as). As the su command is being run as root, no password
will be asked for.
Acutally I have a script at /etc/rc.d/init.d/squid which starts it
automatically.
To have it start at runlevel 3 you must also create a link in the dir of
the rc3.d to
this script, mine's called S85squid .
ie: once /etc/rc.d/init.d/squid is in place, cd to /etc/rc.d/rc3.d and
type:
ln -s ../init.d/squid S85squid
and this should run automatically on startup. This is a much neater way
of
doing it rather that shoving everything in rc.local, and also gives you
a way
of shutting squid down when changing run levels....
============== /etc/rc.d/init.d/squid =================
#!/bin/sh
#
# squid This shell script takes care of starting and stopping
# squid.
#
# description: squid provides caching http proxy server
# Source function library.
/etc/rc.d/init.d/functions
# Source networking configuration.
/etc/sysconfig/network
# Check that networking is up.
[ ${NETWORKING} = "no" ] && exit 0
[ -x /usr/local/squid/bin/squid ] || exit 0
[ -f /usr/local/squid/etc/squid.conf ] || exit 0
# See how we were called.
case "$1" in
start)
# Start daemons.
echo -n "Starting squid: "
su - squid -c /usr/local/squid/bin/squid &
echo "squid"
;;
stop)
# Stop daemons.
echo -n "Shutting down squid: "
kill `cat /usr/local/squid/logs/squid.pid`
echo
;;
restart)
$0 stop
$0 start
;;
status)
status squid
;;
*)
echo "Usage: squid {start|stop|restart|status}"
exit 1
esac
exit 0
==================== cut here ===========================
Hope it helps,
-sam-
--------------9F463DD49F15D9382274E5BF
Content-Type: text/html; charset=us-ascii
Content-Transfer-Encoding: 7bit
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
Adam Carter wrote:
<BLOCKQUOTE TYPE=CITE>I have setup squid to run on my RH 5.2 machine. I
need to know how to
<BR>set it up to run under a specific user context tho. ATM i start it
in
<BR>rc.local (is that bad?), well i attempt to start it in rc.local, it
<BR>fails because it is not running as the correct user.
<P>Adam</BLOCKQUOTE>
Hi Adam,
<P>To start squid or any other process as a different user use the su command
<BR>in your rc.local script as follows:
<P> <TT>su - squid_user -c /usr/local/squid/bin/squid</TT>
<P>or something similarn (where squid_user is the username you want to
<BR>run squid as). As the su command is being run as root, no password
<BR>will be asked for.
<P>Acutally I have a script at /etc/rc.d/init.d/squid which starts it automatically.
<BR>To have it start at runlevel 3 you must also create a link in the dir
of the rc3.d to
<BR>this script, mine's called S85squid .
<P>ie: once /etc/rc.d/init.d/squid is in place, cd to /etc/rc.d/rc3.d and
type:
<P><TT> ln -s ../init.d/squid S85squid</TT>
<P>and this should run automatically on startup. This is a much neater
way of
<BR>doing it rather that shoving everything in rc.local, and also gives
you a way
<BR>of shutting squid down when changing run levels....
<P>============== /etc/rc.d/init.d/squid =================
<P><TT>#!/bin/sh</TT>
<BR><TT>#</TT>
<BR><TT># squid This shell
script takes care of starting and stopping</TT>
<BR><TT>#
squid.</TT>
<BR><TT>#</TT>
<BR><TT># description: squid provides caching http proxy server</TT><TT></TT>
<P><TT># Source function library.</TT>
<BR><TT>. /etc/rc.d/init.d/functions</TT><TT></TT>
<P><TT># Source networking configuration.</TT>
<BR><TT>. /etc/sysconfig/network</TT><TT></TT>
<P><TT># Check that networking is up.</TT>
<BR><TT>[ ${NETWORKING} = "no" ] && exit 0</TT><TT></TT>
<P><TT>[ -x /usr/local/squid/bin/squid ] || exit 0</TT>
<BR><TT>[ -f /usr/local/squid/etc/squid.conf ] || exit 0</TT><TT></TT>
<P><TT># See how we were called.</TT>
<BR><TT>case "$1" in</TT>
<BR><TT> start)</TT>
<BR><TT> # Start daemons.</TT>
<BR><TT> echo -n "Starting squid:
"</TT>
<BR><TT> su - squid -c /usr/local/squid/bin/squid
&</TT>
<BR><TT> echo "squid"</TT>
<BR><TT> ;;</TT>
<BR><TT> stop)</TT>
<BR><TT> # Stop daemons.</TT>
<BR><TT> echo -n "Shutting down
squid: "</TT>
<BR><TT> kill `cat /usr/local/squid/logs/squid.pid`</TT>
<BR><TT> echo</TT>
<BR><TT> ;;</TT>
<BR><TT> restart)</TT>
<BR><TT> $0 stop</TT>
<BR><TT> $0 start</TT>
<BR><TT> ;;</TT>
<BR><TT> status)</TT>
<BR><TT> status squid</TT>
<BR><TT> ;;</TT>
<BR><TT> *)</TT>
<BR><TT> echo "Usage: squid {start|stop|restart|status}"</TT>
<BR><TT> exit 1</TT>
<BR><TT>esac</TT><TT></TT>
<P><TT>exit 0</TT>
<P>==================== cut here ===========================
<P>Hope it helps,
<BR>-sam-</HTML>
--------------9F463DD49F15D9382274E5BF--
Technical Details
Message-ID:
<369FF377.E3ADB4DC@netkafe.time.com.my>Path:
arc1-ca.pugleaf.net!unknown!not-for-mailReferences:
<369AC53A.4495619A@tip.csiro.au>Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 102983,5b3c7607fff9e8d1 X-Google-Attributes: gid102983,public From: Sam Yusuf Abu Ismail <syusuf@netkafe.time.com.my> Subject: Re: Setting user context Date: 1999/01/16 Message-ID: <369FF377.E3ADB4DC@netkafe.time.com.my> X-Deja-AN: 433272483 References: <369AC53A.4495619A@tip.csiro.au> Content-Type: multipart/alternative; boundary="------------9F463DD49F15D9382274E5BF" X-Trace: 16 Jan 1999 12:10:26 +1000, 139.134.220.29 MIME-Version: 1.0 Newsgroups: aus.computers.linux