In systemd units file, I have a Environment which content is key=IamValue=abc, as you can see the value is IamValue=abc which contains =.
For this situation, how can I write the unit files?
I have tried as following, but it seems invalid:
[Unit]
Description=...
[Service]
WorkingDirectory=...
ExecStart=...
Restart=always
RestartSec=10                                          
SyslogIdentifier=...
User=root
Environment=key="IamValue=abc"
                If your service is running, you can use systemctl status <name>. service to identify the PID(s) of the service process(es), and then use sudo strings /proc/<PID>/environ to look at the actual environment of the process.
Systemd Files and Paths Unit files are stored in the /usr/lib/systemd directory and its subdirectories, while the /etc/systemd/ directory and its subdirectories contain symbolic links to the unit files necessary to the local configuration of the host. We recommend putting your scripts in /etc/systemd/system .
Description. The /etc/environment file contains variables specifying the basic environment for all processes. When a new process begins, the exec subroutine makes an array of strings available that have the form Name=Value. This array of strings is called the environment.
I tested that this works in a test.service file:
[Unit]
Description=Hi
[Service]
Type=oneshot
Environment=key="IamValue=abc"
ExecStart=/bin/bash -c "/bin/echo key:$key"
If you run that and then do journalctl -u test, you can see the key containing the equal sign works.
I've proposed an update to the official systemd docs to better clarify this case.
Alternatively use EnvironmentFile, config line in unit file:
EnvironmentFile=-/etc/sysconfig/test
With content in /etc/sysconfig/test:
key="IamValue=abc"
                        If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With