You are not logged in.

#1 2019-06-17 06:24:05

romzr
Member
Registered: 2019-06-17
Posts: 4

[SOLVED] PKGBUILD review request (beacon)

Hi,

I made a package for a tool that I wrote, named beacon.
It's a cross platform daemon that sends system metrics to one or more destinations: logs, cloudwatch, http.

There are 3 files:

$ cat PKGBUILD
# Maintainer: Romain Dura <romain "at" shazbits "dot" com>

pkgname=beacon
pkgver=1.1.0
pkgrel=1
pkgdesc='Tiny system utility reporting CPU, memory, uptime to logs, cloudwatch, http'
arch=('any')
url="https://github.com/shazbits/$pkgname"
license=('MIT')
makedepends=('go')
install=beacon.install
source=("$url/archive/v$pkgver.tar.gz"
        'beacon.service')
sha256sums=('ac309ac8419fe4ee02b204421a8462ce28308c77d9fc42358d2d94504176d1c1'
            'c1e33e6fbb2320fe0ea13e3ca95edbbf779686785a0f6304f32a49dbed97ed9f')

build() {
  cd $pkgname-$pkgver
  go build \
    -gcflags "all=-trimpath=$PWD" \
    -asmflags "all=-trimpath=$PWD" \
    -ldflags "-extldflags $LDFLAGS" \
    -o $pkgname .
}

package() {
  cd $pkgname-$pkgver
  install -Dm755 $pkgname "$pkgdir"/usr/bin/$pkgname
  install -Dm644 LICENSE "$pkgdir/usr/share/licenses/$pkgname/LICENSE"
  install -Dm644 config.yml.example "$pkgdir/etc/beacon/config.yml"
  install -Dm644 "$srcdir/beacon.service" "$pkgdir/etc/systemd/system/beacon.service"
}
$ cat beacon.install
post_install() {
  echo "The beacon service must be running for beacon to work."
  echo "Configure /etc/beacon/config.yml and execute 'sudo systemctl enable beacon' in a terminal."
}

post_upgrade() {
  post_install
}
$ cat beacon.service
[Unit]
Description=Beacon service
After=network.target
StartLimitIntervalSec=0

[Service]
Type=simple
Restart=always
RestartSec=1
User=root
ExecStart=/usr/bin/beacon

[Install]
WantedBy=multi-user.target

I ran namcap, and no warnings appeared.

I made the service run as root, but I wonder if there is a better (and simple) alternative. It doesn't actually require root permissions. I'm not sure if there is a recommended way to create a system user just to run the service.

Any feedback would be appreciated.
Thanks.

Last edited by romzr (2019-06-18 05:16:00)

Offline

#2 2019-06-17 08:04:06

ayekat
Member
Registered: 2011-01-17
Posts: 1,589

Re: [SOLVED] PKGBUILD review request (beacon)

The `arch` array should not be `any`, because the resulting package is architecture-specific (see https://wiki.archlinux.org/index.php/PKGBUILD#arch).
Also, /etc is reserved for the local sysadmin; whether packages should install any files in there is left for debate, but at least packaged systemd service files do not belong in there (they should go to /usr/lib/systemd instead).
I have no experience with Go packaging, so I can't quite comment on that, but otherwise it looks pretty clean to me.

Other than that, here are a few opinions from my side:

  • I don't think it's a good idea to have the service auto-restart in all cases; if the service fails, it likely needs some investigation by the sysadmin (rather than having it attempt and fail to start repeatedly).
    Also, there is no need to set `User=root` for a system service, as that is the default.

  • In post_install(), it would be cleaner to just tell the local sysadmin that beacon.service must be running; don't tell them to run specific commands, as you then start to assume things about their system.
    Also, there is no need to display that message at each upgrade. Personally, since the purpose of the tool seems pretty clear, I think I would even get rid of the messages altogether, but that's really just a personal opinion.

romzr wrote:

I made the service run as root, but I wonder if there is a better (and simple) alternative. It doesn't actually require root permissions. I'm not sure if there is a recommended way to create a system user just to run the service.

Yes, as it exposes a network user interface, having some limitations to what it can do if things go wrong is probably not a bad idea.

--edit: I misread that question. Yes, there is systemd-sysusers. Have a look at some of the files in /usr/lib/sysusers.d/ to get some examples. A simple example of using sysusers.d is probably mpd.

Last edited by ayekat (2019-06-17 08:12:46)


pkgshackscfgblag

Offline

#3 2019-06-17 12:20:46

Lone_Wolf
Member
From: Netherlands, Europe
Registered: 2005-10-04
Posts: 11,868

Re: [SOLVED] PKGBUILD review request (beacon)

echo "The beacon service must be running for beacon to work."
  echo "Configure /etc/beacon/config.yml and execute 'sudo systemctl enable beacon' in a terminal."

Does beacon work correctly when it's started manually or from a script ?
If so, just mention it needs to be started and will run in the background.


Disliking systemd intensely, but not satisfied with alternatives so focusing on taming systemd.


(A works at time B)  && (time C > time B ) ≠  (A works at time C)

Offline

#4 2019-06-18 04:33:59

romzr
Member
Registered: 2019-06-17
Posts: 4

Re: [SOLVED] PKGBUILD review request (beacon)

Thanks for the feedback.

I have:
* changed the arch to x84_64
* changed the service destination path to /usr/lib/systemd/system
* removed the post_upgrade prints (I was copying teamviewer)
* kept the post_install print but rephrased the message to avoid giving a specific command to run

I tried removing the User from the service but that did not work, so I guess that property is mandatory
    beacon.service ... FAILED
==> ERROR: One or more files did not pass the validity check!

And regarding running beacon from a script or manually, that works too, but the service makes it to auto start, get logs, restart if dead. It's optional, that is why it's not enabled by default.

Offline

#5 2019-06-18 05:15:22

romzr
Member
Registered: 2019-06-17
Posts: 4

Re: [SOLVED] PKGBUILD review request (beacon)

The package has been submitted
https://aur.archlinux.org/packages/beacon/

Offline

#6 2019-06-18 06:22:30

ayekat
Member
Registered: 2011-01-17
Posts: 1,589

Re: [SOLVED] PKGBUILD review request (beacon)

romzr wrote:

I tried removing the User from the service but that did not work, so I guess that property is mandatory
    beacon.service ... FAILED
==> ERROR: One or more files did not pass the validity check!

That is makepkg complaining. If you change the file, its checksum is going to be different, so you'll need to update the appropriate entry in the `sha256sums` array in the PKGBUILD as well.


pkgshackscfgblag

Offline

Board footer

Powered by FluxBB