Re: Recommended ways of installing configuration files in SNAP_USER_DATA?

2016-12-13 Thread Jacek Nykis
On 13/12/16 09:42, Stuart Bishop wrote:
>> I might be one step close to getting this to work but I was wondering what
>> is the common/recommended practice to do what I’m trying to achieve here?
> 
> 
> I used the same approach you did, and got it building locally and working (
> https://code.launchpad.net/~stub/+git/pgbouncer-snap/+ref/master , please
> steal freely if there is anything useful there ). I haven't published it
> anywhere because I thought there was a reasonable chance you would be
> looking at it :) Also, I'm holding out hope that we can run non-root
> daemons sooner rather than later since pgbouncer is another app that
> refuses to run as root. I wasn't looking forward to documenting how to
> manually install systemd service definitions :)

I also had similar problem and had to write small wrapper. If you want
one more example to look at you can find source code here:

https://git.launchpad.net/prometheus-pushgateway-snap/tree/

There is an enhancement request in launchpad where we asked for a
standard way to deploy initial config files without need for every snap
to ship with custom wrappers:

https://bugs.launchpad.net/snappy/+bug/1611287

If that would help you you can mark the bug as affecting you to let
developers know.

Regards,
Jacek Nykis




signature.asc
Description: OpenPGP digital signature
-- 
Snapcraft mailing list
Snapcraft@lists.snapcraft.io
Modify settings or unsubscribe at: 
https://lists.ubuntu.com/mailman/listinfo/snapcraft


Re: Recommended ways of installing configuration files in SNAP_USER_DATA?

2016-12-13 Thread Stuart Bishop
On 13 December 2016 at 02:27, Ivan Lezhnjov IV 
wrote:

> Hi,
>
> I’m working on pgbouncer snap package and as I’m new to snaps I wanted to
> ask the community what is the current preferred way to install a program’s
> configuration files that are meant to be edited by users?
>
> For example, pgbouncer has a couple of files: pgbouncer.ini and
> userlist.txt. Both normally located under /etc/pgbouncer.
>
> As users need to be able to modify various settings in pgbouncer.ini it
> has to be under $SNAP_USER_DATA/etc/pgbouncer/.
>
> I use a standalone wrapper script that initializes some filesystem paths,
> creates empty log files, etc. which is all required by pgbouncer and is
> never created by the program itself, where I essentially do this:
>
> [ -e "$CNF_DIR/pgbouncer.ini" ] || cp $SNAP/etc/pgbouncer/pgbouncer.ini
> $CNF_DIR/pgbouncer.ini
>
> As you can see I first dump pgbouncer.ini to $SNAP/etc/pgbouncer/ and then
> attempt to copy it to $CNF_DIR, which expands to
> $SNAP_USER_DATA/etc/pgbouncer.
>
> However, this doesn’t work as $SNAP/etc/pgbouncer/pgbouncer.ini is owned
> by root and when the wrapper script is run as a normal user it cannot read
> the $SNAP/etc/pgbouncer/pgbouncer.ini file (permission denied).
>

I think the only problem here is that $SNAP/etc/pgbouncer/pgbouncer.ini was
not world readable when snapped. Maybe a umask issue, or you need to
explicitly set the permissions on this template file.




> I might be one step close to getting this to work but I was wondering what
> is the common/recommended practice to do what I’m trying to achieve here?


I used the same approach you did, and got it building locally and working (
https://code.launchpad.net/~stub/+git/pgbouncer-snap/+ref/master , please
steal freely if there is anything useful there ). I haven't published it
anywhere because I thought there was a reasonable chance you would be
looking at it :) Also, I'm holding out hope that we can run non-root
daemons sooner rather than later since pgbouncer is another app that
refuses to run as root. I wasn't looking forward to documenting how to
manually install systemd service definitions :)



-- 
Stuart Bishop 
-- 
Snapcraft mailing list
Snapcraft@lists.snapcraft.io
Modify settings or unsubscribe at: 
https://lists.ubuntu.com/mailman/listinfo/snapcraft


Re: Recommended ways of installing configuration files in SNAP_USER_DATA?

2016-12-12 Thread Michael Hall
I've used the same wrapper script configuration[1] as you're doing. If
you make pgbouncer a daemon it will be run as root, so the wrapper will
be able to create the config files without a problem. You should use
$SNAP_DATA rather than $SNAP_USER_DATA for this.

Coming soon (in snapd 2.18 I think) you will also be able to use the
'configure' hook, which will be called on install and update of a snap.
But for now the wrapper you have, plus making it a daemon, should do the
trick.

[1] https://github.com/apache/couchdb/blob/master/configure#L199

Michael Hall
mhall...@gmail.com

On 12/12/2016 02:27 PM, Ivan Lezhnjov IV wrote:
> Hi,
> 
> I’m working on pgbouncer snap package and as I’m new to snaps I wanted to ask 
> the community what is the current preferred way to install a program’s 
> configuration files that are meant to be edited by users?
> 
> For example, pgbouncer has a couple of files: pgbouncer.ini and userlist.txt. 
> Both normally located under /etc/pgbouncer. 
> 
> As users need to be able to modify various settings in pgbouncer.ini it has 
> to be under $SNAP_USER_DATA/etc/pgbouncer/.
> 
> I use a standalone wrapper script that initializes some filesystem paths, 
> creates empty log files, etc. which is all required by pgbouncer and is never 
> created by the program itself, where I essentially do this:
> 
> [ -e "$CNF_DIR/pgbouncer.ini" ] || cp $SNAP/etc/pgbouncer/pgbouncer.ini 
> $CNF_DIR/pgbouncer.ini
> 
> As you can see I first dump pgbouncer.ini to $SNAP/etc/pgbouncer/ and then 
> attempt to copy it to $CNF_DIR, which expands to 
> $SNAP_USER_DATA/etc/pgbouncer.
> 
> However, this doesn’t work as $SNAP/etc/pgbouncer/pgbouncer.ini is owned by 
> root and when the wrapper script is run as a normal user it cannot read the 
> $SNAP/etc/pgbouncer/pgbouncer.ini file (permission denied). 
> 
> I might be one step close to getting this to work but I was wondering what is 
> the common/recommended practice to do what I’m trying to achieve here?
> 
> Ivan
> 

-- 
Snapcraft mailing list
Snapcraft@lists.snapcraft.io
Modify settings or unsubscribe at: 
https://lists.ubuntu.com/mailman/listinfo/snapcraft


Re: Recommended ways of installing configuration files in SNAP_USER_DATA?

2016-12-12 Thread Michael Hall
I've used the same wrapper script configuration[1] as you're doing. If
you make pgbouncer a daemon it will be run as root, so the wrapper will
be able to create the config files without a problem. You should use
$SNAP_DATA rather than $SNAP_USER_DATA for this.

Coming soon (in snapd 2.18 I think) you will also be able to use the
'configure' hook, which will be called on install and update of a snap.
But for now the wrapper you have, plus making it a daemon, should do the
trick.

[1] https://github.com/apache/couchdb/blob/master/configure#L199

Michael Hall
mhall...@ubuntu.com

On 12/12/2016 02:27 PM, Ivan Lezhnjov IV wrote:
> Hi,
> 
> I’m working on pgbouncer snap package and as I’m new to snaps I wanted to ask 
> the community what is the current preferred way to install a program’s 
> configuration files that are meant to be edited by users?
> 
> For example, pgbouncer has a couple of files: pgbouncer.ini and userlist.txt. 
> Both normally located under /etc/pgbouncer. 
> 
> As users need to be able to modify various settings in pgbouncer.ini it has 
> to be under $SNAP_USER_DATA/etc/pgbouncer/.
> 
> I use a standalone wrapper script that initializes some filesystem paths, 
> creates empty log files, etc. which is all required by pgbouncer and is never 
> created by the program itself, where I essentially do this:
> 
> [ -e "$CNF_DIR/pgbouncer.ini" ] || cp $SNAP/etc/pgbouncer/pgbouncer.ini 
> $CNF_DIR/pgbouncer.ini
> 
> As you can see I first dump pgbouncer.ini to $SNAP/etc/pgbouncer/ and then 
> attempt to copy it to $CNF_DIR, which expands to 
> $SNAP_USER_DATA/etc/pgbouncer.
> 
> However, this doesn’t work as $SNAP/etc/pgbouncer/pgbouncer.ini is owned by 
> root and when the wrapper script is run as a normal user it cannot read the 
> $SNAP/etc/pgbouncer/pgbouncer.ini file (permission denied). 
> 
> I might be one step close to getting this to work but I was wondering what is 
> the common/recommended practice to do what I’m trying to achieve here?
> 
> Ivan
> 

-- 
Snapcraft mailing list
Snapcraft@lists.snapcraft.io
Modify settings or unsubscribe at: 
https://lists.ubuntu.com/mailman/listinfo/snapcraft


Recommended ways of installing configuration files in SNAP_USER_DATA?

2016-12-12 Thread Ivan Lezhnjov IV
Hi,

I’m working on pgbouncer snap package and as I’m new to snaps I wanted to ask 
the community what is the current preferred way to install a program’s 
configuration files that are meant to be edited by users?

For example, pgbouncer has a couple of files: pgbouncer.ini and userlist.txt. 
Both normally located under /etc/pgbouncer. 

As users need to be able to modify various settings in pgbouncer.ini it has to 
be under $SNAP_USER_DATA/etc/pgbouncer/.

I use a standalone wrapper script that initializes some filesystem paths, 
creates empty log files, etc. which is all required by pgbouncer and is never 
created by the program itself, where I essentially do this:

[ -e "$CNF_DIR/pgbouncer.ini" ] || cp $SNAP/etc/pgbouncer/pgbouncer.ini 
$CNF_DIR/pgbouncer.ini

As you can see I first dump pgbouncer.ini to $SNAP/etc/pgbouncer/ and then 
attempt to copy it to $CNF_DIR, which expands to $SNAP_USER_DATA/etc/pgbouncer.

However, this doesn’t work as $SNAP/etc/pgbouncer/pgbouncer.ini is owned by 
root and when the wrapper script is run as a normal user it cannot read the 
$SNAP/etc/pgbouncer/pgbouncer.ini file (permission denied). 

I might be one step close to getting this to work but I was wondering what is 
the common/recommended practice to do what I’m trying to achieve here?

Ivan
-- 
Snapcraft mailing list
Snapcraft@lists.snapcraft.io
Modify settings or unsubscribe at: 
https://lists.ubuntu.com/mailman/listinfo/snapcraft