According to the manual man systemd.service
using the prefix @
says this:
If the executable path is prefixed with "@", the second specified token will be passed as "argv[0]" to the executed process (instead of the actual filename), followed by the further arguments specified.
But when I run the service with a bash script or python script the filename or argv[0] has no effect. This only works when I use a program written in c language.
Inside my service I have:
[Unit]
Description=After service Number: 1
[Service]
Type=oneshot
ExecStart=@/home/edgar/bin/script "after-1-service" "1" "Args from after-service"
[Install]
WantedBy=multi-user.target
When I run this service using a c program the filename takes the value of "after-1-service" and the other arguments ("1","Args from after-service") are passed correctly as argv[1] and argv[2] respectively.
But when I run the service using a python or bash script the value of "after-1-service" has no effect and prints the main filename of the script and the arguments "1" and "Args from after-service" are passed correctly as argv[1] and argv[2] respectively.
In the case of python and bash script what is happening to the "after-1-service" argument? because if the filename or argv[0] is ignored I guess it should be passed the "after-1-service" as argv[1] and the other arguments should be paased as argv[2] and argv[3]
This is my code written in c
for printing the filename:
printf("Filename: %s\n",argv[0]);
This is my code written in python
:
print(f"Filename: {sys.argv[0]}")
And this is my code written in bash
:
echo Filename $0
I've tested those scripts using symbolic links and filename changes correctly, so I guess this only works for c programs or maybe it's a bug of systemd (version 251).