1

I have the following script in the /etc/systemd/system/ folder.

# Start the ruby on rails app on boot
[Unit]
Description=Start Ruby Online Ordering Application

[Service] Type=simple RemainAfterExit=yes Username=root PIDFile=/home/deviant/www/tmp/pids/server.pid WorkingDirectory=/home/deviant/www ExecStart=/home/deviant/www/run.sh TimeoutSec=300

[Install] WantedBy=multi-user.target

with a permission of -rw-r--r-- 1 root root

The run.sh script contains

#!/bin/sh
service httpd stop
rails s -p 80 -d

with a permission of -rwxrwxr-x 1 root root

In short, it is supposed to start a Ruby application upon restart of a server, however, it does not appear to be working.

Where can I check to see system error logs? What would cause it NOT to start upon a server restart?

I tried changing the script to:

[Service]
Type=oneshot
RemainAfterExit=yes
PIDFile=/home/deviant/www/tmp/pids/server.pid
WorkingDirectory=/home/deviant/www
ExecStart=/home/deviant/www/run.sh
TimeoutSec=300

And I now get on systemctl enable....

Unknown lvalue 'Username' in section 'Service' ...has Restart= setting other than no, which isn't allowed for Type=oneshot services. Refusing.

I'm not sure what this even means. What does it mean?

karel
  • 2,030
Kendall
  • 131

2 Answers2

2

If your Ruby application conflicts with the httpd service, I don't see why you should keep that service running just to stop it in your run.sh: just run systemctl disable httpd once and it won't even be started.

Now you can eliminate your run.sh altogether and make your service file with Type=simple and ExecStart=/full/path/to/rails s -p 80. Note the removal of the -d option; this is intentional and works well with Type=simple.

For insurance, you can add Conflicts=httpd.service to tell systemd that your service and httpd cannot run at the same time.

So your /etc/systemd/system/my-ruby-application.service should look like this:

# Start the ruby on rails app on boot
[Unit]
Description=Start Ruby Online Ordering Application
Conflicts=httpd.service

[Service]
Type=simple
Username=root
PIDFile=/home/deviant/www/tmp/pids/server.pid
WorkingDirectory=/home/deviant/www
ExecStart=/some/full/path/rails s -p 80
TimeoutSec=300

[Install]
WantedBy=multi-user.target

To make systemd restart your service if it fails for some reason, add a Restart= option that is suitable to your requirements (see Table 2 in man systemd.service). If you do that, it's recommended to also add a RestartSec=<sensible restart delay> to avoid bogging down your server with repeated restart attempts in 0.1s intervals (the default) if your service happens to keep failing after each restart attempt, perhaps because you edited its configuration file and accidentally made a mistake.

Once you've edited your my-ruby-application.service file, you should run systemctl daemon-reload, then systemctl disable httpd and systemctl stop httpd if you didn't already do that, and finally systemctl enable my-ruby-application and systemctl start my-ruby-application.

telcoM
  • 96,466
0

Did you reloaded the systemctl daemon ?

systemctl daemon-reload  
systemctl enable service_name

I know that Centos distros keep boot logs in

cat /var/log/boot.log