You are not logged in.

#1 2022-10-21 18:09:11

Morta
Member
Registered: 2019-07-07
Posts: 660

alpm-hook for ngnix-mainline and nginx-mainline-mod-dav-ext package

Hi

I need a aplm hook at every time who upgrades nginx-mainline it should rebuild the package nginx-mainline-mod-dav-ext from AUR
and restart nginx-mainline after rebuild nginx-mainline-mod-dav-ext.

How does it look the hook? I have no idea.


#Here should stay the right code....
[Trigger]
Operation = Install
Operation = Upgrade
Operation = Remove
Type = Package
Target = *
[Action]
Depends = coreutils
When = PostTransaction
Exec = /usr/bin/sync

Thx

Last edited by Morta (2022-10-21 18:09:45)

Offline

#2 2022-10-22 13:36:57

Morta
Member
Registered: 2019-07-07
Posts: 660

Re: alpm-hook for ngnix-mainline and nginx-mainline-mod-dav-ext package

[Trigger]
Operation = Upgrade
Type = Package
Target = nginx-mainline

[Action]
Description = Rebuild nginx-mainline-mod-dav-ext after upgrade nginx
When = PostTransaction
Depends = nginx-mainline
Exec = /usr/bin/yay -Syu nginx-mainline-mod-dav-ext

Is this correct?

Offline

#3 2022-10-22 13:38:49

Morta
Member
Registered: 2019-07-07
Posts: 660

Re: alpm-hook for ngnix-mainline and nginx-mainline-mod-dav-ext package

Could someone move the thread to forums pacman issues?

Offline

#4 2022-10-22 17:26:28

ewaller
Administrator
From: Pasadena, CA
Registered: 2009-07-13
Posts: 20,601

Re: alpm-hook for ngnix-mainline and nginx-mainline-mod-dav-ext package

Moved, by request.  In the future, please feel free to use the report link on the thread to make the request.  Moderators are notified of the request and we can respond immediately rather than having to stumble upon it.


Nothing is too wonderful to be true, if it be consistent with the laws of nature -- Michael Faraday
The shortest way to ruin a country is to give power to demagogues.— Dionysius of Halicarnassus
---
How to Ask Questions the Smart Way

Offline

#5 2022-10-24 10:57:14

Morta
Member
Registered: 2019-07-07
Posts: 660

Re: alpm-hook for ngnix-mainline and nginx-mainline-mod-dav-ext package

Thx for moving. How I can test if my hook works properly?

Offline

#6 2022-10-24 14:31:34

V1del
Forum Moderator
Registered: 2012-10-16
Posts: 25,076

Re: alpm-hook for ngnix-mainline and nginx-mainline-mod-dav-ext package

you should see the line "Rebuild nginx-mainline-mod-dav-ext after upgrade nginx" in the log/output on a relevant update.

Your hook will not work as is for a multitude of reasons, starting with the fact that you don't have an interactive prompt while running an interactive command, continuing with makepkg refusing to run as root but a hook will run as root and ending on the fact that I doubt it's a very good idea to start a new pacman transaction while one is in active progress.

It's not generally a good idea to try and install packages this way, I'd use the hook to e.g. create a file in the /tmp directory and then have a follow-up/alias that checks  whether such a file exists and on it's existence runs

yay -Sya nginx-mainline-mod-dav-ext --rebuild

as your normal user, e.g.

sudo pacman -Syu
[ -f /tmp/nginx_update ] && yay -Sya --rebuild nginx-mainline-mod-dav-ext && rm /tmp/nginx_update

Last edited by V1del (2022-10-24 15:22:11)

Offline

#7 2022-10-24 14:38:16

Morta
Member
Registered: 2019-07-07
Posts: 660

Re: alpm-hook for ngnix-mainline and nginx-mainline-mod-dav-ext package

V1del wrote:

you should see the line "Rebuild nginx-mainline-mod-dav-ext after upgrade nginx" in the log/output on a relevant update.

Your hook will not work as is for a multitude of reasons, starting with the fact that you don't have an interactive prompt while running an interactive command, continuing with makepkg refusing to run as root but a hook will run as root and ending on the fact that I doubt it's a very good idea to start a new pacman transaction while one is in active progress.

It's not generally a good idea to try and install packages this way, I'd use the hook to e.g. create a file in the /tmp directory and then have a follow-up/alias that checks  whether such a file exists and on it's existence runs

yay -Sya nginx-mainline-mod-dav-ext --rebuild

as your normal user, e.g.

sudo pacman -Syu
[ -f /tmp/nginx_update ] && yay -Sya --rebuild nginx-mainline-mod-dav-ext

How I can make a hook running as normal user?

I appreciate your inputs. 

Can you post a full example of a hook which is working like this?

Thx

Offline

#8 2022-10-24 15:22:36

V1del
Forum Moderator
Registered: 2012-10-16
Posts: 25,076

Re: alpm-hook for ngnix-mainline and nginx-mainline-mod-dav-ext package

You shouldn't manipulate the pacman database while a pacman database operation is in progress. Any hook that intends to install a package will fail by definition of what a hook is. So you need to separate the database operation (installing the package) from the trigger (identifying when to invoke the package installation). So you'd change the hook to simply create the trigger file e.g.

[Trigger]
Operation = Upgrade
Type = Package
Target = nginx-mainline

[Action]
Description = Rebuild nginx-mainline-mod-dav-ext after upgrade nginx
When = PostTransaction
Depends = nginx-mainline
Exec = /usr/bin/touch /tmp/nginx_update

and then run a script as I mentioned it from your normal user (see also my edit).

Last edited by V1del (2022-10-24 15:22:50)

Offline

#9 2022-10-24 16:16:35

Morta
Member
Registered: 2019-07-07
Posts: 660

Re: alpm-hook for ngnix-mainline and nginx-mainline-mod-dav-ext package

Ok thx.

My script looks like this

cat nginx-rebuild.sh 
#/bin/bash
sudo -u morta yay -Sya --rebuild nginx-mainline-mod-dav-ext --rebuild 
sudo pacman -Syu
[ -f /tmp/nginx_update ] && yay -Sya --rebuild nginx-mainline-mod-dav-ext

My problems:

- It's ask me if they should remove dependencies (Yes it should but I have to prompt)

- The hook will build the dir /tmp/nginx_update but ther is no pkg file which build by the script. Should not the hook also execute the script?

Last edited by Morta (2022-10-24 16:23:35)

Offline

#10 2022-11-01 03:42:41

cfr
Member
From: Cymru
Registered: 2011-11-27
Posts: 7,168

Re: alpm-hook for ngnix-mainline and nginx-mainline-mod-dav-ext package

Morta wrote:

- The hook will build the dir /tmp/nginx_update but ther is no pkg file which build by the script. Should not the hook also execute the script?

No, because you don't want this running while pacman is in the middle of an operation. That's why you want the hook just to create the trigger file in /tmp. You also don't want this running as root.

I've never used yay, but doesn't your script try to build the package twice, while updating packages from the official repos in between? You almost certainly shouldn't have/need sudo in this script. Don't you just want the final line?

You could use something to monitor for the trigger file and rebuild the package when it appears. You'd run that as an unprivileged user, so you wouldn't be trying to build anything as root. (Me, I'd run it as a user who wasn't in wheel, but you're using yay, so you presumably like to live dangerously.)


CLI Paste | How To Ask Questions

Arch Linux | x86_64 | GPT | EFI boot | refind | stub loader | systemd | LVM2 on LUKS
Lenovo x270 | Intel(R) Core(TM) i5-7200U CPU @ 2.50GHz | Intel Wireless 8265/8275 | US keyboard w/ Euro | 512G NVMe INTEL SSDPEKKF512G7L

Offline

#11 2022-11-01 18:28:13

Morta
Member
Registered: 2019-07-07
Posts: 660

Re: alpm-hook for ngnix-mainline and nginx-mainline-mod-dav-ext package

OK

1. I create the hook
2. I create a bash script /opt/nginx-rebuild.sh with following context

[ -f /tmp/nginx_update ] && yay -Sya --rebuild nginx-mainline-mod-dav-ext

3. sudo chmod a+x the script
4. Make a systemd service and timer which checks the script

[Unit]
Description=Rebuild nginx-mainline with DAV

[Service]
Restart=always
RestartSec=60s
ExecStart=/opt/nginx-rebuild.sh

[Install]
WantedBy=multi-user.target

Ok?

Thanks for reply and your inputs

Last edited by Morta (2022-11-01 18:30:27)

Offline

#12 2022-11-01 19:15:46

V1del
Forum Moderator
Registered: 2012-10-16
Posts: 25,076

Re: alpm-hook for ngnix-mainline and nginx-mainline-mod-dav-ext package

You'd want an user service if you intend for that approach: https://wiki.archlinux.org/title/Systemd/User

I'd personally make a wrapper script/alias around pacman where you pass all arguments to the script to pacman and then explicitly run yay after pacman completed, e.g.

#!/bin/bash
sudo pacman $@
[ -f /tmp/nginx_update ] && yay -Sya --rebuild nginx-mainline-mod-dav-ext && sudo rm /tmp/nginx_update

Last edited by V1del (2022-11-01 19:22:02)

Offline

#13 2022-11-01 20:42:07

Morta
Member
Registered: 2019-07-07
Posts: 660

Re: alpm-hook for ngnix-mainline and nginx-mainline-mod-dav-ext package

I edited the script like above

and added to nginx-rebuild.service following

[Unit]
Description=Rebuild nginx-mainline with WebDAV 

[Service]
Restart=always
RestartSec=60s
ExecStart=/opt/nginx-rebuild.sh
User=morta
Group=wheel

[Install]
WantedBy=multi-user.target

All ok?

Offline

#14 2022-11-01 20:50:47

V1del
Forum Moderator
Registered: 2012-10-16
Posts: 25,076

Re: alpm-hook for ngnix-mainline and nginx-mainline-mod-dav-ext package

Should work, try it out, there are some differences between an user service and a system service invoked with a specific user, but I'm assuming they might be of cosmetic nature in this particular case, I'd still rather do an user service which would be placing the service under /etc/systemd/user/ and dropping the explicit user like so

[Unit]
Description=Rebuild nginx-mainline with WebDAV 

[Service]
Restart=always
RestartSec=60s
ExecStart=/opt/nginx-rebuild.sh

[Install]
WantedBy=default.target

and doing

systemctl --user enable rebuldNginx.service --now

with your normal user ... You'd also have to run the yay command with --no-confirm if you want to do it that way.

Offline

#15 2022-11-01 21:02:52

Morta
Member
Registered: 2019-07-07
Posts: 660

Re: alpm-hook for ngnix-mainline and nginx-mainline-mod-dav-ext package

[Unit]
Description=Rebuild nginx-mainline with WebDAV 

[Service]
ExecStart=/opt/nginx-rebuild.sh

[Install]
WantedBy=default.target

I edited to this one

Offline

#16 2022-11-01 21:03:49

Morta
Member
Registered: 2019-07-07
Posts: 660

Re: alpm-hook for ngnix-mainline and nginx-mainline-mod-dav-ext package

[morta@5erver systemd]$ systemctl enable --user nginx-rebuild.service --now
Created symlink /home/morta/.config/systemd/user/default.target.wants/nginx-rebuild.service → /etc/xdg/systemd/user/nginx-rebuild.service.

Looks good...

Offline

#17 2022-11-01 23:25:29

cfr
Member
From: Cymru
Registered: 2011-11-27
Posts: 7,168

Re: alpm-hook for ngnix-mainline and nginx-mainline-mod-dav-ext package

V1del wrote:
#!/bin/bash
sudo pacman $@
[ -f /tmp/nginx_update ] && yay -Sya --rebuild nginx-mainline-mod-dav-ext && sudo rm /tmp/nginx_update

Would you mind explaining what the pacman line does when the script is invoked by the user service without arguments?

How does the service get permission for the sudo in this kind of case?


CLI Paste | How To Ask Questions

Arch Linux | x86_64 | GPT | EFI boot | refind | stub loader | systemd | LVM2 on LUKS
Lenovo x270 | Intel(R) Core(TM) i5-7200U CPU @ 2.50GHz | Intel Wireless 8265/8275 | US keyboard w/ Euro | 512G NVMe INTEL SSDPEKKF512G7L

Offline

#18 2022-11-02 09:01:18

V1del
Forum Moderator
Registered: 2012-10-16
Posts: 25,076

Re: alpm-hook for ngnix-mainline and nginx-mainline-mod-dav-ext package

That script isn't intended for a service but for running as a pacman wrapper in place of normal pacman, all behaviour and outputs will be the same as pacman, safe for the fact that it will automatically trigger a yay run after a temp file exists, and will also handle that the same way as if you'd normally run  yay.

I'm not a big fan of automatically doing installs/manipulations, this would give you the normal interactive approach while "remembering" to trigger a specific circumstancial rebuild.

Last edited by V1del (2022-11-02 09:03:33)

Offline

#19 2022-11-02 17:27:19

cfr
Member
From: Cymru
Registered: 2011-11-27
Posts: 7,168

Re: alpm-hook for ngnix-mainline and nginx-mainline-mod-dav-ext package

V1del wrote:

That script isn't intended for a service but for running as a pacman wrapper in place of normal pacman, all behaviour and outputs will be the same as pacman, safe for the fact that it will automatically trigger a yay run after a temp file exists, and will also handle that the same way as if you'd normally run  yay.

I'm not a big fan of automatically doing installs/manipulations, this would give you the normal interactive approach while "remembering" to trigger a specific circumstancial rebuild.

Thanks for that explanation. This thread had me rather confused.


CLI Paste | How To Ask Questions

Arch Linux | x86_64 | GPT | EFI boot | refind | stub loader | systemd | LVM2 on LUKS
Lenovo x270 | Intel(R) Core(TM) i5-7200U CPU @ 2.50GHz | Intel Wireless 8265/8275 | US keyboard w/ Euro | 512G NVMe INTEL SSDPEKKF512G7L

Offline

Board footer

Powered by FluxBB