Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FreeNAS (BSD) support #107

Closed
3 tasks
tprelog opened this issue Nov 18, 2018 · 6 comments
Closed
3 tasks

FreeNAS (BSD) support #107

tprelog opened this issue Nov 18, 2018 · 6 comments
Assignees
Milestone

Comments

@tprelog
Copy link

tprelog commented Nov 18, 2018

Put an x into all the boxes [ ] relevant to your issue (like this: [x])

What is the purpose of your issue?

  • Bug report (encountered problems with amazon-dash)
  • [ X ] Feature request (request for a new functionality)
  • [ X ] Question
  • Other
  • amazon-dash version: 1.3.1
  • Python version: 3.6.6
  • Pip & Setuptools version: 18.1
  • Operating System: FreeNAS 11.2
    • Using iocage jail to run amazon-dash
      • iocage jail OS: FreeBSD 11.2
  • [ X ] The pip install or setup install command has been completed without errors
  • The python -m amazon_dash.install command has been completed without errors
  • [ X ] The amazon-dash discovery command works without errors
  • [ X ] I have created/edited the configuration file
  • [ X ] Amazon-dash service or amazon-dash --debug run works

Description

Describe what you were trying to get done.
Tell us what happened, what went wrong, and what you expected to happen.

Create a FreeNAS plugin for amazon-dash

What I Did

pkg install python36
python3.6 -m ensurepip
pip install amazon-dash
cp /usr/local/lib/python3.6/site-packages/amazon_dash/install/amazon-dash.yml /root/amazon-dash.yml
amazon-dash run

Everything seems to be working fine

Paste the command(s) you ran and the output.
python3.6 -m amazon_dash.install
Executing all install scripts for Amazon-Dash
[OK] config has been installed successfully
ps: illegal option -- -
usage: ps [-aCcdefHhjlmrSTuvwXxZ] [-O fmt | -o fmt] [-G gid[,gid...]]
          [-J jid[,jid...]] [-M core] [-N system]
          [-p pid[,pid...]] [-t tty[,tty...]] [-U user[,user...]]
       ps [-L]
Traceback (most recent call last):
  File "/usr/local/lib/python3.6/runpy.py", line 193, in _run_module_as_main
    "__main__", mod_spec)
  File "/usr/local/lib/python3.6/runpy.py", line 85, in _run_code
    exec(code, run_globals)
  File "/usr/local/lib/python3.6/site-packages/amazon_dash/install/__main__.py", line 3, in <module>
    catch(cli)()
  File "/usr/local/lib/python3.6/site-packages/amazon_dash/install/__init__.py", line 47, in wrap
    return fn(*args, **kwargs)
  File "/usr/local/lib/python3.6/site-packages/click/core.py", line 764, in __call__
    return self.main(*args, **kwargs)
  File "/usr/local/lib/python3.6/site-packages/click/core.py", line 717, in main
    rv = self.invoke(ctx)
  File "/usr/local/lib/python3.6/site-packages/click/core.py", line 1137, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "/usr/local/lib/python3.6/site-packages/click/core.py", line 956, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/usr/local/lib/python3.6/site-packages/click/core.py", line 555, in invoke
    return callback(*args, **kwargs)
  File "/usr/local/lib/python3.6/site-packages/amazon_dash/install/__init__.py", line 152, in all
    has_service = has_service or (service().install() and
  File "/usr/local/lib/python3.6/site-packages/amazon_dash/install/__init__.py", line 71, in install
    self.is_installable()
  File "/usr/local/lib/python3.6/site-packages/amazon_dash/install/__init__.py", line 107, in is_installable
    if get_init_system() != 'systemd' or not get_systemd_services_path():
  File "/usr/local/lib/python3.6/site-packages/amazon_dash/install/__init__.py", line 30, in get_init_system
    return check_output(['ps', '--no-headers', '-o', 'comm', '1']).strip(b'\n ').decode('utf-8')
  File "/usr/local/lib/python3.6/subprocess.py", line 336, in check_output
    **kwargs).stdout
  File "/usr/local/lib/python3.6/subprocess.py", line 418, in run
    output=stdout, stderr=stderr)
subprocess.CalledProcessError: Command '['ps', '--no-headers', '-o', 'comm', '1']' returned non-zero exit status 1.


If there was a crash, please include the traceback here.

I wondering what the amazon_dash.install command does as amazon.dash seems to be working fine without it? It seems like it may just be coping the config file into place and checking for systemd.

@Nekmo
Copy link
Owner

Nekmo commented Nov 18, 2018

Yes, amazon_dash.install only installs the configuration file and the systemd service. You can ignore the error 👍 Probably ps is not available in freenas and that's why it gives this error.

@tprelog
Copy link
Author

tprelog commented Nov 18, 2018

Thank you! Actually ps is installed but it behaves differently than on Linux. Regardless, FreeNAS does not use systemd so if I can safely skip the python3.6 -m amazon_dash.install step and instead copy or create the amazon-dash.yml file AND providing my own start-up file then I'm already good go.

Thanks again for you work!

I'll post back soon with the complete steps to running on amazon-dash on FreeNAS as well as the start-up script I'm using

@Nekmo
Copy link
Owner

Nekmo commented Nov 18, 2018

Thanks to you for supporting Amazon-dash on FreeNAS :)

@tprelog
Copy link
Author

tprelog commented Nov 18, 2018

Creating an iocage-jail running Amazon-dash on FreeNAS 11.2

From the FreeNAS console ( I use ssh ) Create a new jail called amazon-dash: -n jail-name
sudo iocage create -r 11.2-RELEASE dhcp=on bpf=yes vnet=on boot=on -n amazon-dash

Enter the Amazon-dash jail-console and begin by installing the required packages
sudo iocage console amazon-dash
pkg update && pkg install python36 bash sudo

Next we need to set the locale. In my case it's en_US.UTF-8
setenv LANG en_US.UTF-8 && setenv LC_ALL en_US.UTF-8
And to make that persistent after reboot
printf "setenv LANG en_US.UTF-8\nsetenv LC_ALL en_US.UTF-8\n" >> /root/.cshrc

These commands will set-up pip and install amazon-dash
python3.6 -m ensurepip
pip3 install --upgrade pip
pip3 install amazon-dash

Next copy the sample amazon-dash.yml config file to /etc/
cp /usr/local/lib/python3.6/site-packages/amazon_dash/install/amazon-dash.yml /etc/

You should now be able to manually run Amazon-dash ( Ctrl+C to exit )
amazon-dash run --config /etc/amazon-dash.yml


There's no systemd, so instead the start-up script below can be used to run amazon-dash as a daemon.

Create directory and open new file in the editor.
mkdir /usr/local/etc/rc.d
ee /usr/local/etc/rc.d/amazon-dash

Copy/Paste the start-up script below
Press ESC then ENTER twice to exit and save

Make this file executable, enable the service and finally start amazon-dash as a daemon
chmod +x /usr/local/etc/rc.d/amazon-dash
sysrc amazondash_enable=YES
service amazon-dash start

service commands for amazon-dash
service amazon-dash [ start | stop | restart | status ]

start-up script below

#!/bin/sh
#
# PROVIDE: amazon-dash
# REQUIRE: LOGIN
# KEYWORD: shutdown
#
# amazondash_enable:	Set to YES to enable the amazon-dash service.
#			Default: NO
# amazondash_user:	The user account used to run the amazon-dash daemon.
#			This is optional, however do not specifically set this to an
#			empty string as this will cause the daemon to run as root.
#			Default: root
# amazondash_group:	The group account used to run the amazon-dash daemon.
#			This is optional, however do not specifically set this to an
#			empty string as this will cause the daemon to run with group wheel.
#			Default: wheel
# amazondash_conf:	Path to amazon-dash.yml
#			Default: /etc/amazon-dash.yml
#
. /etc/rc.subr
name=amazondash
rcvar=${name}_enable

pidfile_child="/var/run/${name}.pid"
pidfile="/var/run/${name}_daemon.pid"

load_rc_config ${name}
: ${amazondash_enable:="NO"}
: ${amazondash_user:="root"}
: ${amazondash_group:="wheel"}
: ${amazondash_config:="/etc/amazon-dash.yml"}

export LANG=en_US.UTF-8
export LC_ALL=en_US.UTF-8

command="/usr/sbin/daemon"

start_precmd=${name}_precmd
amazondash_precmd()
{
    rc_flags="-f -u ${amazondash_user} -P ${pidfile} -p ${pidfile_child} /usr/local/bin/amazon-dash run --config ${amazondash_config} ${rc_flags}"

    if [ ! -e "${pidfile_child}" ]; then
            install -g ${amazondash_group} -o ${amazondash_user} -- /dev/null "${pidfile_child}";
    fi

    if [ ! -e "${pidfile}" ]; then
            install -g ${amazondash_group} -o ${amazondash_user} -- /dev/null "${pidfile}";
    fi
}

stop_postcmd=${name}_postcmd
amazondash_postcmd()
{
    rm -f -- "${pidfile}"
    rm -f -- "${pidfile_child}"
}

run_rc_command "$1"

@tprelog
Copy link
Author

tprelog commented Nov 19, 2018

I've created a FreeNAS jail/plugin for Amazon Dash

How to Install

wget -O /tmp/amazon-dash.json https://raw.githubusercontent.com/tprelog/iocage-amazon-dash/master/amazon-dash.json
sudo iocage fetch -P dhcp=on vnet=on bpf=yes -n /tmp/amazon-dash.json --branch 'master'

@Nekmo
Copy link
Owner

Nekmo commented Dec 17, 2018

Thanks :) and sorry the wait to answer. I will add this to the documentation in the next release.

@Nekmo Nekmo self-assigned this Dec 17, 2018
Nekmo added a commit that referenced this issue Dec 17, 2018
@Nekmo Nekmo added this to the v1.3.2 milestone Jan 6, 2019
@Nekmo Nekmo closed this as completed Mar 20, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants