init.d draaien als gebruiker

Pagina: 1
Acties:

  • Jeldert
  • Registratie: Juni 2001
  • Niet online

Jeldert

Rozijntjes

Topicstarter
Ik heb een eigen script gemaakt die het programma TSC moet opstarten. Dit gaat goed.

Het probleem is nu dat het script het programma start als root. Ik wil echter dat het gedraaid wordt als een andere gebruiker. Hoe doe ik dat?

Hier het script zoals het nu is:
code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
#! /bin/sh
# No Copyright (c) 2007 Jeldert Pol
# No rights reserved.
#
# Author: Jeldert Pol, Januari 25th, 2007

TSC_BIN=/home/jeldert/.CommunityTSC/TSC/D2OL
test -x $TSC_BIN || { echo "$TSC_BIN not installed";
        if [ "$1" = "stop" ]; then exit 0;
        else exit 5; fi; }

# Check for existence of needed config file and read it
TSC_CONTROL=/home/jeldert/.CommunityTSC/TSC/control.prp
test -r $TSC_CONTROL || { echo "$TSC_CONTROL not existing";
        if [ "$1" = "stop" ]; then exit 0;
        else exit 6; fi; }

case "$1" in
  start)
    # Start TSC
    nice -n 19 $TSC_BIN controller:file &
    ;;
  stop)
    # Stop TSC
    sed -e 's/Shutdown=false/Shutdown=true/g' -i $TSC_CONTROL
    sleep 3
    ;;
  *)
    echo "Usage: /etc/init.d/tsc {start|stop}"
    exit 1
    ;;
esac

exit 0

Juist


  • zAo
  • Registratie: Maart 2002
  • Laatst online: 31-01 10:31

zAo

GPLv2 Fanboy

Kun je niet gewoon het sticky-bit zetten voor de gebruiker zodat het onder deze gebruiker wordt gestart? Anders in het startscipt het volgende zetten:
code:
1
su - $USERNAME -c "$COMMAND"


Wel even de variabelen invullen uiteraard :)

  • Jeldert
  • Registratie: Juni 2001
  • Niet online

Jeldert

Rozijntjes

Topicstarter
Bedankt! Het werkt nu. Hier nog even het nieuwe script:
code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
#! /bin/sh
# No Copyright (c) 2007 Jeldert Pol
# No rights reserved.
#
# Author: Jeldert Pol, Januari 25th, 2007

TSC_BIN=/home/jeldert/.CommunityTSC/TSC/D2OL
USERNAME=jeldert

test -x $TSC_BIN || { echo "$TSC_BIN not installed";
        if [ "$1" = "stop" ]; then exit 0;
        else exit 5; fi; }

# Check for existence of needed config file and read it
TSC_CONTROL=/home/jeldert/.CommunityTSC/TSC/control.prp
test -r $TSC_CONTROL || { echo "$TSC_CONTROL not existing";
        if [ "$1" = "stop" ]; then exit 0;
        else exit 6; fi; }

case "$1" in
  start)
    # Start TSC
    su - $USERNAME -c "nice -n 19 $TSC_BIN controller:file &"
    ;;
  stop)
    # Stop TSC
    su - $USERNAME -c "sed -e 's/Shutdown=false/Shutdown=true/g' -i $TSC_CONTROL"
    sleep 3
    ;;
  *)
    echo "Usage: /etc/init.d/tsc {start|stop}"
    exit 1
    ;;
esac

exit 0

Juist


  • Zwerver
  • Registratie: Februari 2001
  • Niet online
Persoonlijk zou ik van start-stop-daemon gebruik maken in combinatie met de volgende optie:
-c|--chuid username|uid
Change to this username/uid before starting the process. You can
also specify a group by appending a :, then the group or gid in
the same way as you would for the `chown' command (user:group).
When using this option you must realize that the primary and
supplemental groups are set as well, even if the --group option
is not specified. The --group option is only for groups that
the user isn't normally a member of (like adding per/process
group membership for generic users like nobody).

Woonachtig Down Under. Ik negeer je insults niet, maar tegen de tijd dat ik ze lees zijn ze meestal niet relevant meer


  • Boudewijn
  • Registratie: Februari 2004
  • Niet online

Boudewijn

omdat het kan

eensch met zwerver, is iig een stuk netter.
wilde btw net dat ook posten.

Zaram module kopen voor je glasvezelaansluiting?


  • Jeldert
  • Registratie: Juni 2001
  • Niet online

Jeldert

Rozijntjes

Topicstarter
Ik zal er zo eens naar kijken.

Juist


  • wzzrd
  • Registratie: Februari 2000
  • Laatst online: 17-01 19:39

wzzrd

The guy with the Red Hat

SUID gebruiken ;)

Helemaal geen security issue of zo :O

  • smokalot
  • Registratie: Juni 2001
  • Laatst online: 15-01 22:00

smokalot

titel onder

of sudo, is ook wel net.

It sounds like it could be either bad hardware or software

Pagina: 1