Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>After looking at all the suggestions here, I've discovered a few things which I hope will be useful to others in my position:</p> <ol> <li><p><a href="https://stackoverflow.com/users/3850/hop">hop</a> is right to point me back at <code>/etc/init.d/functions</code>: the <code>daemon</code> function already allows you to set an alternate user:</p> <pre><code>daemon --user=my_user my_cmd &amp;&gt;/dev/null &amp; </code></pre> <p>This is implemented by wrapping the process invocation with <code>runuser</code> - more on this later.</p></li> <li><p><a href="https://stackoverflow.com/users/15168/jonathan-leffler">Jonathan Leffler</a> is right: there is setuid in Python:</p> <pre><code>import os os.setuid(501) # UID of my_user is 501 </code></pre> <p>I still don't think you can setuid from inside a JVM, however.</p></li> <li><p>Neither <code>su</code> nor <code>runuser</code> gracefully handle the case where you ask to run a command as the user you already are. E.g.:</p> <pre><code>[my_user@my_host]$ id uid=500(my_user) gid=500(my_user) groups=500(my_user) [my_user@my_host]$ su my_user -c "id" Password: # don't want to be prompted! uid=500(my_user) gid=500(my_user) groups=500(my_user) </code></pre></li> </ol> <p>To workaround that behaviour of <code>su</code> and <code>runuser</code>, I've changed my init script to something like:</p> <pre><code>if [[ "$USER" == "my_user" ]] then daemon my_cmd &amp;&gt;/dev/null &amp; else daemon --user=my_user my_cmd &amp;&gt;/dev/null &amp; fi </code></pre> <p>Thanks all for your help!</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload