0

I want to run a process with a specific user.

On RHEL 7, I am able to this with:

source /etc/rc.d/init.d/functions
daemon --user=myuser $JAVA_HOME/bin/java -cp $appClassPath $MAIN_CLASS

How can I achieve the same behavior on SLES12? The /etc/rc.d/init.d/functions is not available on SLES12 out of the box.

2

1 Answer 1

0

SUSE wants Your to use LSB start_daemon. (https://en.opensuse.org/openSUSE:Packaging_init_scripts).
But I'm not certain whether it will be continued in systemd times or is about to be phases out.
Of course recommended way in systemd systems is to create a systemd unit...

Otherwise use the default tools like runuser or su or even sudo which has the convenience that You can call it as any user with permissions to run that command line.
Background and detach Your program within these wrappers (or exec it). Possibly with help of nohup.
That is more standard conforming and not coupled to a deprecated init-system infrastructure.

3
  • I have created the systemd unit file. Is there a different way to specify user in systemd unit file? Nov 25, 2019 at 7:59
  • 1
    Use User=someuser in the [Service] section on the unit file. These things are easy to google. Nov 25, 2019 at 9:26
  • 1
    Also the question title is misleading. "Run a process as different user" does not sound like working on a systemd unit... ;-)
    – user301446
    Nov 25, 2019 at 18:12

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .