All posts by megebaek

Setup Home Assistant with Letsencrypt on Synology

Setup Lets Encrypt on Synology

How to install Let’s Encrypt SSL Certificate on Synology NAS with DSM 6


Rember that it validate on port 80 so forward port 80 to your Synology (remember Firewall)

Find Certificate : find / -name
Normal : /usr/syno/etc/certificate/system/default
Set rights:

sudo chmod 755 /usr/syno/etc/certificate/system/default
sudo chmod 755 /usr/syno/etc/certificate/system/default/privkey.pem
sudo chmod 755 /usr/syno/etc/certificate/system/default/fullchain.pem

Manual renew certificate : /usr/syno/sbin/syno-letsencrypt renew-all

Setup HA:
Create folders:

mkdir -p /volume1/docker/HA

Install Docker

sudo docker run -d –restart=always –name=”home-assistant” -v /volume1/docker/HA:/config -v /usr/syno/etc/certificate/system/default:/ssl -e “TZ=Europe/Copenhagen” –net=host homeassistant/home-assistant

Configuration.yaml

#####################################
### HTTP
#####################################
http:
base_url: https://%homeassistantdnsname%:8123
ssl_certificate: /ssl/fullchain.pem
ssl_key: /ssl/privkey.pem

Sensor.yaml

#####################################
### Cert Check
#####################################
– platform: command_line
name: SSL cert expiry
unit_of_measurement: days
command: “/config/custom_components/check_cert.sh”

create: check_cert.sh
Set rights:

sudo chmod +s /volume1/docker/HA/custom_components/check_cert.sh

check_cert.sh:

# Website to check
website=”homeassistantdnsname”

# temporary file to store certificate
certificate_file=$(mktemp)

# delete temporary file on exit
trap “unlink $certificate_file” EXIT
echo -n | openssl s_client -servername “$website” -connect “$website”:8123 2>/dev/null | sed -ne ‘/-BEGIN CERTIFICATE-/,/-END CERTIFICATE-/p’ > $certificate_file
certificate_size=$(stat -c “%s” $certificate_file)
if [ “$certificate_size” -gt “1” ]; then
date=$(openssl x509 -in $certificate_file -enddate -noout | sed “s/.*=\(.*\)/\1/”)
date_s=$(date -d “${date}” +%s)
now_s=$(date -d now +%s)
date_diff=$(( (date_s – now_s) / 86400 ))
echo “$date_diff”
if [ “$date_s” -gt “$now_s” ]; then
exit 0 # ok
else
exit 1 # not ok
fi
else
exit 254
fi
else
exit 255

Setup TasmoAdmin on Synology DOCKER

create dirs for Docker Volumes(data)

mkdir -p /volume1/docker/Portainer/data
mkdir -p /volume1/docker/TasmoAdmin/data

install Portainer

sudo docker run -d -p 9000:9000 -v /var/run/docker.sock:/var/run/docker.sock -v /volume1/docker/Portainer/data:/data –name=Portainer –restart=always portainer/portainer


#install tasmoadmin

sudo docker run -d -p 5555:80 -v /volume1/docker/TasmoAdmin/data:/data –name=TasmoAdmin –restart=always raymondmm/tasmoadmin

#check if containers r running

sudo docker ps

Setup MQTT on Synology DOCKER

Create folders:

mkdir -p /volume1/docker/mqtt/log
mkdir -p /volume1/docker/mqtt/data
mkdir -p /volume1/docker/mqtt/config
chmod 0777 /volume1/docker/mqtt/log

Cerate conf file: (/volume1/docker/mqtt/config/mosquitto.conf)

pid_file /var/run/mosquitto.pid
persistence true
persistence_location /mqtt/data/
password_file /mqtt/config/passwd_file
allow_anonymous false
user mosquitto
# Port to use for the default listener.
port 1883
log_dest file /mqtt/log/mosquitto.log
log_dest stdout

Setup Passws_file:

cd /volume1/docker/mqtt/data
mosquitto_passwd -c passwd_file %username%
password: %password%

Start Docker

sudo docker run –name mqtt –restart=always –net=host -tid -v /volume1/docker/mqtt/config:/mqtt/config:ro -v /volume1/docker/mqtt/log:/mqtt/log -v /volume1/docker/mqtt/data/:/mqtt/data/ toke/mosquitto

Delete/Sendt items in Shared mailbox in Exchange 2013

If you have a shared mailbox and deletes or send a items it will go to your own mailbox

You have to use thise to fix it:

Office 2010
Windows Registry Editor Version 5.00
[HKEY_CURRENT_USERSoftwareMicrosoftOffice14.0OutlookPreferences]
“DelegateSentItemsStyle”=dword:00000001

[HKEY_CURRENT_USERSoftwareMicrosoftOffice14.0OutlookOptionsGeneral]
“DelegateWastebasketStyle”=dword:00000004

————————————————————————-

Office 2013
Windows Registry Editor Version 5.00
[HKEY_CURRENT_USERSoftwareMicrosoftOffice15.0OutlookPreferences]
“DelegateSentItemsStyle”=dword:00000001

[HKEY_CURRENT_USERSoftwareMicrosoftOffice15.0OutlookOptionsGeneral]
“DelegateWastebasketStyle”=dword:00000004

WSUS reset

How to Do a Reset:

Note: You may want to execute the procedure below during off hours as your WSUS server will be downloading quite a bit of data.

1) Correct any settings above or disapprove any unneeded updates.

2) Close any open WSUS consoles.

3) Go to Administrative Tools – Services and STOP the Update Services service.

4) In Windows Explorer browse to the WSUSContent folder (typically D:WSUSWSUSContent or C:WSUSWSUSContent)

5) Delete ALL the files and folders in the WSUSContent folder.

6) Go to Administrative Tools – Services and START the Update Services service.

7) Open a command prompt and navigate to the folder: C:Program FilesUpdate ServicesTools.

8) Run the command WSUSUtil.exe RESET

-This command tells WSUS to check each update in the database, and verify that the content is present in the WSUSContent folder. As it finds that the content is not present in the folder, it executes a BITS job to download the content from Microsoft. This process takes quite a bit of time and runs in the background.

How do you tell when the process is complete?

Other than noticing that the WSUSContent folder is no longer growing you can also check the SoftwareDistribution.log:

C:Program FilesUpdate ServicesLogFilesSoftwareDistribution.log

When you start the reset process, you should see a line towards the bottom of the log which looks like this:

WsusService.13  ExecutionContext.runTryCode     State Machine Reset Agent Starting

After waiting for some time, check the log again and search for the text “State Machine Reset Agent Finished”

WsusService.13  ExecutionContext.runTryCode     State Machine Reset Agent Finished

SQL database in suspect or emergency mode

If you have a database that is in suspect or emergency mode do this to get it online:

ALTER DATABASE XXX SET ONLINE

If this work is’s all fine, else you have to kill all active connections with this:

select
t1.session_id,
t1.start_time as request_start_time,
db_name(t1.database_id) as DatabaseName,
t1.reads,
t1.writes,
t1.logical_reads,
t1.logical_reads*8/1024/1024 as logical_reads_GB,
t1.cpu_time as cpu,
t1.total_elapsed_time,
t1.wait_time,
t1.wait_type,
t1.wait_resource,
t1.open_transaction_count,
t1.blocking_session_id,
SUBSTRING(text, (statement_start_offset/2)+1,
((CASE statement_end_offset
WHEN -1 THEN DATALENGTH(text)
ELSE statement_end_offset
END – statement_start_offset)/2) + 1) AS statement_text,
text as full_statement_text,
login_time,
program_name,
login_name,
client_net_address,
query_plan
from
sys.dm_exec_requests t1
outer apply sys.dm_exec_sql_text(sql_handle) t2
outer apply sys.dm_exec_query_plan(t1.plan_handle)
inner join sys.dm_exec_sessions t3 on t1.session_id = t3.session_id
inner join sys.dm_exec_connections t4 on t1.session_id = t4.session_id
where t1.session_id > 50 and t1.session_id <> @@spid

When all connections is terminatet do this:

ALTER DATABASE XXX SET EMERGENCY
ALTER DATABASE XXX SET SINGLE_USER WITH ROLLBACK IMMEDIATE
DBCC CHECKDB (XXX, REPAIR_ALLOW_DATA_LOSS)
ALTER DATABASE XXX SET ONLINE
ALTER DATABASE XXX SET MULTI_USER

To see the status on this you this command:

SELECT
session_id ,
request_id ,
percent_complete ,
estimated_completion_time ,
DATEADD(ms,estimated_completion_time,GETDATE()) AS EstimatedEndTime,
start_time ,
status ,
command
FROM sys.dm_exec_requests

 

Change SQL max memory

Log on the SQL Server and start a new Query

– Set the SQL Server in Operation Mode –

sp_configure 'show advanced options', 1;
GO
RECONFIGURE;
go

– View Settings that are running on the server –

EXEC sp_configure;

– Set Max Memory (MB) – (in this example the max is set to 6 GB)

EXEC  sp_configure'max server memory (MB)',6000;

Activate the Settings

RECONFIGURE;
GO