D
D
di2019-12-11 10:41:06
linux
di, 2019-12-11 10:41:06

How to run commands in daemon mode?

OS - ubuntu 18.04
There is a command that goes into the service code directory and calls npm start there to start the service locally
cd ~/services/analytic-front && npm start
. I want to run it as a daemon. In order to be able to put the daemon into autoload, for example, you often have to raise the service for testing on your machine. Well, for your own self-development, it's interesting.
I created af.sh file in /home/aa/services directory

#!/bin/bash
cd ~/services/analytic-front && npm start

The file is executable, when run directly, the script works correctly
Then in etc / systemd / system I created the af.service file with a description of the daemon
[Unit]
Description=Analytic Front Service
After=network.target

[Service]
Type=simple
ExecStart=/home/aa/services/af.sh
Restart=always

[Install]
WantedBy=multi-user.target

But the result is deplorable
5df09ae1d32f0303427800.jpeg
What's wrong?

Answer the question

In order to leave comments, you need to log in

4 answer(s)
V
Vladimir, 2019-12-11
@Delgus

https://stackoverflow.com/questions/4018154/how-do...

A
Alexey Dmitriev, 2019-12-11
@SignFinder

When starting from the console, does the application break away from it, or does it continue to hang in the console?
If the second - you need to tear it off the console through nohup, for example.

P
pfg21, 2019-12-11
@pfg21

stands and gets rid of the bash layer in the service
i.e. instead of cd ~/services/analytic-front && npm start you
write
WorkingDirectory=/home/%USER%/services/analytic-front
ExecStart=/home/%USER%/services/analytic-front/npm start in the
script appropriate
User=
Group=
to not start the service as root because it's not secure.
ps systemd does not like relative paths, also because of security

A
Alexander Chernykh, 2019-12-11
@sashkets

there is also supervisord for such cases

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question