Execute a service as a specific user under ubuntuVMWare Server flakiness on Ubuntu 9.10Problem with...

Why can't the Brexit deadlock in the UK parliament be solved with a plurality vote?

How to make money from a browser who sees 5 seconds into the future of any web page?

What does "Scientists rise up against statistical significance" mean? (Comment in Nature)

I'm just a whisper. Who am I?

Can I run 125kHz RF circuit on a breadboard?

El Dorado Word Puzzle II: Videogame Edition

Why Shazam when there is already Superman?

Isometric embedding of a genus g surface

Can I say "fingers" when referring to toes?

Why do Radio Buttons not fill the entire outer circle?

Echo with obfuscation

Is there a distance limit for minecart tracks?

How to make a list of partial sums using forEach

Integral Notations in Quantum Mechanics

Can I cause damage to electrical appliances by unplugging them when they are turned on?

How to test the sharpness of a knife?

Why would five hundred and five be same as one?

Check if object is null and return null

What is this high flying aircraft over Pennsylvania?

The Digit Triangles

Does Doodling or Improvising on the Piano Have Any Benefits?

Do people actually use the word "kaputt" in conversation?

How much do grades matter for a future academia position?

Make a Bowl of Alphabet Soup



Execute a service as a specific user under ubuntu


VMWare Server flakiness on Ubuntu 9.10Problem with restarting MySQL server installed through aptitude on Ubuntu Lucid LynxNot able to setup juggernaut push notification server on ubuntuReset MySQL Passwordphp5cgi keeps dying and nginx gives 502 Bad GatewayPercona 5.6 not starting automatically after server reboot on Ubuntu with VirtualminStarting a script as another userRun command in screen when LSB initscript stoppedInstalling gitblit GO as service in Ubuntu Server 16.04I get this error “Active: failed ” from the Process: 9666 ExecStart=/etc/init.d/apache2 start (code=exited, status=2)?













0















I'm running a gameserver and want to start it on a screen on system start, but screen is user specific, so I have to run the command as 'user'. So I wrote this short service script which starts itself as 'user':



#!/bin/sh
#/etc/init.d/gameserver

case "$1" in
-user)
sleep 1
case "$2" in
start)
echo "Starting server..."
screen -dmS scr1 /home/user/game/run.sh
echo "Server started"
;;
stop) #definitely unfinished
echo "Stopping Server..."
#screen -S scr1 say Server is going down for a halt now!
#sleep 1
#screen -S scr1 stop
echo "Server stopped"
;;
*)
echo "Usage: /etc/init.d/gameserver {start|stop}"
exit 1
;;
esac
;;
*)
su - user -c "bash -c '/etc/init.d/gameserver -user $1'"
;;
esac

exit 0


and after sudo update-rc.d gameserver defaults the command sudo service gameserver start runs fine, but sadly the server isnt started on system startup.. I'm running Ubuntu 12.04 x64



edit: I've tried replacing su -c with setuid but still no change.










share|improve this question
















bumped to the homepage by Community 11 mins ago


This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.




















    0















    I'm running a gameserver and want to start it on a screen on system start, but screen is user specific, so I have to run the command as 'user'. So I wrote this short service script which starts itself as 'user':



    #!/bin/sh
    #/etc/init.d/gameserver

    case "$1" in
    -user)
    sleep 1
    case "$2" in
    start)
    echo "Starting server..."
    screen -dmS scr1 /home/user/game/run.sh
    echo "Server started"
    ;;
    stop) #definitely unfinished
    echo "Stopping Server..."
    #screen -S scr1 say Server is going down for a halt now!
    #sleep 1
    #screen -S scr1 stop
    echo "Server stopped"
    ;;
    *)
    echo "Usage: /etc/init.d/gameserver {start|stop}"
    exit 1
    ;;
    esac
    ;;
    *)
    su - user -c "bash -c '/etc/init.d/gameserver -user $1'"
    ;;
    esac

    exit 0


    and after sudo update-rc.d gameserver defaults the command sudo service gameserver start runs fine, but sadly the server isnt started on system startup.. I'm running Ubuntu 12.04 x64



    edit: I've tried replacing su -c with setuid but still no change.










    share|improve this question
















    bumped to the homepage by Community 11 mins ago


    This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.


















      0












      0








      0








      I'm running a gameserver and want to start it on a screen on system start, but screen is user specific, so I have to run the command as 'user'. So I wrote this short service script which starts itself as 'user':



      #!/bin/sh
      #/etc/init.d/gameserver

      case "$1" in
      -user)
      sleep 1
      case "$2" in
      start)
      echo "Starting server..."
      screen -dmS scr1 /home/user/game/run.sh
      echo "Server started"
      ;;
      stop) #definitely unfinished
      echo "Stopping Server..."
      #screen -S scr1 say Server is going down for a halt now!
      #sleep 1
      #screen -S scr1 stop
      echo "Server stopped"
      ;;
      *)
      echo "Usage: /etc/init.d/gameserver {start|stop}"
      exit 1
      ;;
      esac
      ;;
      *)
      su - user -c "bash -c '/etc/init.d/gameserver -user $1'"
      ;;
      esac

      exit 0


      and after sudo update-rc.d gameserver defaults the command sudo service gameserver start runs fine, but sadly the server isnt started on system startup.. I'm running Ubuntu 12.04 x64



      edit: I've tried replacing su -c with setuid but still no change.










      share|improve this question
















      I'm running a gameserver and want to start it on a screen on system start, but screen is user specific, so I have to run the command as 'user'. So I wrote this short service script which starts itself as 'user':



      #!/bin/sh
      #/etc/init.d/gameserver

      case "$1" in
      -user)
      sleep 1
      case "$2" in
      start)
      echo "Starting server..."
      screen -dmS scr1 /home/user/game/run.sh
      echo "Server started"
      ;;
      stop) #definitely unfinished
      echo "Stopping Server..."
      #screen -S scr1 say Server is going down for a halt now!
      #sleep 1
      #screen -S scr1 stop
      echo "Server stopped"
      ;;
      *)
      echo "Usage: /etc/init.d/gameserver {start|stop}"
      exit 1
      ;;
      esac
      ;;
      *)
      su - user -c "bash -c '/etc/init.d/gameserver -user $1'"
      ;;
      esac

      exit 0


      and after sudo update-rc.d gameserver defaults the command sudo service gameserver start runs fine, but sadly the server isnt started on system startup.. I'm running Ubuntu 12.04 x64



      edit: I've tried replacing su -c with setuid but still no change.







      ubuntu bash service gnu-screen startup






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Nov 10 '14 at 10:42







      y-spreen

















      asked Nov 9 '14 at 14:27









      y-spreeny-spreen

      1238




      1238





      bumped to the homepage by Community 11 mins ago


      This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.







      bumped to the homepage by Community 11 mins ago


      This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.
























          1 Answer
          1






          active

          oldest

          votes


















          0














          You need to enable it to be started at boot time




          update-rc.d gameserver enable




          or if you are doing it manually; you need symlink in most probably (/etc/rc2.d) to /etc/init.d/gameserver




          ln -s /etc/init.d/gameserver /etc/rc2.d/S99gameserver




          and to stop it at shutdown and reboot these two




          ln -s /etc/init.d/gameserver /etc/rc0.d/K99gameserver



          ln -s /etc/init.d/gameserver /etc/rc6.d/K99gameserver




          edit



          explicitly set PATH in your init script; it is likely failing because it cant find where 'screen' 'bash' and 'su' you are trying to run there are



          to set path do;




          export PATH=/sbin:/bin:/usr/sbin:/usr/bin:/usr/local/bin:/usr/local/sbin




          set this just after #!/bin/bash in your script






          share|improve this answer


























          • I forgot to mention the argument 'defaults' on the update-rc.d command, edited the post now. There are all these links already there, except its S/K20.. not S/K99..

            – y-spreen
            Nov 9 '14 at 14:58











          • is init script set as executable ? chmod 0755 /etc/init.d/gameserver ?

            – Hrvoje Špoljar
            Nov 9 '14 at 15:04











          • I ran a chmod +x on it. Also tried chmod 0755 as you suggested, but it didnt change anything

            – y-spreen
            Nov 9 '14 at 15:08











          • can you add something like touch /tmp/foo in your init script and check when computer boots if /tmp/foo exists; this will tell you if your init script ran at all... trying to narrow down

            – Hrvoje Špoljar
            Nov 9 '14 at 15:25











          • also; try set path; I think path is not set and screen can't be found when you run your script at boot time... whereas when you run it from shell it inherits PATH you currently have set

            – Hrvoje Špoljar
            Nov 9 '14 at 15:29











          Your Answer








          StackExchange.ready(function() {
          var channelOptions = {
          tags: "".split(" "),
          id: "2"
          };
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function() {
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled) {
          StackExchange.using("snippets", function() {
          createEditor();
          });
          }
          else {
          createEditor();
          }
          });

          function createEditor() {
          StackExchange.prepareEditor({
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader: {
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          },
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          });


          }
          });














          draft saved

          draft discarded


















          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fserverfault.com%2fquestions%2f643078%2fexecute-a-service-as-a-specific-user-under-ubuntu%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown

























          1 Answer
          1






          active

          oldest

          votes








          1 Answer
          1






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes









          0














          You need to enable it to be started at boot time




          update-rc.d gameserver enable




          or if you are doing it manually; you need symlink in most probably (/etc/rc2.d) to /etc/init.d/gameserver




          ln -s /etc/init.d/gameserver /etc/rc2.d/S99gameserver




          and to stop it at shutdown and reboot these two




          ln -s /etc/init.d/gameserver /etc/rc0.d/K99gameserver



          ln -s /etc/init.d/gameserver /etc/rc6.d/K99gameserver




          edit



          explicitly set PATH in your init script; it is likely failing because it cant find where 'screen' 'bash' and 'su' you are trying to run there are



          to set path do;




          export PATH=/sbin:/bin:/usr/sbin:/usr/bin:/usr/local/bin:/usr/local/sbin




          set this just after #!/bin/bash in your script






          share|improve this answer


























          • I forgot to mention the argument 'defaults' on the update-rc.d command, edited the post now. There are all these links already there, except its S/K20.. not S/K99..

            – y-spreen
            Nov 9 '14 at 14:58











          • is init script set as executable ? chmod 0755 /etc/init.d/gameserver ?

            – Hrvoje Špoljar
            Nov 9 '14 at 15:04











          • I ran a chmod +x on it. Also tried chmod 0755 as you suggested, but it didnt change anything

            – y-spreen
            Nov 9 '14 at 15:08











          • can you add something like touch /tmp/foo in your init script and check when computer boots if /tmp/foo exists; this will tell you if your init script ran at all... trying to narrow down

            – Hrvoje Špoljar
            Nov 9 '14 at 15:25











          • also; try set path; I think path is not set and screen can't be found when you run your script at boot time... whereas when you run it from shell it inherits PATH you currently have set

            – Hrvoje Špoljar
            Nov 9 '14 at 15:29
















          0














          You need to enable it to be started at boot time




          update-rc.d gameserver enable




          or if you are doing it manually; you need symlink in most probably (/etc/rc2.d) to /etc/init.d/gameserver




          ln -s /etc/init.d/gameserver /etc/rc2.d/S99gameserver




          and to stop it at shutdown and reboot these two




          ln -s /etc/init.d/gameserver /etc/rc0.d/K99gameserver



          ln -s /etc/init.d/gameserver /etc/rc6.d/K99gameserver




          edit



          explicitly set PATH in your init script; it is likely failing because it cant find where 'screen' 'bash' and 'su' you are trying to run there are



          to set path do;




          export PATH=/sbin:/bin:/usr/sbin:/usr/bin:/usr/local/bin:/usr/local/sbin




          set this just after #!/bin/bash in your script






          share|improve this answer


























          • I forgot to mention the argument 'defaults' on the update-rc.d command, edited the post now. There are all these links already there, except its S/K20.. not S/K99..

            – y-spreen
            Nov 9 '14 at 14:58











          • is init script set as executable ? chmod 0755 /etc/init.d/gameserver ?

            – Hrvoje Špoljar
            Nov 9 '14 at 15:04











          • I ran a chmod +x on it. Also tried chmod 0755 as you suggested, but it didnt change anything

            – y-spreen
            Nov 9 '14 at 15:08











          • can you add something like touch /tmp/foo in your init script and check when computer boots if /tmp/foo exists; this will tell you if your init script ran at all... trying to narrow down

            – Hrvoje Špoljar
            Nov 9 '14 at 15:25











          • also; try set path; I think path is not set and screen can't be found when you run your script at boot time... whereas when you run it from shell it inherits PATH you currently have set

            – Hrvoje Špoljar
            Nov 9 '14 at 15:29














          0












          0








          0







          You need to enable it to be started at boot time




          update-rc.d gameserver enable




          or if you are doing it manually; you need symlink in most probably (/etc/rc2.d) to /etc/init.d/gameserver




          ln -s /etc/init.d/gameserver /etc/rc2.d/S99gameserver




          and to stop it at shutdown and reboot these two




          ln -s /etc/init.d/gameserver /etc/rc0.d/K99gameserver



          ln -s /etc/init.d/gameserver /etc/rc6.d/K99gameserver




          edit



          explicitly set PATH in your init script; it is likely failing because it cant find where 'screen' 'bash' and 'su' you are trying to run there are



          to set path do;




          export PATH=/sbin:/bin:/usr/sbin:/usr/bin:/usr/local/bin:/usr/local/sbin




          set this just after #!/bin/bash in your script






          share|improve this answer















          You need to enable it to be started at boot time




          update-rc.d gameserver enable




          or if you are doing it manually; you need symlink in most probably (/etc/rc2.d) to /etc/init.d/gameserver




          ln -s /etc/init.d/gameserver /etc/rc2.d/S99gameserver




          and to stop it at shutdown and reboot these two




          ln -s /etc/init.d/gameserver /etc/rc0.d/K99gameserver



          ln -s /etc/init.d/gameserver /etc/rc6.d/K99gameserver




          edit



          explicitly set PATH in your init script; it is likely failing because it cant find where 'screen' 'bash' and 'su' you are trying to run there are



          to set path do;




          export PATH=/sbin:/bin:/usr/sbin:/usr/bin:/usr/local/bin:/usr/local/sbin




          set this just after #!/bin/bash in your script







          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited Nov 9 '14 at 15:32

























          answered Nov 9 '14 at 14:49









          Hrvoje ŠpoljarHrvoje Špoljar

          4,4901839




          4,4901839













          • I forgot to mention the argument 'defaults' on the update-rc.d command, edited the post now. There are all these links already there, except its S/K20.. not S/K99..

            – y-spreen
            Nov 9 '14 at 14:58











          • is init script set as executable ? chmod 0755 /etc/init.d/gameserver ?

            – Hrvoje Špoljar
            Nov 9 '14 at 15:04











          • I ran a chmod +x on it. Also tried chmod 0755 as you suggested, but it didnt change anything

            – y-spreen
            Nov 9 '14 at 15:08











          • can you add something like touch /tmp/foo in your init script and check when computer boots if /tmp/foo exists; this will tell you if your init script ran at all... trying to narrow down

            – Hrvoje Špoljar
            Nov 9 '14 at 15:25











          • also; try set path; I think path is not set and screen can't be found when you run your script at boot time... whereas when you run it from shell it inherits PATH you currently have set

            – Hrvoje Špoljar
            Nov 9 '14 at 15:29



















          • I forgot to mention the argument 'defaults' on the update-rc.d command, edited the post now. There are all these links already there, except its S/K20.. not S/K99..

            – y-spreen
            Nov 9 '14 at 14:58











          • is init script set as executable ? chmod 0755 /etc/init.d/gameserver ?

            – Hrvoje Špoljar
            Nov 9 '14 at 15:04











          • I ran a chmod +x on it. Also tried chmod 0755 as you suggested, but it didnt change anything

            – y-spreen
            Nov 9 '14 at 15:08











          • can you add something like touch /tmp/foo in your init script and check when computer boots if /tmp/foo exists; this will tell you if your init script ran at all... trying to narrow down

            – Hrvoje Špoljar
            Nov 9 '14 at 15:25











          • also; try set path; I think path is not set and screen can't be found when you run your script at boot time... whereas when you run it from shell it inherits PATH you currently have set

            – Hrvoje Špoljar
            Nov 9 '14 at 15:29

















          I forgot to mention the argument 'defaults' on the update-rc.d command, edited the post now. There are all these links already there, except its S/K20.. not S/K99..

          – y-spreen
          Nov 9 '14 at 14:58





          I forgot to mention the argument 'defaults' on the update-rc.d command, edited the post now. There are all these links already there, except its S/K20.. not S/K99..

          – y-spreen
          Nov 9 '14 at 14:58













          is init script set as executable ? chmod 0755 /etc/init.d/gameserver ?

          – Hrvoje Špoljar
          Nov 9 '14 at 15:04





          is init script set as executable ? chmod 0755 /etc/init.d/gameserver ?

          – Hrvoje Špoljar
          Nov 9 '14 at 15:04













          I ran a chmod +x on it. Also tried chmod 0755 as you suggested, but it didnt change anything

          – y-spreen
          Nov 9 '14 at 15:08





          I ran a chmod +x on it. Also tried chmod 0755 as you suggested, but it didnt change anything

          – y-spreen
          Nov 9 '14 at 15:08













          can you add something like touch /tmp/foo in your init script and check when computer boots if /tmp/foo exists; this will tell you if your init script ran at all... trying to narrow down

          – Hrvoje Špoljar
          Nov 9 '14 at 15:25





          can you add something like touch /tmp/foo in your init script and check when computer boots if /tmp/foo exists; this will tell you if your init script ran at all... trying to narrow down

          – Hrvoje Špoljar
          Nov 9 '14 at 15:25













          also; try set path; I think path is not set and screen can't be found when you run your script at boot time... whereas when you run it from shell it inherits PATH you currently have set

          – Hrvoje Špoljar
          Nov 9 '14 at 15:29





          also; try set path; I think path is not set and screen can't be found when you run your script at boot time... whereas when you run it from shell it inherits PATH you currently have set

          – Hrvoje Špoljar
          Nov 9 '14 at 15:29


















          draft saved

          draft discarded




















































          Thanks for contributing an answer to Server Fault!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid



          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.


          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fserverfault.com%2fquestions%2f643078%2fexecute-a-service-as-a-specific-user-under-ubuntu%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          As a Security Precaution, the user account has been locked The Next CEO of Stack OverflowMS...

          Список ссавців Італії Природоохоронні статуси | Список |...

          Українські прізвища Зміст Історичні відомості |...