0

I need help with converting an upstart .conf into a systemd .service. Essentially what my .conf file does is this: exec su -l foo -c 'cd /var/www/path/to/file ; bundle exec puma -C config/puma.rb'

As far as I can tell, we are running the command as root, and then creating a login shell using our "user":

root 1 0.0 0.0 5 7 ? Ss Date 0:00 su -l foo -c cd /var/www/path/to/file ; bundle exec puma -C config/puma.rb foo 2 0.0 0.0 6 8 ? Ss Date 0:00 -su -c cd /var/www/path/to/file ; bundle exec puma -C config/puma.rb

This is what I have so far with my systemd .service file:

[Unit]
Description=simple boot on start
After=network.target

[Service]
Type=simple
User=foo
WorkingDirectory=/var/www/path/to/file
ExecStart=/usr/bin/sudo /bin/bash -lc 'bundle exec puma -C /var/www/path/to/file/config/puma.rb'
Restart=always

[Install]
WantedBy=multi-user.target

I know this is wrong, but it works...sort of. In the sense that I get the process to run, but as root. Not running the command as root to run the process as the "user":

root 3 0.0 0.0 4 5 ? Ss Date 0:00 /usr/bin/sudo /bin/bash -lc bundle exec puma -C /var/www/path/to/file/config/puma.rb

This is pretty new to me at a new job, so trying to find may around this system. Any help is appreciated.

Thanks! D

1

You're not meant to just copy things literally into ExecStart=, especially those which are just for setup, like changing the working directory or user. Those have different directives (which you already used!) so you should just start your program.

For Puma in particular, you should just start with the sample systemd unit, and customize it to add the user, working directory, path to puma, and (if applicable) your TLS certificate and key.

| improve this answer | |
  • Just for context, I did not just copy what was there over. That has been the result of finding my way to that...solution. The closest I came to getting anything working, using another result was this: Type=simple User=foo WorkingDirectory=/var/www/path/to/file ExecStartPre=/bin/bash -c 'PATH=$PATH:/usr/local/bin' ExecStart=/bin/bash -lc 'bundle exec puma -C config/puma.rb' Restart=always But the process would kick off, but not persist. I would run once and never restart. – Dubl1n Dec 27 '18 at 19:58
  • I did find a solution to my problem, and while it is not ideal, it is a combination of the link Michael sent (which I is why I am marking as resolved). It helped with the ExecStop= portion, which I was also having trouble with. But the ExecStart= I ended up writing a script to do the things the way I needed to do them. – Dubl1n Dec 28 '18 at 17:02
  • Sure, occasionally you do need a script. The point here was that you don't need to use a script to do things that systemd can handle for you, like switching users or changing directories. – Michael Hampton Dec 28 '18 at 17:22

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.