Error on "shutdown" task

Hello,

I created a “shutdown” task through “scheduled task” menu like following:

test

the task is returning this error when executing:

[27/Feb/2024 17:23:04] ERROR [storageadmin.util:45] Exception: Failed to shutdown the system due to a low level error: (Exception while running command(['/sbin/shutdown', '-h', 3]): expected str, bytes or os.PathLike object, not int).
Traceback (most recent call last):
  File "/opt/rockstor/src/rockstor/system/osi.py", line 236, in run_command
    p = subprocess.Popen(
        ^^^^^^^^^^^^^^^^^
  File "/usr/lib64/python3.11/subprocess.py", line 1026, in __init__
    self._execute_child(args, executable, preexec_fn, close_fds,
  File "/usr/lib64/python3.11/subprocess.py", line 1883, in _execute_child
    self.pid = _fork_exec(
               ^^^^^^^^^^^
TypeError: expected str, bytes or os.PathLike object, not int

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/opt/rockstor/src/rockstor/storageadmin/views/command.py", line 316, in post
    system_shutdown(delay)
  File "/opt/rockstor/src/rockstor/system/osi.py", line 1371, in system_shutdown
    o, e, rc = run_command(cmd)
               ^^^^^^^^^^^^^^^^
  File "/opt/rockstor/src/rockstor/system/osi.py", line 253, in run_command
    raise Exception("Exception while running command({}): {}".format(cmd, e))
Exception: Exception while running command(['/sbin/shutdown', '-h', 3]): expected str, bytes or os.PathLike object, not int

any help please?

Hello again @aymenSo. Curious, that this is failing, it seems that the shutdown parameters are not passed correctly. The coding in this area has not been touched for years, so I have no idea whether that has changed at some point recently (for the shell command), or none of our automated tests/testers have set up a shutdown task before.

The code ultimately attempts to execute the system command:

/sbin/shutdown -h 3

which comes from here:

causing the error.

According to the man page, the format of the delay should either be a “special case” like now, a specific time as hh:mm or a delay should be in the format of +m. As one can see from the code, the delay that’s defined (and subsequently passed) is only an integer number without the + sign in front (which would automatically type it as a string, I believe).

https://man7.org/linux/man-pages/man8/shutdown.8.html

This will then create a lower level exception in the osi.py and other python modules.
It probably needs to look like this instead:

/sbin/shutdown -h +3

I have created an issue on github for this:

Note, this problem will definitely exist in all 5.x release candidates, but likely also in the 4.x version (can’t test that right now).

2 Likes

If you can’t wait for the fix, you could try to change the delay variable above to +3 and see whether the task will execute correctly, but that’s only if you’re comfortable mucking about in your code.

1 Like

Hello @Hooverdan and thank you for the quick answer.

I changed the delay variable to +3 but still have the same error, I assume that the .py file should be compiled to take into account the modification but I don’t know how to do it.
I will wait for the fix :slight_smile:

1 Like

@Hooverdan & @aymenSo Re:

/sbin/shutdown -h 3
Shutdown scheduled for Thu 2024-03-21 18:20:31 WET, use 'shutdown -c' to cancel.

Does work just dandy as indicated above: but as @Hooverdan has discovered, and detailed, in the linked issue; we have a Python 2.7 ism still in play. Where our use now in testing channel of Py3.11 has surfaced a few remaining stragglers where we still fail to honour the new string type. I’ve begun to fix these straggler bugs against a related issue, so just wanted to note here that a fix should be in our next rpm release: assuming all things go according to plan :).

Hope that helps. And if you need a by-hand patch in the mean time: @Hooverdan has noted one in the linked issue.

2 Likes