Run scripts in Systemd

Also i have a question on referencing files such as bash files
when i use %S/bin/test.sh i get an error of file not found or executable yet i had made chmod +x test.sh

is there a proper way to reference files

I noticed SELinux prevents Systemd from running commands from directories other than /usr/bin or similar.

As your command is a shell script run it like /bin/bash test.sh.

1 Like

Okay
here is an example of a docker compose service

So first we create a bash file inside bin configurator and put the contents below

after that we create a service to handle and run the configurator

when i run this i get the error file does not exist or is not executable

So should i use %S/bin/filename or filename

I think the issue is behind trying to execute %S/bin/configurator inside the container, which is exactly what is being asked, but there’s no %S/bin/configurator inside the container, it’s only outside in the module, so the container cannot access it.

You can, however, from reading in the documentation of the image you’re using, that you’ll better off setting the variables with the -e append with the named variable of your choice.

So, the changes needed are the following:

  1. remove the --entrypoint '["bash", "-c"] \, it’s not needed, configurator will run
  2. set every variable you need with set-config using -e, for example: bench set-config -g db_host $$DB_HOST becomes -e DB_HOST=<yourvaluehere>
  3. Remove the command %S/bin/configurator after the image variable

After this it might run, however I have no knowledge of this containerized environment and haven’t tested it myself :frowning_face:

2 Likes

So actually if i remove the %S/bin/configurator it will run the default entry point.
So for us we need first to set the configure the site using the script file configurator so as the application to work

For this service it runs well
since we are able to run the command inside the container

Sure, however configurator can and will pick up the environment variables as per doc given by frappe: frappe_docker/docs/environment-variables.md at main · frappe/frappe_docker · GitHub, maybe the issue is that they’re using the same image for multiple runtimes, if that’s so you can just --entrypoint '["bash", "-c", "exit", "0"] \ and it should load the environment. But something else appears to be going on behind the curtains :thinking: (I see a gunicorn command and a ton of parameters)

Yes, this is because the executable node is inside the container $PATH and the file /home/frappe/frappe-bench/apps/frappe/socketio.js exists within the container (it’s mounted using the the volumes -v)

However there’s no file such as /bin/configurator inside the container, you can mount it using -v %S/bin/configurator:/bin/configurator:Z and then write something like ${ERPNET_IMAGE} /bin/configurator at the end of ExecStart

I don’t suggest it however, containers should be responsible for their own configuration, if not given they should be self sufficient (exiting or generating one or picking data from env)

2 Likes

Okay i think this is a nice way
let ne try then give you a response on how it will be

Now this is working thank you