I have a service implemented as a Bash script. Inside it's actually a node.js application, but it could be anything for the purposes of this question.
The basic use case is that we develop/debug the script in an interactive shell, then enable it as a service.
If I ssh to my device (logging in) my entire environment is there, and I can launch my script at the command line, no problem. The shell I'm in has picked up the right environment from
.profile, etc. and everything works.
But if I launch it from a systemd service, it
source the environment as it would for an interactive shell. There are provisions to add environment variables to the unit, but for what I'm doing here that just duplicates what my interactive environment does and becomes an easy way to forget something.
For a real production service I'm sure there's a Right Way of doing this, but this is a lab application and I need to make it easy so no one working on the script needs to know how systemd works.
So the question: What do I need to do to get a script written to run under an interactive Bash shell to run from systemd?
I have tried launching bash with
--login, but that doesn't work. Nor does explicitly doing a
source .bashrc in an outer script.
Here's an example I'm working with to highlight the problem:
core script (
#!/bin/bash cd while [ 1 ] do pwd echo USER is $USER echo PATH is $PATH which node node --version sleep 1 done
I call it from another script (
#!/bin/bash echo starting wrapper... bash --login /home/droid/job.sh
and here is my
job.service unit in
[Unit] Description=Job Daemon [Service] User=droid ExecStart=/home/droid/wrapper.sh [Install] WantedBy=multi-user.target
What do I not understand about systemd that prevents me from getting this to work?