You are not logged in.
Hello all,
A quick question that I cannot find an answer.
Can systemd be use to start a script upon a user login which will obviously be terminated whilst the user log out of power off the desktop? If yes, can a service also be launch at a specific user login?
Many thanks for your replies.
Offline
Yes in both cases. Please review the systemd user article in the wiki.
As described in the article, to launch a service for all users, put the .service file in /etc/systemd/user/; for a service specific to a single user the .service file should be placed in ~/.config/systemd/user/.
The service can then be enabled with systemctl --user enable sweetthedevils.service or so.
Regards,
Offline
to launch a service for all users, put the .service file in /etc/systemd/user/
Small clarification: this is not to launch (that's what enable/start does), but simply to make the .service file available to all users.
Offline
Right, the question was that systemd will automatically launch the script when the user login - sorry I didn't read the page yet.
Is that not the case?
Offline
Small clarification: this is not to launch (that's what enable/start does), but simply to make the .service file available to all users.
Sorry, should have proofed my answer. You're right of course.
systemd will automatically launch the script when the user login
It can do so on first login; I don't think it will do so if you're already logged in and start another session on the same machine.
Just create a .service file and enable it:
[Unit]
Description=Sweetthedevil Login Service
[Service]
ExecStart=/path/to/sweetthedevilscript.sh
[Install]
WantedBy=default.target
Drop in directory per above and enable. It will then run on next first login. I just tested this and it seems to work.
Offline
anks for the answer.
My goal was for the script - which is a repetitive loop willterminate if the user either log out or power off the computer. If it doesn't achieve the above is there a better way?
Offline
Providing you write the unit file correctly then yes.
All user services will be stopped when the user no longer has any active sessions (unless they have enabled lingering).
All of this is covered in the wiki and the systemd man pages.
Offline
sorry I didn't read the page yet.
So go read it. Do not expect to be spoon fed here. Everything you described indicates that a systemd user service is what you want.
"UNIX is simple and coherent..." - Dennis Ritchie, "GNU's Not UNIX" - Richard Stallman
Offline
Hello,
You are right - I mentioned it because I did not have time, not that I didn't want to. It does make absolutle sense now that I read it.
However, I have tried to run squid.service with systemd --user but I am running into rights issues.
Is it not possible to run service like squid (web proxy) through systemd/user?
Offline
Is it not possible to run service like squid (web proxy) through systemd/user?
It is possible, but you would have to create a service file yourself as the one provided is for running it as a system service.
Offline