openhab / openhab-linuxpkg

Repo for Linux packages
Eclipse Public License 2.0
18 stars 33 forks source link

Add /usr/bin/openhab #77

Closed BClark09 closed 6 years ago

BClark09 commented 6 years ago

There should be a set of openhab commands that are easy to use and fairly self explanatory. Ones I can think of:

Usage:  openhab command [options]

Possible commands:
  start                          -- Starts openHAB as a daemon service.
  stop                           -- Stops an existing openHAB daemon service.
  restart                        -- Stops then starts an openHAB daemon service.
  status                         -- Checks to see if openHAB is running or prints systemctl status.
  console                        -- Opens the openHAB console.
  backup [filename]              -- Stores the current configuration of openHAB.
  restore filename               -- Restores the state of openHAB to a backup.
  showlogs [-l lines] ] [--tail] -- Displays the last log messages of openHAB.

@ThomDietrich, think of any more?

ThomDietrich commented 6 years ago

Ah you are thinking about a separate script for this?

In openHABian there are a few aliases for these kinds of things but I never extended or promoted them much... I like the idea to combine everything into one handy (documented) command. I'm undecided if another "onion layer" is beneficial...

Edit: on second thought, we can unify everything for all (incl. newbie) users and systems. The experienced user will know what's going on behind the command. So, no concern on my side.

As for the list of commands: Looks complete to me. Will also integrate nicely in openHABian. Any help needed?

Be aware, that some of these commands need root, while others don't. A symlink to /usr/sbin seems to be common.

BClark09 commented 6 years ago

A symlink to /usr/sbin seems to be common.

image

image

Any resources you have on this? All I could find was a general agreement that scripts that need root access should go in /usr/sbin only. Is there any reason to have them in both?

ThomDietrich commented 6 years ago

spidey-meme

Nevermind. 😛

BClark09 commented 6 years ago

Haha!

Since we're doing this, should a man entry be necessary? I'd have no idea how to integrate it though.

ThomDietrich commented 6 years ago

Doesn't hurt but I'd say it's not needed. Maybe at a later point.

You've changed the issue name to sbin. That's not what I wanted to suggest. The script can reside in bin, it already has its internal root checking. some commands like status or log don't even need root privileges.

BClark09 commented 6 years ago

Ah I see, that makes sense, having a look at the scripts that already exist using:

grep -rl '^#!/.*sh' /usr/bin

It looks like they do the same (e.g. raspi-config). Back we go!!!

BClark09 commented 6 years ago

Untested example of what I had planned:

https://gist.github.com/BClark09/4e98b9e2dc6a372f02ede1fae130df27

ThomDietrich commented 6 years ago

Looks good! Nice thing about it is, that you can recycle a lot from other scripts :D You are exporting HTTP_PORT without making sure it exists. Also I wonder about the log command. Might be interesting to extend the command in openHABian, see https://community.openhab.org/t/multitail-color-scheme-for-openhab-logs/31302?source_topic_id=13379

BClark09 commented 6 years ago

You are exporting HTTP_PORT without making sure it exists

Sorry, recycled too hard... It won't need HTTP_PORT as this would be checked elsewhere. Other paths may not used in the script and may not be needed either.

Indeed, the log command should be the only command that'll need some code snippet not already used elsewhere in linuxpkg. Will have a think about that when I have the time to test! Thanks!

Thinking about it a little more, should be fine to use multitail by default and revert to tail -f if not found? That way users will be able to see a colour scheme if you implement it on openHABian.

ThomDietrich commented 6 years ago

@BClark09 this might be far fetched but take a minute to think about it: The longer I think about the options of this script and the ways it could be extended over time, I wonder if we should discuss how the openhabian-config program could be re-purposed in that matter. It is already quite capable and offers many things every apt based installation can benefit from. Options as the above are easily added. RPM support can be added and the script would probably benefit from a broader developer base. I'm talking long run here, for now the PR is fine as it is and should be merged.

BClark09 commented 6 years ago

Sorry, I'm a little unsure what you mean, are you suggesting to include the features of openhabian-config into this script?

ThomDietrich commented 6 years ago

Hey @BClark09, I'm sorry I forgot to answer. I meant it the other way around. I wonder if instead of maintaining a new script/management tool, we could use openhabian-config for that task. The script is already capable to do a lot of things and could easily handle the few extra tasks your script provides. The script would definitely benefit from a broader user base and new developers.

Another question: This might come a bit late but may I ask if you thought about another name for the script? openhab as a command seems a bit mistakable. Typical alternatives are names like systemctl or gitlab-cli

BClark09 commented 6 years ago

I see, so you'd rather call openhab-cli backup etc from within openhabian-config? Makes sense, and this script can be extended to cover distribution specific tasks.

I can certainly change the name now, I haven't announced it yet and no one has downloaded the snapshot. openhab-cli makes sense to me, and I've seen many other programs do this.

ThomDietrich commented 6 years ago

I can certainly change the name now

Now is the last chance, I thought so too. Alternatives are openhab-cli, openhab-cmd, openhab-ctl However please do not feel urged to rename it, this is up to you.