I need to start few process at boot time.
I did this :
1- Create the script with start/restart/…
2- add :
chkconfig: 345 99 0
3- add this script in /etc/init.d/
4- chkconfig --add my script
5- chkconfig --level 3 myscript on
Ok when I do >service myscript start it’s work.
Now my pbm is that at reboot time, it is ROOT user who launch the script and I don’t want to do that.
What could be the best solution to launch this script at boot time under an other user than root. This script has to be launch in his directory because it looks for other files in his specific dir.
I Thought do a SU - user1 -c /user/rep/thecommand
But it’s not enough as, the directory of the command in the script is not under ~/ of the user but under a subdirectory.
I also thought to create a symlink from the /home/user/dir1/command (with chown user1:user1) to /etc/init.d/command (with chown root:root).
But I’m not sure it will work ?
For example here is my script. It has to run in /home/user1/dir1/ and in /home/user1/dir1/src/pgm
I’m not sur it will work at boot time because it looks for file in different locations
description: script pgm1 carat hosting
chkconfig: 345 99 0
if [ “$1” = “start” ] ; then
echo "Starting "
if [ -r $PID_FILE ] ; then
mv -f $PID_FILE $PID_BACKUP
su - user1 -c /home/user1/dir1/src/pgm1
if [ ! -r $PID_FILE ] ; then
echo “Possible error encountered (not started ?)”
echo "Check above for possible errors, and this output of "
echo “pgm1.log” echo “=====================================================”
tail -n 5 /home/user1/dir1/pgm1.log
if [ -r $PID_BACKUP ] ; then
su - user1 -c mv -f $PID_BACKUP $PID_FILE
elif [ “$1” = “stop” ] ; then
echo “Stopping pgm”
elif [ “$1” = “rehash” ] ; then
echo “Rehashing pgm”
elif [ “$1” = “restart” ] ; then
echo “Restarting pgm”
elif [ “$1” = “mkpasswd” ] ; then
su - user1 -c /home/user1/dir1/src/pgm -P $2 $3
elif [ “$1” = “version” ] ; then
su - user1 -c /home/user1/dir1/src/pgm -v
echo “Usage: pgm start|stop|rehash|restart|mkpasswd|version”
Is there a better solution to do that than SU - user1 -c ?
Is a symlink from my pgm1 to /init.d/ --> /rc3.d/ will work and do what I’d like (I don’t want files created as pgm.pid are with root owner !! but user1) ?
All your comments suggestions are well welcomed