0

I'm using CentOS 7. I want to run a nodeJS script as a service but run the service as the "rails" user. As root, I created the file /usr/lib/systemd/system/myservice.service, with the contents

[Unit]
Description=mydir nodejs server

[Service]
ExecStart=/home/rails/mydir/start.sh
ExecStop=/home/rails/mydir/stop.sh

[Install]
WantedBy=multi-user.target

What else do I need to do to get the service to run as the user I want?

  • It looks like a quick Google would produce some useful examples, including some right here on U&LSE. – John Bollinger May 7 '18 at 20:05
  • Yeah but those are dealing with older versions of CentOS than what I listed in my question. E.g. top Google result is centos.org/forums/viewtopic.php?t=54865 but that deals with CenteOS 5. – Dave May 7 '18 at 20:44
1

You can specify the user and group under the [Service] heading:

User=rails
Group=rails

See the credentials section of systemd.exec for details.

Also, use /etc/systemd/system/myservice.service as the path for service files created by the system administrator instead of /usr/lib/systemd/system. See Creating and Modifying systemd Unit Files

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.