[arch-general] systemd user unit files from custom directory

Andre "Osku" Schmidt andre.osku.schmidt at gmail.com
Sat Jan 30 13:29:23 UTC 2016


On Sat, Jan 30, 2016 at 2:22 PM, Andre "Osku" Schmidt
<andre.osku.schmidt at gmail.com> wrote:
> On Sat, Jan 30, 2016 at 1:41 PM, Damjan Georgievski <gdamjan at gmail.com> wrote:
>> On 30 January 2016 at 12:48, Andre "Osku" Schmidt
>> <andre.osku.schmidt at gmail.com> wrote:
>>> hello,
>>>
>>> thought i'd ask here first, in case it's a distro problem.
>>>
>>> was wondering if we can use systemd to start and stop a daemon for
>>> testing purposes during development. meaning, i would like to not have
>>> to "install" my daemon nor its systemd service file, and instead run
>>> all from the working directory.
>>>
>>> from systemd.unit man page i got the impression that this example would work:
>>>
>>> ❱ tree $PWD
>>> /data/projects/hmm
>>> └── systemd
>>>     └── user
>>>         └── foobar.service
>>>
>>> ❱ cat systemd/user/foobar.service
>>> [Unit]
>>> Description=Foo Bar
>>> [Service]
>>> ExecStart=/usr/bin/sleep 42
>>>
>>> ❱ XDG_CONFIG_HOME=$PWD systemctl --user start foobar
>>> Failed to start foobar.service: Unit foobar.service failed to load: No
>>> such file or directory.
>>>
>>> am i doing it wrong, or?
>>
>> the daemon reads and starts the service not systemctl.
>> in recent versions of systemd you can symlink the service file from
>> ouside ~/.config/systemd/ too
>>
>> ps.
>> what exactly are you testing? there's also systemd-run
>>
>>
>> --
>> damjan
>
> awesome,
>
> didn't know about systemd-run, seems perfect for my use-case, thank
> you for the tip!
>
> Cheers
> Andre Schmidt
>
> ps. FWIW, during development of my daemon (a "webapp"/server) i want
> to start the daemon, run (functional) tests, and stop the daemon, all
> without needing to "install" anything.

pps. works perfectly, in npm package.json:
...
"scripts": {
  "start": "systemd-run --user --unit=foobar-test ./server",
  "stop": "systemctl --user stop foobar-test",
  "test": "npm start && ./node_modules/.bin/mocha && npm stop"
}
...


More information about the arch-general mailing list