1

My systemd service file is in the name of os.service and has the following line of configuration.

#  This systemd service file will help supervise os service
[Unit]
Description=Os Server
After= network.target

[Service]

# Preferably configure a non-privileged user
# User=deploy
# Group=deploy

# Environment variables shared across the config
#EnvironmentFile=  # environment file to be used, includes RACK_ENV
EnvironmentFile=/home/deploy/test/shared/.env
SyslogIdentifier=test
PIDFile=/home/deploy/test/shared/tmp/server.pid

# Specify the path to your test application root
# WorkingDirectory=/home/deploy/test/

# Start/Reload/Stop syntax
ExecStart=/home/deploy/test/current

# TimeoutSec=15
# TimeoutStopSec=10
RestartSec=5s           

# Restart os, always if it dies for some reason
Restart=always

[Install]
WantedBy=multi-user.target

In server when I disconnect my ssh connection then service dies and results in 502 Bad Gateway. I have to ssh and run systemctl --user start os.service to start and make it work. Again once i close my terminal then os.service dies again.

2

You’re running the service from your user manager (--user), and apparently your logind doesn’t have lingering enabled for you. As a result, your session (including any services started inside it) is closed down whenever you log out.

To change this behaviour, you need to enable lingering:

sudo loginctl enable-linger $USER

This will start a user manager for you at boot and allow your services to survive your login sessions.

A better approach for a system service such as this is really to run it as its own user, managed by the main systemd instance.

1
  • Thanks. That solved!!!!. I used command loginctl enable-linger $USER and close my ssh connection server and systemd service is running fine.
    – NinjaMAN
    Jun 17 '19 at 5:24

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.