WelcomeWelcome | FAQFAQ | DownloadsDownloads | WikiWiki

Author Topic: programmatic reboot / shutdown  (Read 7480 times)

Offline LazyLarry

  • Newbie
  • *
  • Posts: 42
programmatic reboot / shutdown
« on: October 30, 2013, 01:51:37 PM »
I have a program originally written for ubuntu that is now running on TC. There is both a shutdown and a reboot button as part of the program. These dont seem to do anything in TC. They simply call
reboot(0x01234567) and reboot(0xcdef0123).
What do i need to do go be able to support these buttons?

Thanks in advance.

Offline bmarkus

  • Administrator
  • Hero Member
  • *****
  • Posts: 7183
    • My Community Forum
Re: programmatic reboot / shutdown
« Reply #1 on: October 30, 2013, 02:03:53 PM »
Are shutdown/reboot executed as root?
Béla
Ham Radio callsign: HA5DI

"Amateur Radio: The First Technology-Based Social Network."

Offline theYinYeti

  • Full Member
  • ***
  • Posts: 177
    • YetI web site
Re: programmatic reboot / shutdown
« Reply #2 on: October 31, 2013, 08:47:49 AM »
If it is not an option to prepend sudo to the commands you use, then create reboot and shutdown scripts in ~/.local/bin/ that will add the needed sudo, eg. for reboot:
Code: [Select]
#!/bin/sh
exec sudo reboot

Offline curaga

  • Administrator
  • Hero Member
  • *****
  • Posts: 11039
Re: programmatic reboot / shutdown
« Reply #3 on: October 31, 2013, 08:58:38 AM »
Tested, those system calls work fine on TC when run as root.
The only barriers that can stop you are the ones you create yourself.

Offline LazyLarry

  • Newbie
  • *
  • Posts: 42
Re: programmatic reboot / shutdown
« Reply #4 on: November 01, 2013, 08:46:37 AM »
OK, thanks for the feedback. I don't seem to be able to run the program from the command line. I can run it from the fluff browser, but when I go to the directory and type the filename I get a "not found" error. I have just copied this program into RAM from an external drive. Do I need to do something to TC to tell it there's a new program?
ALso, to run it as root, do I just stick sudo in front of the filename or do i need to do more.

Thanks,

Offline gerald_clark

  • TinyCore Moderator
  • Hero Member
  • *****
  • Posts: 4254
Re: programmatic reboot / shutdown
« Reply #5 on: November 01, 2013, 09:15:08 AM »
What do you mean "copied this program into RAM"?
Unless the program is in one of the directories in $PATH, you will need to provide a proper full or relative path to the executable.
Is it executable?

You can run 'hash -r' to refresh your program hash.

Offline LazyLarry

  • Newbie
  • *
  • Posts: 42
Re: programmatic reboot / shutdown
« Reply #6 on: November 01, 2013, 10:24:35 AM »
By copying into RAM i mean I have the executable on an external drive. I copy it into the /opt directory, which I assume is in RAM.

i actually can run it now, by specifying the full path. thanks for that tip. I thought If i was in the directory ( cd /opt) i could run it from the filename. I hadnt thought of using the full path.

However, I'm back to my original problem. I type "sudo /opt/filename" and the program runs, but my shutdown button only closes the app but doesn't do shutdown.

If it's any help, in the terminal window, when the program exits i get a message
init: must be run as PID 1

Offline coreplayer2

  • Hero Member
  • *****
  • Posts: 3020
Re: programmatic reboot / shutdown
« Reply #7 on: November 01, 2013, 10:42:24 AM »
/opt  is not in PATH

try
echo $PATH

Perhaps best to read the wiki on making Extensions, then create an extension which installs your app into /usr/local/bin
 

You might want to create a menu item also.  For this follow working desktop entry examples in /tmp/tcloop

good luck


though I'm not sure why you would reinvent the wheel when these features already exist

Offline Rich

  • Administrator
  • Hero Member
  • *****
  • Posts: 11570
Re: programmatic reboot / shutdown
« Reply #8 on: November 01, 2013, 10:58:20 AM »
Hi LazyLarry
Quote
... but when I go to the directory and type the filename I get a "not found" error.
If you are in the directory, you can execute the filename like this:
Code: [Select]
./FILENAME
Quote
... when the program exits i get a message init: must be run as PID 1
That sounds like you are not running as root. Did you try running it with  sudo ?

Offline LazyLarry

  • Newbie
  • *
  • Posts: 42
Re: programmatic reboot / shutdown
« Reply #9 on: November 06, 2013, 01:09:19 PM »
yes, i tried it as sudo, but no joy either