[systemd-devel] Service should run with a certain User?

Mirco Tischler mt-ml at gmx.de
Sat Apr 23 02:06:30 PDT 2011


Hi
2011/4/23 Baldur <baldur at email.de>:
> Hi,
>
> I am embarrassed to answer myself after hitting the send button.
> Of course i should not have put "test.sh" in /root , because the
> user has no rights to access it...
>
> It works now - but now the stopping the service seems a problem.
> It always goes to failed because the java vm seems to provide  a status=143
> Loaded: loaded (/lib/systemd/system/cruisctl.service)
>           Active: failed
>          Process: 4811 ExecStart=/usr/bin/java $CRUISCTLOPTIONS
> (code=exited, status=143)
>           CGroup: name=systemd:/system/cruisctl.service
>
>
> Regards  (and hoping that the solution will also come to me when i hit the
> send button)

The cleanest solution would of cause be to make the jvm exit with 0.
But if that is
not possible you can prefix the ExecStart path with a minus
(ExecStart=-/usr/bin/java...).
This way the exit status is ignored and the service should end up with
status exited.

> Here is the working script:
>
> #
> # Install
> # in directory /lib/systemd/system
>
> [Unit]
> Description=Cruise Control
> After=local-fs.target network.target
>
> [Service]
> Type=simple

Note that you don't need this line as simple is the default type

> EnvironmentFile=/etc/sysconfig/cruisctl
> User=cruisctl
> WorkingDirectory=/var/cruisecontrol
> ExecStart=/usr/bin/java $CRUISCTLOPTIONS
> #ExecStart=/tmp/test.sh $CRUISCTLOPTIONS
>
>
>
> [Install]
> WantedBy=multi-user.target

Mirco


More information about the systemd-devel mailing list