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

v5.0.1 install.sh does not work to upgrade sshnp/sshnpd #761

Closed
cconstab opened this issue Jan 29, 2024 · 12 comments · Fixed by #765
Closed

v5.0.1 install.sh does not work to upgrade sshnp/sshnpd #761

cconstab opened this issue Jan 29, 2024 · 12 comments · Fixed by #765
Assignees
Labels
bug Something isn't working

Comments

@cconstab
Copy link
Member

Describe the bug

various problems with upgrade process that need to be addressed

If sshnp/sshnpd are in use then they cannot be copied over (I have sucessfully dodged this by mv sshnpd sshnpd.old then using cp

The tmux install fails badly see bel;ow

Steps to reproduce

  1. First I install sshnp/sshnpd - TMUX / bin installs tested
  2. Then I try to install over them to upgrade
  3. Things fail on Mac/Linux

Expected behavior

just works/upgrades with single command idealy so you could use sshnp to upgrade in a single command to make things easier if you had 100 or 1000 machines!

Perhaps auto upgrade solution ?

Screenshots

constab@tarial sshnp % ./install.sh tmux sshnpd                                                                             
Installed sshnpd to /Users/cconstab/.local/bin
Installed srv to /Users/cconstab/.local/bin
cron job already installed, killing old tmux session
Unknown tmux service: kill-session
./install.sh [command]
Available commands:
at_activate     - install at_activate
sshnp           - install sshnp
sshnpd          - install sshnpd
srv           - install srv
srvd          - install srvd
binaries        - install all base binaries

debug_srvd    - install srvd with debugging enabled
debug           - install all debug binaries

all             - install all binaries (base and debug)

headless <job>  - install a headless cron job
                  available jobs: [sshnpd, srvd]

tmux <service>  - install a service in a tmux session
                  available services: [sshnpd, srvd]
cconstab@tarial

Smartphones

  • sshnp v5.0.1

Were you using an atApplication when the bug was found?

No response

Additional context

No response

@cconstab cconstab added the bug Something isn't working label Jan 29, 2024
@cconstab cconstab changed the title v5.0.1 instal.sh does not work to upgrade sshnp/sshnpd v5.0.1 install.sh does not work to upgrade sshnp/sshnpd Jan 29, 2024
@gkc
Copy link
Contributor

gkc commented Jan 29, 2024

Fixed. Took me a while but I eventually realized that the tmux function in the script was masking the tmux command itself

Here are the relevant output portions from my fixed branch for an install, re-install, re-install with sshnpd service running

gary@gkc2019-2 sshnp % install.sh tmux sshnpd     
=> Installed sshnpd to /Users/gary/.local/bin
=> Installed srv to /Users/gary/.local/bin
=> Installing cron job: @reboot tmux new-session -d -s sshnpd && tmux send-keys -t sshnpd /Users/gary/.local/bin/sshnpd.sh C-m


gary@gkc2019-2 sshnp % install.sh tmux sshnpd
=> Installed sshnpd to /Users/gary/.local/bin
=> Installed srv to /Users/gary/.local/bin
=> Cron job already installed, will not re-install


gary@gkc2019-2 sshnp % tmux new-session -d -s sshnpd && tmux send-keys -t sshnpd /Users/gary/.local/bin/sshnpd.sh C-m


gary@gkc2019-2 sshnp % install.sh tmux sshnpd
=> Installed sshnpd to /Users/gary/.local/bin
=> Installed srv to /Users/gary/.local/bin
=> Cron job already installed, will not re-install
=> Found existing tmux session for sshnpd - will kill and restart it


gary@gkc2019-2 sshnp % tmux ls
sshnpd: 1 windows (created Mon Jan 29 12:15:31 2024)


gary@gkc2019-2 sshnp % install.sh tmux sshnpd
=> Installed sshnpd to /Users/gary/.local/bin
=> Installed srv to /Users/gary/.local/bin
=> Cron job already installed, will not re-install
=> Found existing tmux session for sshnpd - will kill and restart it


gary@gkc2019-2 sshnp % tmux ls
sshnpd: 1 windows (created Mon Jan 29 12:15:40 2024)

@cconstab
Copy link
Member Author

So I tried the new install.sh and it worked but only on the second time.. See log below..

cconstab@orac:~/sshnp$ vi install.sh
cconstab@orac:~/sshnp$ ./install.sh tmux sshnpd
cconstab@orac:~/sshnp$
cconstab@orac:~/sshnp$
cconstab@orac:~/sshnp$
cconstab@orac:~/sshnp$ ~/.local/bin/sshnpd
-bash: /home/cconstab/.local/bin/sshnpd: No such file or directory
cconstab@orac:~/sshnp$ ./install.sh tmux sshnpd
=> Installed sshnpd to /home/cconstab/.local/bin
cconstab@orac:~/sshnp$ ~/.local/bin/sshnpd
Version : 5.0.1 (core: 6.0.1)
-k, --key-file,--keyFile              Sending atSign's keyFile if not in ~/.atsign/keys/
-a, --atsign (mandatory)              atSign of this device
-m, --manager (mandatory)             Managers atSign, that this device will accept triggers from
-d, --device                          Send a trigger to this device, allows multiple devices share an atSign
                                      (defaults to "default")
-s, --[no-]sshpublickey               When set, will update authorized_keys to include public key sent by manager
-u, --[no-]un-hide,--[no-]username    When set, makes various information visible to the manager atSign - e.g. username, version, etc
-v, --[no-]verbose                    More logging
    --ssh-client                      What to use for outbound ssh connections.
                                      [openssh (default), dart]
    --root-domain                     atDirectory domain
                                      (defaults to "root.atsign.org")
    --local-sshd-port                 port on which sshd is listening locally on localhost
                                      (defaults to "22")
    --ephemeral-permissions           The permissions which will be added to the authorized_keys file for the ephemeral public keys which are generated when a client is
                                      connecting via forward ssh e.g. PermitOpen="host-1:3389",PermitOpen="localhost:80"
                                      (defaults to "")
    --ssh-algorithm                   Use RSA 4096 keys rather than the default ED25519 keys
                                      [ssh-ed25519 (default), ssh-rsa]
    --storage-path                    Directory for local storage. Defaults to $HOME/.sshnp/${atSign}/storage

Invalid argument(s): Option atsign is mandatory.
cconstab@orac:~/sshnp$

@cconstab cconstab reopened this Jan 29, 2024
@cconstab
Copy link
Member Author

Plus the tmux restart of the job assumes that it is running a bash shell I think which it may not be. On Ubuntu I notice that often/sometimes the tmux session uses /bin/sh.. Perhaps as we start the tmux we force a bash shell ?

again see below from the tmux console


INFO|2024-01-29 11:02:02.739828|AtLookup|Creating new connection
INFO|2024-01-29 11:02:03.626715|AtLookup|New connection created OK
INFO|2024-01-29 11:02:03.876366|AtLookup|auth success
INFO|2024-01-29 11:02:03.876444|AtClientManager|setCurrentAtSign called with atSign @ssh_1
INFO|2024-01-29 11:02:03.876483|AtClientManager|Switching atSigns from null to @ssh_1
INFO|2024-01-29 11:02:03.878640|HiveBase|commit_log_6277982265d52db809e3ec7210a0ad87294fc9e6b857b6fe0a7f2e6b3f82ff36 initialized successfully
INFO|2024-01-29 11:02:03.880634|HiveBase|6277982265d52db809e3ec7210a0ad87294fc9e6b857b6fe0a7f2e6b3f82ff36 initialized successfully
INFO|2024-01-29 11:02:03.889436|AtClientCommitLogCompaction (@ssh_1)|Starting commit log compaction job running for every 11 minute(s)
INFO|2024-01-29 11:02:03.890414|AtClientManager|setCurrentAtSign complete
INFO|2024-01-29 11:02:03.894141| sshnpd |Starting heartbeat
INFO|2024-01-29 11:02:03.894169| sshnpd |Subscribing to orac\.sshnp@
INFO|2024-01-29 11:02:03.894201| sshnpd |Deleting old device info for orac (if it exists)
INFO|2024-01-29 11:02:03.894261|AtLookup|Creating new connection
INFO|2024-01-29 11:02:04.790533|AtLookup|New connection created OK
INFO|2024-01-29 11:02:05.033394|Monitor (@ssh_1)|monitor started for @ssh_1 with last notification time: null
INFO|2024-01-29 11:02:05.063375|AtLookup|auth success
INFO|2024-01-29 11:02:05.195390| sshnpd |Done
^C^P

$ -sh: 2: : not found
$

@gkc
Copy link
Contributor

gkc commented Jan 29, 2024

So I tried the new install.sh and it worked but only on the second time.. See log below..

Platform? I tested this repeatedly this morning and it worked 🤔

@XavierChanth
Copy link
Member

uname -a?

@gkc
Copy link
Contributor

gkc commented Jan 29, 2024

Re: tmux restart : perhaps we should remove the kill and restart and instead just prompt the user that they need to do so. Previous behavior was just a tmux kill-session which seemed wrong

@gkc
Copy link
Contributor

gkc commented Jan 29, 2024

So I tried the new install.sh and it worked but only on the second time.. See log below..

Platform? I tested this repeatedly this morning and it worked 🤔

@cconstab I see no output at all from your first "install tmux sshnpd" - can you "set -x" before running it, so we can see what it is doing, exactly?

On second run again I would have expected to see more output (re crontab etc) so that's even weirder

Are you running the install.sh which is currently in trunk?

@cconstab
Copy link
Member Author

I cut and paste the install.sh in trunk yup..

Will rerun tomorrow.. thought it odd so reopened for more testing.

@gkc
Copy link
Contributor

gkc commented Jan 30, 2024

I've found the main problem you've encountered, it seems to be a combination of two things (1) a bug in setting user_home IF you have su'd to the current user (2) a bug in my renaming of binaries to .old / removing of old .old binaries. PR will follow shortly

@gkc
Copy link
Contributor

gkc commented Jan 30, 2024

Plus the tmux restart of the job assumes that it is running a bash shell I think which it may not be. On Ubuntu I notice that often/sometimes the tmux session uses /bin/sh.. Perhaps as we start the tmux we force a bash shell ?

Not sure I understand this ... how does the restart assume that it is running a bash shell? This is what install.sh does to kill and restart the session if there is one running; I don't see anything bash-specific in these commands ... what am I missing?

  if (command tmux has-session -t "$service_name" 2> /dev/null); then
    echo "=> Found existing tmux session for $service_name - will kill and restart it"
    command tmux kill-session -t "$service_name"
    command tmux new-session -d -s "$service_name" && command tmux send-keys -t "$service_name" "$dest" C-m
  fi

FYI The template sshnpd.sh uses #!/bin/sh - should we change that?

@XavierChanth
Copy link
Member

Not sure I understand this ... how does the restart assume that it is running a bash shell? This is what install.sh does to kill and restart the session if there is one running; I don't see anything bash-specific in these commands ... what am I missing?

Nothing assumes a bash shell here

FYI The template sshnpd.sh uses #!/bin/sh - should we change that?

No, we are using POSIX shell for better compatibility.

@XavierChanth
Copy link
Member

FYI shellcheck is a big help in ensuring POSIX shell compliance:

Vscode extension:

Name: ShellCheck
Id: timonwong.shellcheck
Description: Integrates ShellCheck into VS Code, a linter for Shell scripts.
Version: 0.35.0
Publisher: Timon Wong
VS Marketplace Link: https://marketplace.visualstudio.com/items?itemName=timonwong.shellcheck

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
3 participants