2018-11-07 17:37:16 +01:00
#!/bin/bash
2019-05-21 09:21:22 -07:00
set -eu -o pipefail
2018-11-14 10:20:16 -08:00
# This script collects diagnostic information to help debug server related issues
# It also enables SSH access for the cloudron support team
2018-11-07 17:37:16 +01:00
PASTEBIN = "https://paste.cloudron.io"
OUT = "/tmp/cloudron-support.log"
LINE = "\n========================================================\n"
2022-04-29 12:39:42 -07:00
CLOUDRON_SUPPORT_PUBLIC_KEY = "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIGWS+930b8QdzbchGljt3KSljH9wRhYvht8srrtQHdzg support@cloudron.io"
2018-11-26 15:28:11 +01:00
HELP_MESSAGE = "
2021-11-15 09:58:25 -08:00
This script collects diagnostic information to help debug server related issues.
2018-11-26 15:28:11 +01:00
Options:
2021-11-15 09:58:25 -08:00
--owner-login Login as owner
--enable-ssh Enable SSH access for the Cloudron support team
--reset-appstore-account Reset associated cloudron.io account
--help Show this message
2018-11-26 15:28:11 +01:00
"
2018-11-07 17:37:16 +01:00
# We require root
if [ [ ${ EUID } -ne 0 ] ] ; then
2019-05-21 09:44:58 -07:00
echo "This script should be run as root. Run with sudo"
2018-11-07 17:37:16 +01:00
exit 1
fi
2018-11-26 15:28:11 +01:00
enableSSH = "false"
2021-11-15 09:58:25 -08:00
args = $( getopt -o "" -l "help,enable-ssh,admin-login,owner-login,reset-appstore-account" -n " $0 " -- " $@ " )
2018-11-26 15:28:11 +01:00
eval set -- " ${ args } "
while true; do
case " $1 " in
--help) echo -e " ${ HELP_MESSAGE } " ; exit 0; ;
--enable-ssh) enableSSH = "true" ; shift; ;
2019-07-02 16:37:46 -07:00
--admin-login)
2020-03-27 18:42:06 -07:00
# fall through
; &
--owner-login)
2021-06-25 12:51:42 -07:00
admin_username = $( mysql -NB -uroot -ppassword -e "SELECT username FROM box.users WHERE role='owner' AND username IS NOT NULL ORDER BY creationTime LIMIT 1" 2>/dev/null)
2019-07-02 16:37:46 -07:00
admin_password = $( pwgen -1s 12)
2021-09-20 13:16:26 +02:00
dashboard_domain = $( mysql -NB -uroot -ppassword -e "SELECT value FROM box.settings WHERE name='admin_fqdn'" 2>/dev/null)
mysql -NB -uroot -ppassword -e " INSERT INTO box.settings (name, value) VALUES ('ghosts_config', '{\" ${ admin_username } \":\" ${ admin_password } \"}') ON DUPLICATE KEY UPDATE name='ghosts_config', value='{\" ${ admin_username } \":\" ${ admin_password } \"}' " 2>/dev/null
echo " Login at https:// ${ dashboard_domain } as ${ admin_username } / ${ admin_password } . This password may only be used once. "
2019-07-02 16:37:46 -07:00
exit 0
; ;
2021-11-15 09:58:25 -08:00
--reset-appstore-account)
echo -e "This will reset the Cloudron.io account associated with this Cloudron. Once reset, you can re-login with a different account in the Cloudron Dashboard. See https://docs.cloudron.io/appstore/#change-account for more information.\n"
read -e -p "Reset the Cloudron.io account? [y/N] " choice
[ [ " $choice " != [ Yy] * ] ] && exit 1
mysql -uroot -ppassword -e "DELETE FROM box.settings WHERE name='cloudron_token';" 2>/dev/null
dashboard_domain = $( mysql -NB -uroot -ppassword -e "SELECT value FROM box.settings WHERE name='admin_fqdn'" 2>/dev/null)
echo " Account reset. Please re-login at https:// ${ dashboard_domain } /#/appstore "
exit 0
; ;
2018-11-26 15:28:11 +01:00
--) break; ;
*) echo " Unknown option $1 " ; exit 1; ;
esac
done
2018-11-13 13:31:49 +01:00
# check if at least 10mb root partition space is available
if [ [ "`df --output=" avail" / | sed -n 2p`" -lt "10240" ] ] ; then
echo "No more space left on /"
echo "This is likely the root case of the issue. Free up some space and also check other partitions below:"
echo ""
df -h
echo ""
2020-09-15 14:46:22 -07:00
echo "To recover from a full disk, follow the guide at https://docs.cloudron.io/troubleshooting/#recovery-after-disk-full"
2018-11-13 13:31:49 +01:00
exit 1
fi
# check for at least 5mb free /tmp space for the log file
if [ [ "`df --output=" avail" /tmp | sed -n 2p`" -lt "5120" ] ] ; then
echo "Not enough space left on /tmp"
echo "Free up some space first by deleting files from /tmp"
exit 1
fi
2022-04-28 11:31:18 +02:00
if [ [ " ${ enableSSH } " = = "true" ] ] ; then
ssh_port = $( cat /etc/ssh/sshd_config | grep "Port " | sed -e "s/.*Port //" )
ssh_user = "cloudron-support"
keys_file = "/home/cloudron-support/.ssh/authorized_keys"
echo -e $LINE "SSH" $LINE >> $OUT
echo " Username: ${ ssh_user } " >> $OUT
echo " Port: ${ ssh_port } " >> $OUT
echo " Key file: ${ keys_file } " >> $OUT
echo -n "Enabling ssh access for the Cloudron support team..."
mkdir -p $( dirname " ${ keys_file } " ) # .ssh does not exist sometimes
touch " ${ keys_file } " # required for concat to work
if ! grep -q " ${ CLOUDRON_SUPPORT_PUBLIC_KEY } " " ${ keys_file } " ; then
echo -e " \n ${ CLOUDRON_SUPPORT_PUBLIC_KEY } " >> " ${ keys_file } "
chmod 600 " ${ keys_file } "
chown " ${ ssh_user } " " ${ keys_file } "
fi
echo "Done"
exit 0
fi
2018-11-07 17:37:16 +01:00
echo -n "Generating Cloudron Support stats..."
# clear file
rm -rf $OUT
2021-02-17 20:27:46 -08:00
echo -e $LINE "DASHBOARD DOMAIN" $LINE >> $OUT
mysql -NB -uroot -ppassword -e "SELECT value FROM box.settings WHERE name='admin_fqdn'" & >> $OUT 2>/dev/null || true
2019-07-26 10:49:29 -07:00
echo -e $LINE "PROVIDER" $LINE >> $OUT
cat /etc/cloudron/PROVIDER & >> $OUT || true
2018-11-07 17:37:16 +01:00
echo -e $LINE "Docker container" $LINE >> $OUT
2018-11-14 10:20:16 -08:00
if ! timeout --kill-after 10s 15s docker ps -a & >> $OUT 2>& 1; then
echo -e "Docker is not responding" >> $OUT
fi
2018-11-07 17:37:16 +01:00
echo -e $LINE "Filesystem stats" $LINE >> $OUT
df -h & >> $OUT
2019-04-23 10:07:57 -07:00
echo -e $LINE "Appsdata stats" $LINE >> $OUT
2020-02-24 14:12:25 -08:00
du -hcsL /home/yellowtent/appsdata/* & >> $OUT || true
2019-04-23 10:07:57 -07:00
echo -e $LINE "Boxdata stats" $LINE >> $OUT
du -hcsL /home/yellowtent/boxdata/* & >> $OUT
echo -e $LINE "Backup stats (possibly misleading)" $LINE >> $OUT
2020-02-24 14:12:25 -08:00
du -hcsL /var/backups/* & >> $OUT || true
2018-11-07 17:37:16 +01:00
echo -e $LINE "System daemon status" $LINE >> $OUT
2020-08-01 20:00:20 -07:00
systemctl status --lines= 100 box mysql unbound cloudron-syslog nginx collectd docker & >> $OUT
2018-11-07 17:37:16 +01:00
2018-11-19 19:47:19 +01:00
echo -e $LINE "Box logs" $LINE >> $OUT
tail -n 100 /home/yellowtent/platformdata/logs/box.log & >> $OUT
2021-02-17 20:04:43 -08:00
echo -e $LINE "Interface Info" $LINE >> $OUT
2019-06-10 09:31:34 -07:00
ip addr & >> $OUT
2018-11-07 17:37:16 +01:00
echo -e $LINE "Firewall chains" $LINE >> $OUT
iptables -L & >> $OUT
2023-03-23 07:22:40 +01:00
has_ipv6 = $( cat /proc/net/if_inet6 >/dev/null 2>& 1 && echo "yes" || echo "no" )
echo -e " IPv6: ${ has_ipv6 } " >> $OUT
[ [ " ${ has_ipv6 } " = = "yes" ] ] && ip6tables -L & >> $OUT
2018-11-07 17:37:16 +01:00
echo "Done"
2019-05-21 09:44:58 -07:00
echo -n "Uploading information..."
2021-11-09 16:05:34 +01:00
paste_key = $( curl -X POST ${ PASTEBIN } /documents --silent --data-binary " @ $OUT " | python3 -c "import sys, json; print(json.load(sys.stdin)['key'])" )
2019-05-21 09:44:58 -07:00
echo "Done"
2018-11-07 17:37:16 +01:00
echo ""
2023-03-23 07:22:40 +01:00
echo "Please email the following link to support@cloudron.io :"
2018-11-07 17:37:16 +01:00
echo ""
echo " ${ PASTEBIN } / ${ paste_key } "