Posts

Showing posts from March, 2016

Let systemd manage your running of unprivileged scripts

Image
Instructions
let's save a text file named "test.sh" having the following content


#! /bin/bash for i in `seq 50` do    echo $i    sleep 1 done

it just print number from 1 to 50 second by second (you can change 50 to any number) now as regular user type

chmod +x ./test.sh systemd-run --user --unit=my-test ./test.sh 
the above command will run the script as a user service called my-test
at any time you can trace it with systemctl and see the logs using journalctl like this

journalctl -ln 100 -f --user-unit=my-test systemctl --user status my-test
you can abort it using

systemctl --user stop my-test


Use cases
Let's assume you have a web interface that trigger something and you want to trace it later just make your unprivileged web application (written in php/python and running as regular non-root user) called "systemd-run --user" and query the status and follow the logs using systemctl and journactl
for example if you have a web interface that triggers building…