2

I am trying to export a simple Ruby app using foreman. Based on its usage for systemd, I appear to be doing things correctly.

However, when I start the target/service, I get status messages along the lines of this:

systemd[1]: Starting app-web-1.service...
systemd[1]: Started app-web-1.service.
systemd[1]: Service app-web-1.service is not needed anymore. Stopping.
systemd[1]: Stopping app-web-1.service...
systemd[1]: Stopped app-web-1.service.

The process begins, then ends. I have no idea why this is happening.

Granted, I am not an expert in systemd. This is my first time dealing with service scripts so I am not sure if there is something in the generated files that is causing this.

When exporting through foreman, a few target and service files are created. Thus, there are a few I have to deal with.

Here are the contents of app.target:

[Unit]
StopWhenUnneeded=true
Wants=app-web.target

[Install]
WantedBy=multi-user.target

And the contents of app-web-1.target:

[Unit]
StopWhenUnneeded=true
Wants=app-web-1.service

Finally, app-web-1.service:

[Unit]
StopWhenUnneeded=true

[Service]
User=deployer
WorkingDirectory=/home/deployer/app/releases/20141202043054
Environment=PORT=5000
ExecStart=/bin/bash -lc 'bundle exec puma -p 5000 '
Restart=always
StandardInput=null
StandardOutput=syslog
StandardError=syslog
SyslogIdentifier=%n
KillMode=process

Obviously, StopWhenUnneeded is part of the problem, but I am not sure what this is supposed to do in context of starting a web server within my app.

Can anyone help me figure how to get the server running and permanent?

2 Answers 2

2

While grawity was a great help on figuring out what the problem was, I finally solved by running a simple, but overlooked command:

sudo systemctl enable app.target

That was it. Just enable the target and the service will work like a charm.

The CoreOS docs helped me figure this out.

1

As in the manual pages, StopWhenUnneeded=true means "stop this unit as soon as no other active units depend on it anymore".

For example, if you start app.target, it depends on app-web-1.target which will also be started, and likewise depends on app-web-1.service.

But if you stop the main app.target later, normally it wouldn't affect other two units at all – they don't have any dependencies in the "reverse" direction, so both app-web-1.target and app-web-1.service would continue running.

In other words, the most likely intention was to allow one to stop everything using just systemctl stop app.target, without having to stop each service manually. It would have worked if the setting was only in the "sub"-unit files (although it's not ideal – BindsTo= is better in this case).

So the problem is with StopWhenUnneeded= in the main app.target unit. Since you start it manually, it never has any other units depending on it, therefore it will be stopped immediately.

0

You must log in to answer this question.

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