What command does the UI use to shutdown freenas?

jaaassh

Dabbler
Joined
Apr 23, 2015
Messages
49
TLDR: How can I shutdown freenas from the command line the same way the UI does?

------------------

My BIOS is configured s.t. WOL works. If I plug in my machine, and send the packet, the system turns on.

The UPS service, by default, shuts freenas down with "shutdown -p now"
-- This command, powers off the motherboard entirely. So, nothing is listening for the WOL packet.

I tried "shutdown -h now"
-- This shuts lots of things down, but ultimately leaves "press any key to reboot" on the screen. So, as far as the BIOS is concerned, the system is still up I can't remotely reboot things.

Using the freenas UI to shutdown actually shuts things down AND leaves the system in a state that WOL works... but it's not clear what freenas is doing under the hood to trigger that shutdown?

I found this thing: https://github.com/freenas/freenas/blob/master/src/freenas/etc/ix.rc.d/ix-shutdown

...which seems a bit different on my installed system:

Code:
# cat /etc/ix.rc.d/ix-shutdown
#
# $FreeBSD$
#

# PROVIDE: ix-shutdown
# REQUIRE: LOGIN
# KEYWORD: shutdown

. /etc/rc.subr

execute_task()
{
    local stype=$1
    local f="ini_$stype"
    eval local $f
    local sf=$(var_to_sf $f)

    ${FREENAS_SQLITE_CMD} ${FREENAS_CONFIG} \
    "SELECT $sf FROM tasks_initshutdown WHERE ini_when = 'shutdown' AND ini_enabled = 1 AND ini_type = '$stype' ORDER BY id" | \
    while eval read -r $f; do
        if [ "${stype}" = "command" ]; then
            sh -c "${ini_command}" < /dev/null
        else
            if [ -e "${ini_script}" ]; then
                sh -c "exec ${ini_script}" < /dev/null
            fi
        fi
    done
}

do_shutdown()
{
    RO_FREENAS_CONFIG=$(ro_sqlite ${name} 2> /tmp/${name}.fail && rm /tmp/${name}.fail)
    trap 'rm -f ${RO_FREENAS_CONFIG}' EXIT

    /usr/local/bin/midclt call core.event_send system ADDED '{"id": "shutting-down"}' > /dev/null

    execute_task "command"
    execute_task "script"
}

name="ix-shutdown"
start_cmd=':'
stop_cmd='do_shutdown'

load_rc_config $name
run_rc_command "$1"


...and it doesn't seem to do much:
# /etc/ix.rc.d/ix-shutdown
Usage: /etc/ix.rc.d/ix-shutdown [fast|force|one|quiet](start|stop|restart|rcvar|enabled|describe|extracommands|status|poll)
# /etc/ix.rc.d/ix-shutdown stop
#

Am I on the right track?
 

sretalla

Powered by Neutrality
Moderator
Joined
Jan 1, 2016
Messages
9,703
Usage: /etc/ix.rc.d/ix-shutdown [fast|force|one|quiet](start|stop|restart|rcvar|enabled|describe|extracommands|status|poll)
# /etc/ix.rc.d/ix-shutdown stop
#

Am I on the right track?
I would read that as a service, so stopping it would do nothing.

Perhaps you can start with status, to see if it's even running.

If it's not, see what happens when you start it.
 

kingc

Dabbler
Joined
Jul 2, 2019
Messages
17
Just "poweroff", as per src/middlewared/middlewared/plugins/system.py

Code:
async def shutdown(self, job, options=None):
        """
        Shuts down the operating system.

        Emits an "added" event of name "system" and id "shutdown".
        """
        if options is None:
            options = {}

        self.middleware.send_event('system', 'ADDED', id='shutdown', fields={
            'description': 'System is going to shutdown',
        })

        delay = options.get('delay')
        if delay:
            await asyncio.sleep(delay)

        await Popen(['/sbin/poweroff'])
 

Patrick M. Hausen

Hall of Famer
Joined
Nov 25, 2013
Messages
7,776
shutdown -p now
 

xames

Patron
Joined
Jun 1, 2020
Messages
235
How i can do a scheduled freenas shutdown every night? Thanks.
 

Patrick M. Hausen

Hall of Famer
Joined
Nov 25, 2013
Messages
7,776
Tasks --> Cron Jobs
 

rmccullough

Patron
Joined
May 17, 2018
Messages
269
Why isn't the "Shutdown command" field of the UPS service configuration defaulted to "shutdown -p now"?
 
Top