I just started to learn about systemctl, I tried to create a service file that will run a nodejs script but it fails to run and the error doesn't really tell me why.
Here are the steps I've taken:
1) Navigated to /lib/systemd/system and created a file using the following command:
sudo nano /lib/systemd/system/hello_env.service 2) Created the following service file:
[Unit] Description= After=network.target [Service] Type=simple ExecStart=/usr/bin/node /home/dev/index.js Restart=always [Install] WantedBy=multi.user.target 3) typed sudo systemctl daemon-reload
4) Started the process:
sudo systemctl start hello_env 5) Checked status:
sudo systemctl status hello_env And got the following error:
> hello_env.service Loaded: loaded > (/lib/systemd/system/hello_env.service; disabled; vendor pres > Active: failed (Result: exit-code) since Wed 2020-01-29 16:00:37 IST; > 2s ago Process: 25605 ExecStart=/usr/bin/node > /home/dev/index.j Main PID: 25605 (code=exited, > status=1/FAILURE) > > Jan 29 16:00:37 sf-env systemd[1]: hello_env.service: Main process > exited, code Jan 29 16:00:37 sf-env systemd[1]: hello_env.service: > Failed with result 'exit- Jan 29 16:00:37 sf-env systemd[1]: > hello_env.service: Service hold-off time ove Jan 29 16:00:37 sf-env > systemd[1]: hello_env.service: Scheduled restart job, re Jan 29 > 16:00:37 sf-env systemd[1]: Stopped index.js - starting the bot. Jan > 29 16:00:37 sf-env systemd[1]: hello_env.service: Start request > repeated to Jan 29 16:00:37 sf-env systemd[1]: hello_env.service: > Failed with result 'exit- Jan 29 16:00:37 sf-env systemd[1]: Failed to > start index.js. Please note that If I navigate to /home/dev/index.js and run the script with node index.js it works just fine - please advise what I'm missing
type=simplewithtype=forking.systemctl daemon-reloadafterwards? Does your script exit with a 0 if it works?