How to start a systemd service after user login and stop it before user logout

Use systemd it already includes support for user sessions, in fact you should already depend on it (unwittingly).

Create the service directory

mkdir -p $HOME/.local/share/systemd/user

Create edit a service file (vim, gedit, geany - whatever you want)

vim $HOME/.local/share/systemd/user/my.service

It should roughly look like this, if it's a permanent service.

[Unit]
Description=My very own Service
[Service]
Type=simple
TimeoutStartSec=0
ExecStart=/path/to/start/script arguments
[Install]
WantedBy=default.target

But it sounds like you rather want to trigger it once, then be good with it, so rather use a oneshot configuration like this:

[Service]
Type=oneshot
RemainAfterExit=true
StandardOutput=journal
ExecStart=/path/to/start/script arguments
ExecStop=/path/to/stop/script arguments
[Install]
WantedBy=default.target

This of course assumes that your script is executable, i.e.:

chmod a+x /path/to/start/script
chmod a+x /path/to/stop/script

Else you would need to prepend the path to the respective interpreter:

ExecStart=/bin/bash /path/to/start/script arguments

Now reload systemd (and re-login for the sake of testing)

systemctl --user enable my.service # enables the service
systemctl --user # should display your new unit in the list
journalctl --user should show the log

If you need more information refer to the Arch-Wiki for example. This askubuntu thread has various ideas, including incidentally, mine.

You can extend the behaviour (if you are root) to other users by defining the service globally. In order to do this you would need to create the service file in /usr/share/systemd/user/ not in $HOME/.local/share/systemd/user.