Systemd custom service doesn't read PATH
Clash Royale CLAN TAG#URR8PPP
up vote
0
down vote
favorite
I am trying to run a Node.js app as a service in Debian 9. So, following some tutorials, I've made a service like that.
[Unit]
Description=bumer API Http Server
[Service]
PIDFile=/tmp/bumer-service.pid
User=root
Group=root
Restart=always
KillSignal=SIGQUIT
WorkingDirectory=/root/bumer/
SyslogIdentifier=bumer
ExecStart=/root/bumer/app.js
[Install]
WantedBy=multi-user.target
My app has #!/usr/bin/env node
as its first line and it runs pretty well if I run the command /root/bumer/app.js
.
The problem is that when I start the service I was getting the following error:
main process exited, code=exited, status=127/n/a
So, I tried to change the first line of the app.js file to the node's path instead of the word "node" #!/usr/bin/env /usr/local/lib/nodejs/node-v8.11.4/bin/node
and now it's running fine.
I guess the service is not reading the PATH variable and I need some help to realize why it doesn't.
(my PATH is right and when I run "type node" the result is OK).
root@bumer:~# type node
node is /usr/local/lib/nodejs/node-v8.11.4/bin/node
(I am logging the variable PORT which I set on ~/.bashrc on the app.js but it cannot read as well, it logs undefined
).
systemd path services node.js
add a comment |Â
up vote
0
down vote
favorite
I am trying to run a Node.js app as a service in Debian 9. So, following some tutorials, I've made a service like that.
[Unit]
Description=bumer API Http Server
[Service]
PIDFile=/tmp/bumer-service.pid
User=root
Group=root
Restart=always
KillSignal=SIGQUIT
WorkingDirectory=/root/bumer/
SyslogIdentifier=bumer
ExecStart=/root/bumer/app.js
[Install]
WantedBy=multi-user.target
My app has #!/usr/bin/env node
as its first line and it runs pretty well if I run the command /root/bumer/app.js
.
The problem is that when I start the service I was getting the following error:
main process exited, code=exited, status=127/n/a
So, I tried to change the first line of the app.js file to the node's path instead of the word "node" #!/usr/bin/env /usr/local/lib/nodejs/node-v8.11.4/bin/node
and now it's running fine.
I guess the service is not reading the PATH variable and I need some help to realize why it doesn't.
(my PATH is right and when I run "type node" the result is OK).
root@bumer:~# type node
node is /usr/local/lib/nodejs/node-v8.11.4/bin/node
(I am logging the variable PORT which I set on ~/.bashrc on the app.js but it cannot read as well, it logs undefined
).
systemd path services node.js
add a comment |Â
up vote
0
down vote
favorite
up vote
0
down vote
favorite
I am trying to run a Node.js app as a service in Debian 9. So, following some tutorials, I've made a service like that.
[Unit]
Description=bumer API Http Server
[Service]
PIDFile=/tmp/bumer-service.pid
User=root
Group=root
Restart=always
KillSignal=SIGQUIT
WorkingDirectory=/root/bumer/
SyslogIdentifier=bumer
ExecStart=/root/bumer/app.js
[Install]
WantedBy=multi-user.target
My app has #!/usr/bin/env node
as its first line and it runs pretty well if I run the command /root/bumer/app.js
.
The problem is that when I start the service I was getting the following error:
main process exited, code=exited, status=127/n/a
So, I tried to change the first line of the app.js file to the node's path instead of the word "node" #!/usr/bin/env /usr/local/lib/nodejs/node-v8.11.4/bin/node
and now it's running fine.
I guess the service is not reading the PATH variable and I need some help to realize why it doesn't.
(my PATH is right and when I run "type node" the result is OK).
root@bumer:~# type node
node is /usr/local/lib/nodejs/node-v8.11.4/bin/node
(I am logging the variable PORT which I set on ~/.bashrc on the app.js but it cannot read as well, it logs undefined
).
systemd path services node.js
I am trying to run a Node.js app as a service in Debian 9. So, following some tutorials, I've made a service like that.
[Unit]
Description=bumer API Http Server
[Service]
PIDFile=/tmp/bumer-service.pid
User=root
Group=root
Restart=always
KillSignal=SIGQUIT
WorkingDirectory=/root/bumer/
SyslogIdentifier=bumer
ExecStart=/root/bumer/app.js
[Install]
WantedBy=multi-user.target
My app has #!/usr/bin/env node
as its first line and it runs pretty well if I run the command /root/bumer/app.js
.
The problem is that when I start the service I was getting the following error:
main process exited, code=exited, status=127/n/a
So, I tried to change the first line of the app.js file to the node's path instead of the word "node" #!/usr/bin/env /usr/local/lib/nodejs/node-v8.11.4/bin/node
and now it's running fine.
I guess the service is not reading the PATH variable and I need some help to realize why it doesn't.
(my PATH is right and when I run "type node" the result is OK).
root@bumer:~# type node
node is /usr/local/lib/nodejs/node-v8.11.4/bin/node
(I am logging the variable PORT which I set on ~/.bashrc on the app.js but it cannot read as well, it logs undefined
).
systemd path services node.js
systemd path services node.js
asked Sep 25 at 15:16
Lionzinho
1
1
add a comment |Â
add a comment |Â
1 Answer
1
active
oldest
votes
up vote
2
down vote
Services do not run in login session contexts.
Your PATH
is not right, and the value of PATH
in a shell in a login session is completely irrelevant, as are your shell's startup scripts.
One of the features of service management systems (in general, not limited to systemd) is that they start all services based upon a single uniform environment, as modified only by elements of the service definition (whatever that is). It is nothing to do with how login shells set up user environments for login sessions. (Not, it is not root
's login session environment either.)
In systemd's case, your service definition is the service unit file, and unless you modify PATH
in that unit it will be whatever default value that all services are started with. In systemd's case, this is documented; and /usr/local/lib/nodejs/node-v8.11.4/bin/
is not on the list.
If you want PATH
to be something other than the all-serviecs default, you need to modify your service unit with Environment=
settings to change it.
Further reading
- Lennart Poettering et al. (2017). "Environment variables in spawned processes". systemd.exec. systemd manual pages. Freedesktop.org.
add a comment |Â
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
2
down vote
Services do not run in login session contexts.
Your PATH
is not right, and the value of PATH
in a shell in a login session is completely irrelevant, as are your shell's startup scripts.
One of the features of service management systems (in general, not limited to systemd) is that they start all services based upon a single uniform environment, as modified only by elements of the service definition (whatever that is). It is nothing to do with how login shells set up user environments for login sessions. (Not, it is not root
's login session environment either.)
In systemd's case, your service definition is the service unit file, and unless you modify PATH
in that unit it will be whatever default value that all services are started with. In systemd's case, this is documented; and /usr/local/lib/nodejs/node-v8.11.4/bin/
is not on the list.
If you want PATH
to be something other than the all-serviecs default, you need to modify your service unit with Environment=
settings to change it.
Further reading
- Lennart Poettering et al. (2017). "Environment variables in spawned processes". systemd.exec. systemd manual pages. Freedesktop.org.
add a comment |Â
up vote
2
down vote
Services do not run in login session contexts.
Your PATH
is not right, and the value of PATH
in a shell in a login session is completely irrelevant, as are your shell's startup scripts.
One of the features of service management systems (in general, not limited to systemd) is that they start all services based upon a single uniform environment, as modified only by elements of the service definition (whatever that is). It is nothing to do with how login shells set up user environments for login sessions. (Not, it is not root
's login session environment either.)
In systemd's case, your service definition is the service unit file, and unless you modify PATH
in that unit it will be whatever default value that all services are started with. In systemd's case, this is documented; and /usr/local/lib/nodejs/node-v8.11.4/bin/
is not on the list.
If you want PATH
to be something other than the all-serviecs default, you need to modify your service unit with Environment=
settings to change it.
Further reading
- Lennart Poettering et al. (2017). "Environment variables in spawned processes". systemd.exec. systemd manual pages. Freedesktop.org.
add a comment |Â
up vote
2
down vote
up vote
2
down vote
Services do not run in login session contexts.
Your PATH
is not right, and the value of PATH
in a shell in a login session is completely irrelevant, as are your shell's startup scripts.
One of the features of service management systems (in general, not limited to systemd) is that they start all services based upon a single uniform environment, as modified only by elements of the service definition (whatever that is). It is nothing to do with how login shells set up user environments for login sessions. (Not, it is not root
's login session environment either.)
In systemd's case, your service definition is the service unit file, and unless you modify PATH
in that unit it will be whatever default value that all services are started with. In systemd's case, this is documented; and /usr/local/lib/nodejs/node-v8.11.4/bin/
is not on the list.
If you want PATH
to be something other than the all-serviecs default, you need to modify your service unit with Environment=
settings to change it.
Further reading
- Lennart Poettering et al. (2017). "Environment variables in spawned processes". systemd.exec. systemd manual pages. Freedesktop.org.
Services do not run in login session contexts.
Your PATH
is not right, and the value of PATH
in a shell in a login session is completely irrelevant, as are your shell's startup scripts.
One of the features of service management systems (in general, not limited to systemd) is that they start all services based upon a single uniform environment, as modified only by elements of the service definition (whatever that is). It is nothing to do with how login shells set up user environments for login sessions. (Not, it is not root
's login session environment either.)
In systemd's case, your service definition is the service unit file, and unless you modify PATH
in that unit it will be whatever default value that all services are started with. In systemd's case, this is documented; and /usr/local/lib/nodejs/node-v8.11.4/bin/
is not on the list.
If you want PATH
to be something other than the all-serviecs default, you need to modify your service unit with Environment=
settings to change it.
Further reading
- Lennart Poettering et al. (2017). "Environment variables in spawned processes". systemd.exec. systemd manual pages. Freedesktop.org.
answered Sep 25 at 16:30
JdeBP
30k462137
30k462137
add a comment |Â
add a comment |Â
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f471359%2fsystemd-custom-service-doesnt-read-path%23new-answer', 'question_page');
);
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password