0

I need to create a service that will automatically start my Rails server. Since the rails server command works correctly only in the application directory, I use the /lib/systemd/system/dev.fhc.name.service file with the following content:

[Unit]
Description=Puma development server for fhc.name domain

[Service]
ExecStart=cd /home/fhc/www && screen -dmS dev.fhc.name rails server -u puma -e development -p 3001
ExecStop=screen -X -S dev.fhc.name quit
Type=idle
KillMode=process

SyslogIdentifier=dev-fhc-name
SyslogFacility=daemon

Restart=on-failure

[Install]
WantedBy=multi-user.target

However, trying to run it:

sudo systemctl start dev.fhc.name

Leads to an error:

Aug 25 23:00:51 fhc.name systemd[1]: /lib/systemd/system/dev.fhc.name.service:5: Executable "cd" not found in path "/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"

What am I doing wrong?

2

1 Answer 1

1

Based on this answer you should use directive WorkingDirectory. Do not forget other directives like ExecStart should have full path.

And for me usage of screen look a bit odd and not in place.

4
  • For some reason, Puma won't start with the -d flag. It writes a success notification as a daemon, and immediately stops without any errors. So you have to use screen.
    – Risto
    Aug 26, 2022 at 12:19
  • 1
    You don't start services daemonized with systemd. Aug 26, 2022 at 12:27
  • @GeraldSchneider Yes, you're right, I didn't think about removing it when transferring the command to the service. True, now the question arises, how to write the command to stop this particular server in ExecStop?
    – Risto
    Aug 26, 2022 at 12:48
  • 1
    rails should create a pid file. Use it in systemd. Aug 26, 2022 at 12:50

You must log in to answer this question.

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