Hi all, having an issue, i have the below service setup and it runs grand, only thing is that I need it to run as a particular user and not root, I've tried many thing for example, adding in '--user={username}' between the daemon and config entries with no luck.
Any help is greatly appreciated.
#!/bin/bash
CONFIG="/opt/customapp/new_serv.conf"
DAEMON="/opt/customapp/new_serv"
USER="myuser"
# Checking for customapp binary
test -f $DAEMON || exit 0
# The init commands
case "$1" in
start)
echo "Starting customapp server..."
su - $USER -c $DAEMON $CONFIG > /dev/null 2>&1 &
;;
stop)
echo "Stopping customapp server..."
kill -9 `ps -C new_serv -o pid --no-headers`
;;
restart)
echo "Stopping customapp server..."
kill -9 `ps -C new_serv -o pid --no-headers`
echo "Starting customapp server..."
su - $USER -c $DAEMON $CONFIG > /dev/null 2>&1 &
;;
*)
echo "usage: /etc/init.d/customapp"
echo "$0 {start | stop | restart}"
exit 1
;;
esac
By the looks of that config file, you define the user it must run under here:
USER="myuser"
Which when you start it triggers:
Quote
su - $USER -c $DAEMON $CONFIG > /dev/null 2>&1 &
So that should work just fine and if you look in the process list it should be running under the user you define there.
The user must exist of course.