I am trying to build an application release by using Snapcraft.io, and I have almost all working.Snapcraft already compiles the source code, generates the .snap file, includes all the dependencies, and so on.However, I am stuck at how I can initialize some configuration files in the SNAP_USER_DATA folder after the first app install.I do not want to place the files in the default read-only path SNAP, as the default parameters should be modified by the user, also I need to generate some additional files, like server certificates.So I need to copy some files, and also run a script after the first install. Is this possible?
Thanks.
Because snaps are installed as root, it's impossible to do exactly as you ask at install time, as $SNAP_USER_DATA is user-specific, so it'll always be root's. However, you can do this at install-time using a system-wide directory, such as $SNAP_DATA, using the install hook:
$ snapcraft init
Created snap/snapcraft.yaml.
Edit the file to your liking or run `snapcraft` to get started
Create the hook. In our case we'll just create a new file in $SNAP_DATA, but you could do whatever you wanted.
$ mkdir -p snap/hooks
$ echo "touch \$SNAP_DATA/foo" >> snap/hooks/install
$ chmod a+x snap/hooks/install
Build the snap.
$ snapcraft
Preparing to pull my-part
Pulling my-part
Preparing to build my-part
Building my-part
Staging my-part
Priming my-part
Snapping 'my-snap-name' |
Snapped my-snap-name_0.1_amd64.snap
Install the snap. This will run the install hook.
$ sudo snap install my-snap-name_0.1_amd64.snap --devmode --dangerous
my-snap-name 0.1 installed
Notice a file was created in $SNAP_DATA.
$ ls /var/snap/my-snap-name/current
foo
The only way to get similar functionality for $SNAP_USER_DATA would be to wrap your real command in a script that creates the config. This command is then run by the user, which means you get the $SNAP_USER_DATA you intend. Of course, this isn't at install-time.
Related
I tried doing the following. First, I install a relocatable perl, e.g.:
% perlbrew -Duserelocatableinc -j4 -n --as perl-5.28.1-fresh_src 5.28.1
Then, whenever I need a new throw-away fresh installation of perl to test things out, I do:
% cp -la ~/perl5/perlbrew/perls/perl-5.28.1-fresh{_src,1}
% perlbrew switch 5.28.1-fresh1
(then would later create fresh2, fresh3 and so on as needed; and when I want to throw these away I just rm -rf ~/perl5/perlbrew/perls/*fresh1 and so on.)
However, something (cpanm? EUMM?) is still confused. Scripts installed from CPAN still has the original perl path (in this case, /home/USER/perl5/perlbrew/perls/perl-5.28.1-fresh_src/bin) in their shebang line.
Any hint to the problem above, or an alternative way to quickly create a fresh throw-away perl installation is appreciated. Also, would the -l (--link) option of cp in the above command cause issue (other than perllocal.pod being appended and will contain installation records of perl installations, which is fine for me)?
It's not quite the same, but I find docker works if I'm needing a clean install for certain testing scenarios - build up a base image and a clean perl install, fire up the container and run 'whatever'.
You'll need root access and be able to install packages (e.g. docker) so it's not going to be suitable for every use case.
https://buildlogs.centos.org/centos/7/docker/ has a base image you can use to build a 'clean' CentOS (or use whatever OS you prefer frankly - most have container versions)
FROM scratch
ADD CentOS-7-20140625-x86_64-docker_01.img.tar.xz
LABEL name="CentOS Base Image"
CMD ["/bin/bash"]
In the working directory:
docker build -t mycentos .
This will give you a very basic image:
Then your perl dockerfile:
FROM mycentos
COPY local.repo /etc/yum.repos.d/local.repo
RUN yum clean all
RUN yum install --nogpgcheck -y make gcc tar
ADD perl-5.28.1.tar.gz /build/
RUN cd /build/perl-5.28.1 && ./Configure -de
RUN cd /build/perl-5.28.1 && make && make test && make install
COPY MyConfig.pm /root/.cpan/CPAN/MyConfig.pm
RUN cpan install Bundle::CPAN
CMD ["/bin/bash"]
You'll be able to spin this up, with e.g. docker run and invoke a script using /usr/local/bin/perl.
It's not quite what you asked for, but your base image can be started and discarded as you wish - you can maintain image for a few different OS and perl combinations too.
I'm building an RPM that needs to run a number of scripts to configure it after it's been installed to complete the installation. I have to run the scripts in the %post section because the configuration is dependent upon the type of host. All this is fairly easy and well, but every time I run into a bug with the %post section, I have to rebuild the entire package which takes about 20 minutes. Is there a way to skip recompiling everything and just build a new package with just the changes from %post?
If your spec file doesn't create a random build directory and won't delete that build tree afterwards, the more time consuming compiling can be omitted by make. I.e. Similar to not using the --clean option in rpmbuild.
You can then also use the --short-circuit flag to rpmbuild to skip the first stages in building.
Is the script doing something different when run manually vs. run from the RPM install? You can make a test RPM that has no %post, then manually run the script under test (as root). Do this on every host type that needs to be tested until you think you got it. Then add it as the %post and give it a try.
I have a relatively big project that has many dependencies, and I would like to distribute this project around, but installing these dependencies where a bit of a pain, and takes a very long time (pip install takes quite some time). So I was wondering if it was possible to migrate a whole virtualenv to another machine and have it running.
I tried copying the whole virtualenv, but whenever I try running something, this virtualenv still uses the path of my old machine. For instance when I run
source activate
pserve development.ini
I get
bash: ../bin/pserve: /home/sshum/backend/bin/python: bad interpreter: No such file or directory
This is my old directory. So is there a way to have virtualenv reconfigure this path with a new path?
I tried sed -i 's/sshum/dev1/g' * in the bin directory and it solved that issue. However, I'm getting a different issue now, my guess is that this sed changed something.
I've confirmed that I have libssl-dev installed but when I run python I get:
E: Unable to locate package libssl.so.1.0.0
E: Couldn't find any package by regex 'libssl.so.1.0.0'
But when I run aptitude search libssl and I see:
i A libssl-dev - SSL development libraries, header files and documentation
I also tried virtualenv --relocatable backend but no go.
Export virtualenvironment
from within the virtual environment:
pip freeze > requirements.txt
as example, here is for myproject virtual environment:
once in the new machine & environment, copy the requirements.txt into the new project folder in the new machine and run the terminal command:
sudo pip install -r requirements.txt
then you should have all the packages previously available in the old virtual environment.
When you create a new virtualenv it is configured for the computer it is running on. I even think that it is configured for that specific directory it is created in. So I think you should always create a fresh virtualenv when you move you code. What might work is copying the lib/Pythonx.x/site-packages in your virtualenv directory, but I don't think that is a particularly good solution.
What may be a better solution is using the pip download cache. This will at least speed up the download part of pip install. Have a look at this thread: How do I install from a local cache with pip?
The clean way seems to be with virtualenv --relocatable.
Alternatively, you can do it manually by editing the VIRTUAL_ENV path in bin/activate to reflect the changes. If you choose to do so, you must also edit the first line (#) of bin/pserve which indicates the interpreter path.
I'd like to install a PHP extension on a bluehost shared site; specifically the MongoDB driver. Since pecl is unable to write to the primary server directory that has all the installed extensions, I'd like to install the mongo.so file to a directory I specify under my home. The closest article I found on the web was:
http://www.site5.com/blog/programming/php/how-to-setup-your-own-php-pear-environment/20090624/
However, after following the steps when I use the "pecl install mongo" command, it still keeps trying to install to bluehost's central directory on the server.
According to my web host's technical support team, utilising the pecl installer attempts to install the extension server-wide rather than under your account only. My web host doesn't allow server-wide installations in their shared environment for security reasons and because they want to keep their fleet universally the same across the board. I suspect your host is the same.
However, they did suggest I download, configure and install the pecl package (pecl_http) in my account only (rather than server-wide) via the following manual process:
$ cd ~/
$ wget http://pecl.php.net/get/pecl_http
$ tar -zxvf pecl_http.tar.gz
$ cd pecl_http
$ phpize
$ ./configure --prefix=~/bin
$ make
$ make test
$ make install
A successful install will have created extname.so and put it into the
PHP extensions directory. You'll need to edit php.ini (in my case,
this was a copy of the standard php.ini file that I placed in the same
folder as the script using the extension) and add an
extension=extname.so line (in my case, extension=http.so) before you can use the extension.
http://www.php.net/manual/en/install.pecl.phpize.php
Note that the tilde character (~) in the above code refers to the home directory of the current user (e.g. /home/username on my host's server).
Issues you may run into
When using the tar command, a "cannot open: not a directory" error
appeared as pecl_http had been downloaded without a file extension.
This was easily corrected:
mv pecl_http pecl_http.tar.gz
When using the make install command, a "cp: cannot create regular
file...: Permission denied" errror appeared. I resolved this issue
by changing the ext_dir for pecl...
pecl config-set ext_dir /home/username/bin/extensions
...and re-running make install. I also had to copy the http.so extension to /home/username/bin/extensions and then reference that location in my php.ini file:
extension_dir = "/home/username/bin/extensions"
this sounds like you don't have root access to your server. if your need to compile anything you must be have root access permission to server, or maybe you must be one of the sudoers.
I'm using Solaris 10, ksh. Whenever I do a ./configure, I get the error "ksh: ./configure: not found"
When I do a "where configure", nothing is found.
How do I "install configure"?
./configure means that you want to run an executable called configure in your current directory (signified by a .). I'm guessing you're trying to build and install from source, and the directions say to do the standard ./configure; make; make install. You should do that from the top-level directory of the source you downloaded and unpacked:
$ cd /path/to/source
$ ./configure
$ make
$ make install
"./configure" means "run the program configure from the current directory". That is, you need to cd to the directory that configure lives in before attempting to run it like that.
As for where configure might be found, it's usually at the root of whatever source package you're trying to build.
I'm not a Solaris guy, but the configure script should be within your current directory before you execute it. I am assuming you're trying to build something. If it's a project of your own, take a look at GNU autoconf. (I have no idea if this a part of Solaris or not.) It's part of M4.
If it's a project that you downloaded, untar/unzip/unpack it and then cd to its directory before running the configure script.
I had to run a command for another directory; and then that popped everything up :)
In case someone else comes across this specific issue, I'm trying to install the Perl-Php plugin on a Solaris machine. Initially, there is no configure file; instead you have to find where your "phpize" is located -- for me it was /opt/webstack/php/5.2/phpize, run it while you are still in the "perl-php-plugin" folder, and then configure will appear.
Then you can ./configure :)
Thanks to everyone who responded.