aptly icon indicating copy to clipboard operation
aptly copied to clipboard

Include systemd unit file for Aptly API

Open kpostrup opened this issue 10 years ago • 11 comments

It would be nice if the Debian package for Aptly also included e.g. a systemd unit file for running the API as a service. Systemd would work on both Debian 8.x and Ubuntu 16.04 LTS.

This would include:

  • An aptly system user and group, e.g. homedir /var/lib/aptly
  • A systemd unit file, for starting $ aptly api serve with the correct user
  • Possibly combined with a config file (#423)

I would have made a patch myself, but I can't seem to find where in the source the Debian package is made.

kpostrup avatar Jul 12 '16 13:07 kpostrup

We used the following systemd service for starting aptly rest-api, note that there is probably a better way to stop the the service, I am open to your advices.

[Unit]
Description=Aptly REST API service

[Service]
User=aptly
WorkingDirectory=/var/lib/aptly
ExecStart=/usr/bin/aptly api serve -listen "localhost:8000" -no-lock
KillSignal=SIGTERM
KillMode=process
TimeoutStopSec=15s

[Install]
WantedBy=multi-user.target

erickeller avatar Aug 30 '16 15:08 erickeller

Apologies for not directly answering the original query, but I figured I'd add this for anyone searching the internet like I did myself and came across this post.

An alternative way to run API as a "service"

I ended up installing supervisor

apt-get install supervisor

made a config file /etc/supervisor/conf.d/aptlyapi.conf:

[program:aptlyapi]
command = aptly api serve
directory = /var/lib/aptly
user = aptly

Restart supervisor: service supervisor restart

confirm the api stops and starts with supervisorctl

supervisorctl status
supervisorctl stop aptlyapi
supervisorctl start aptlyapi
curl http:// <URL or IP> :8080/api/version

And view stdout and stderr logs:

tail /var/log/supervisor/*

Added benefits:

  • Starts at boot
  • Restarts if stops unexpectedly

I hope this helps any one out there looking for a very simple way to run the API as a service!

Inveracity avatar Sep 20 '16 09:09 Inveracity

Thirded (fourthed?) for requesting a systemd unit file. Currently debugging the aptly-api init file on Ubuntu 16.04 post-1.0 upgrade, and it is quite painful without a native systemd unit.

law avatar Mar 28 '17 10:03 law

For Debian official package, please refer to package maintainer if you want to add system unit file, for the aptly package from repo.aptly.info, it would be great if someone could submit PR, additional package files are added here: https://github.com/smira/aptly/blob/master/Makefile#L73 (root/ becomes / of .deb package)

smira avatar Mar 28 '17 13:03 smira

@smira just adding the service file is not enough we have to trigger and enable the systemd service, actually your aplty debian package does not contain any postinst/postrm script... It's kind of wired to not produce a native debian package from your code and hack our way around through this makefile.

@kpostrup I think that per default not every user want to have the rest-api started as a service when you install the aptly package. Therfore the only way is to create a meta package where you depend on the aptly from your Debian/Ubuntu distribution and implement this changes on your own.

erickeller avatar Mar 28 '17 15:03 erickeller

AFAIK it is considered bad practice to automatically enable and start services upon package installation. But there's no reason to omit a message telling the user how to do it though.

@smira I could take care of package building including a systemd unit file.

jola5 avatar Mar 28 '17 17:03 jola5

I still think it would be nice if Aptly included a systemd service manifest, for the restful API, but it could just be disabled by default, requiring the user to enable it.

@erickeller that is one way (and acceptable) to go about it. I will consider this for my internal use.

kpostrup avatar May 04 '17 14:05 kpostrup

Let's make a PR for systemd disabled by default then but keep it in mind that the debian maintainer ([email protected]) will have to package it.

Best Regards

On Thu, May 4, 2017 at 4:01 PM Kenneth Østrup [email protected] wrote:

I still think it would be nice if Aptly included a systemd service manifest, for the restful API, but it could just be disabled by default, requiring the user to enable it.

@erickeller https://github.com/erickeller that is one way (and acceptable) to go about it. I will consider this for my internal use.

— You are receiving this because you were mentioned.

Reply to this email directly, view it on GitHub https://github.com/smira/aptly/issues/425#issuecomment-299193856, or mute the thread https://github.com/notifications/unsubscribe-auth/ABOw0udNOtmGANi2X0q38i5HR-_HIHeiks5r2dpKgaJpZM4JKZ4Z .

erickeller avatar May 04 '17 16:05 erickeller

On May/04, Eric Keller wrote:

Let's make a PR for systemd disabled by default then but keep it in mind that the debian maintainer ([email protected]) will have to package it.

I can do that, no problem.

Cheers,

--Seb

erickeller avatar May 09 '17 08:05 erickeller

I'm all for including default configs in aptly repo if that is going to help us.

smira avatar May 10 '17 20:05 smira

See https://github.com/aptly-dev/aptly/discussions/1345, systemd service is now also provided as debian package (aptly-api).

neolynx avatar Sep 25 '24 18:09 neolynx