Answer the question
In order to leave comments, you need to log in
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
[Unit]
Description=Analytic Front Service
After=network.target
[Service]
Type=simple
ExecStart=/home/aa/services/af.sh
Restart=always
[Install]
WantedBy=multi-user.target
Answer the question
In order to leave comments, you need to log in
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.
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
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question