Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

systemd on Ubuntu 16.04 has wrong WorkingDirectory #63

Open
gavbaa opened this issue Jun 3, 2016 · 7 comments
Open

systemd on Ubuntu 16.04 has wrong WorkingDirectory #63

gavbaa opened this issue Jun 3, 2016 · 7 comments
Labels

Comments

@gavbaa
Copy link

gavbaa commented Jun 3, 2016

With current master, upon installing the service, I get a config file like the following:

[Unit]
Description=xxx
ConditionFileIsExecutable=/var/www/xxx/xxx

[Service]
StartLimitInterval=5
StartLimitBurst=10
ExecStart=/var/www/xxx/xxx
RootDirectory="/var/www/xxx"
WorkingDirectory="/var/www/xxx"



Restart=always
RestartSec=120

[Install]
WantedBy=multi-user.target

However, the application gets a working directory of / . syslog from the install shows:

Jun  3 20:59:18 xxx systemd[1]: Reloading.
Jun  3 20:59:18 xxx systemd[1]: [/etc/systemd/system/xxx.service:9] Not an absolute path, ignoring: "/var/www/xxx"
Jun  3 20:59:18 traininglocker systemd[1]: [/etc/systemd/system/xxx.service:10] Working directory path '"/var/www/xxx"' is not absolute, ignoring.
Jun  3 20:59:18 xxx systemd[1]: apt-daily.timer: Adding 10h 2min 11.830881s random time.
Jun  3 20:59:18 xxx systemd[1]: Reloading.
Jun  3 20:59:18 xxx systemd[1]: [/etc/systemd/system/xxx.service:9] Not an absolute path, ignoring: "/var/www/xxx"
Jun  3 20:59:18 xxx systemd[1]: [/etc/systemd/system/xxx.service:10] Working directory path '"/var/www/xxx"' is not absolute, ignoring.

When I removed the quotes around the WorkingDirectory item (but not RootDirectory), and ran systemctl daemon-reload, the service started as expected, with the correct working directory.

As a side note, if I removed quotes from the RootDirectory item, the service wouldn't start, it complained about the application name.

@corneldamian
Copy link

Had the same problem and i didn't had RootDirectory. Without RootDirectory i had the same problem with the working dir, even if i've removed the "

@kardianos kardianos added the bug label Sep 2, 2016
@kardianos
Copy link
Owner

Thanks for the report. I need to look into systemd unit files more, again.

@tsharma14
Copy link

Hi,
Can you please let me know the progress on this bug, as I am facing the same issue. I am setting some value in working directory alone but it is not reflecting. Can you please share the alternative way to set the PWD value in systemd service file.

Thanks

@kardianos
Copy link
Owner

I have not yet looked into this. Thanks for the ping. I'll research this later this week hopefully.

@tsharma14
Copy link

Can you please provide some alternative approach for this. As my service is not running properly due to this. I need to change the current working directory to some other dir in service file. which will enable my server to pick the correct path using PWD.

@dach384
Copy link

dach384 commented Jun 10, 2017

Any update on this?

@corford
Copy link

corford commented Jul 20, 2017

I don't know for RootDirectory but WorkingDirectory doesn't support double quotes (at least with the version of systemd that's present on Ubuntu 16.04). The solution is to escape the path with systemd-escape --path and prepend a leading '/' to the result.

WorkingDirectory="/var/path with spaces in it/bin" [ DOES NOT work ]

WorkingDirectory=/var-path\x20with\x20spaces\x20in\x20it-bin [ DOES work ]

More info here:
https://www.freedesktop.org/software/systemd/man/systemd-escape.html
https://serverfault.com/a/792831/173055
https://unix.stackexchange.com/a/242028

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

6 participants