I have a node.js app that I want to set up as a service that gets started on bootup.
I can do that using systemctl by creating a script in /etc/systemd/system/TestApp.service .
The problem is that I want this app to be run inside a screen, so I can attach to it by logging into the system and issue command like screen -r -D TestApp
But doing so causes sysmtemctl to fail and the app does not start.
Here is the script that I have created:
[Unit]
Description=Script to start TestApp website on bootup
[Service]
ExecStart=/usr/bin/screen -S TestApp "/usr/bin/node /opt/NodeApps/TestApp/mainApp.js"
[Install]
WantedBy=multi-user.target
and here is the status of systemctl along with the error it throws:
sudo systemctl status TestApp.service
TestApp.service - Script to start TestApp website on bootup
Loaded: loaded (/etc/systemd/system/TestApp.service; disabled; vendor preset: enabled)
Active: failed (Result: exit-code) since Sun 2020-09-13 09:35:21 UTC; 30s ago
Main PID: 13012 (code=exited, status=1/FAILURE)
Sep 13 09:35:21 sp-webserver systemd[1]: Started Script to start TestApp website on bootup.
Sep 13 09:35:21 sp-webserver screen[13012]: Must be connected to a terminal.
Sep 13 09:35:21 sp-webserver systemd[1]: TestApp.service: Main process exited, code=exited, status=1/FAILURE
Sep 13 09:35:21 sp-webserver systemd[1]: TestApp.service: Failed with result 'exit-code'.
Please advice on how best to set this up so it runs inside a screen upon boot up.
screen
? If you need interactivity with the service, consider making the node service expose a socket, and provide a cli tool to communicate through it.systemctl
and you can lookup your logs injournalctl