Last active
October 6, 2019 16:55
-
-
Save spajak/37bbf28c52f42406d2245c0a959074e4 to your computer and use it in GitHub Desktop.
My steps to enable systemd manager for any user (In this case www-data)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # Create user runtime directory | |
| sudo install -d -o www-data -g www-data -m 0700 /run/user/`id -u www-data` | |
| # Start user manager | |
| sudo systemctl start user@`id -u www-data` | |
| # Optionally enable lingering (User manager is spawned for the user at boot and kept around after logouts). | |
| sudo loginctl enable-linger www-data | |
| # Test it | |
| sudo -u www-data \ | |
| XDG_RUNTIME_DIR=/run/user/`id -u www-data` \ | |
| DBUS_SESSION_BUS_ADDRESS=unix:path=/run/user/`id -u www-data`/bus \ | |
| systemd-run --user echo "foo-`id -u`-bar" | |
| # See if it's working | |
| sudo systemctl status user@`id -u www-data` | |
| # If not working try restarting this services: | |
| sudo systemctl restart dbus.socket | |
| sudo systemctl restart dbus.service | |
| sudo systemctl restart user@`id -u www-data` |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # Bonus: php-fpm | |
| # If you want to be able execute a systemd task from a PHP script (using php-fpm) | |
| # do this: in systemd unit file (mine is /lib/systemd/system/php-fpm.service) add: | |
| [Service] | |
| ... | |
| EnvironmentFile=/usr/local/etc/php/environment | |
| # Create /usr/local/etc/php/environment with: | |
| XDG_RUNTIME_DIR=/run/user/33 | |
| DBUS_SESSION_BUS_ADDRESS=unix:path=/run/user/33/bus | |
| # Replace 33 with `id -u www-data` | |
| # Add this to /usr/local/etc/php/pool.d/www.conf near the end: | |
| env[XDG_RUNTIME_DIR] = $XDG_RUNTIME_DIR | |
| env[DBUS_SESSION_BUS_ADDRESS] = $DBUS_SESSION_BUS_ADDRESS | |
| # Restart PHP FPM | |
| sudo systemctl daemon-reload | |
| sudo systemctl restart php-fpm |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment