HomeSoftwareScriptsNotesToolboxGallery
Computing
Thoughts on Coding Styleddrescue Recovery NotesDomain 301 Perma RedirectWin/Linux PuTTY File TransferOpenVPN Site-to-Site SetupParity Data CheckingRclone Quick ReferenceSnapRAID NotesSSH TunnelingTransfer E-Mails with IMAPUDK Third Person CameraVPN Protocol Ports

GNU/Linux
Apache Process Mem UsageApache and CA OpenSSLApache2 htpasswd NotesCentOS 7 GlusterFS NotesCracking WEP and WPADebian 7 on Hyper-VDebian 7 to 8 UpgradeDebian 8 to 9 UpgradeDebian 9 DRBD SetupDebian and VirtualboxDebian and LSBInitScriptsDebian and systemdDebian Apache LetsEncryptDebian Apt AutoremoveDebian Cron & AnacronDebian KVM HypervisorLinux Bash ColorsLinux Cron BackupLinux Dnsmasq Setup NotesIptables Chain ExampleIptables Firewall and GatewayLinux MD RAID BasicsLinux iproute2 RoutingLinux SFTP Network ShareAvoid Linux Shell LoggingChecking Storage UsageLinux I/O Disk PerformanceLinux ZFS NotesVi/Vim Basic Reference

Microsoft
Bypass Windows PasswordDaz and ToolkitMRTG Network Traffic ViewMS Outlook NotesDOS File Content SearchDOS Merging VCF filesROBOCOPY Batch ScriptingPowerShell Reference NotesThe runas CommandTeamViewer on HeadlessUpdateOrchestrator ModWorkgroup Failover ClusterDisable OneDrive in W10Windows 10 ServerWindows WiFi and netshWindows Boot Custom UIHyper-V NetworkingHyper-V ReplicationIIS10 and PHP7 SetupLet's Encrypt and IISPlex Media Server MigrationRebuilding Boot PartitionSecuring RDP ConnectionsServer 2012 R2 SetupWindows Shortcut CommandsWBAdmin Bare-Metal Backup

BSD/Unix
FreeBSD 10.0 Setup (NOR)

C#/.NET
C# Associative ArraysC# Asynchronized WebcallC# Base64 GZipped JSONC# Broadcast Registry ChangesChanging a project nameC# Code Execution TimerCode Signing With SigntoolC# Creating a WebserverC# Dealing with WhitespacesC# djDBI for SQL CEC# Form ReferencingC# Get Folder SizeC# Handling DisconnectsC# HTTP POST and GETC# Importing DLL FunctionsC# Installing ServicesC# Kill and Start ProcessesC# Lambda ExpressionsC# Local AppData HandlingC# Memory StreamReadingC# Minimize to System TrayC# PDFsharp and MigraDocC# Public Fields vs PropsC# Registry HandlingC# Regular ExpressionsC# Require AdministratorC# RichTextBox File StreamC# Application SettingsC# SqlCeConnection CodeC# Start with hidden formC# String EncryptionC# Cross Thread HandlingC# Updating A RuntimeC# Gmail as SMTPVSI Dependency ErrorC# Handle XML

C/C++
AOB Scan/InjectC Autodelete Old FilesC/C++ Multiline StringsC Socket ListeningC StringsGDI Double BufferWin32 Button ControlWin32 Edit ControlWin32 GetLastError()Win32 KeyloggingWin32 KeypostingWin32 Simple WindowWin32 Socket ProgrammingWin32 VERSIONINFO

PHP
Bitwise IP HandlingPHP ClassesContent Length HandlingDetecting Mobile BrowsersGoogle Captcha IntegrationHidden DownloadsHostname and Port RegexJSON Output HeadersMS Access Conn with COMProportional Image SizingRandom StringsRecursive FunctionsSending MailPHP SessionsSimple HTML-2-PDFPHP SimpleXMLTernary Operator and If/Else

SQL
MS Access Connection StringsMSSQL Case SensitivityMySQL Root Password ResetMySQL Check Slow QueriesColumn CountingQuick Note on CROSS JOINQuick Note on INNER JOINRandom Rows

HTML
HTML Raw Skeleton

JavaScript
AJAX Basicsevent.keyCode ReferenceIE7 Onclick EventsIE GIF Animation Problem

Java
Java Notater (NOR)

CSS
Border StylesFlyout MenusFont-Family Reference

Electrical
Betegnelser og SpenningsfallLovdata Elektrisk ArbeidResistors Series and ParallelSilicone and Circuit Boards

Debian and systemd


Debian 8 is here and systemd is here to stay. I'll be using this article to make some notes and references to get started.

Checking if you have systemd:
dpkg -l | grep systemd


The systemd system and service manager:
# systemctl start [name.service]
# systemctl stop [name.service]
# systemctl restart [name.service]
# systemctl reload [name.service]
$ systemctl status [name.service]
# systemctl is-active [name.service]
$ systemctl list-units --type service --all
$ systemctl list-unit-files (show all service files which are installed)
# systemctl enable [name.service] (make service launch on boot)
# systemctl disable [name.service] (make service not launch on boot)

General first time service procedure:
- Copy unit/service file into /etc/systemd/system/
- Run systemctl enable [name.service] to create the target symlinks (e.g. make it start at boot).
- Run systemctl start [name.service] to start it manually after enabling the first time.


Checking boot times for services:
 $ systemd-analyze blame
8.366s mysql.service
7.975s winbind.service
7.937s nmbd.service
7.731s samba-ad-dc.service
5.262s apache2.service
2.940s ModemManager.service
1.880s DJFirewall.service


Query the systemd journal (use with pipe for specific service):
# view logs (each line is short)
journalctl

# view logs with normal line lengths (lines are not contracted), get used to always running -a (For all), a for "showing All of the line".
journalctl -a

# show the 100 latest lines of logs
journalctl -an100

# following the log (synonymous with "tail -f /var/log/syslog"), f for "Following"
journalctl -fa


Creating the simplest possible systemd service (/etc/systemd/system/myservice):
[Unit]
Description=My Simple Service

[Service]
ExecStart=/usr/bin/myservice

[Install]
WantedBy=multi-user.target


Make it a real daemon / fork it:
[Unit]
Description=My Simple Service

[Service]
Type=forking
# The PID file is optional, but recommended in the manpage
# "so that systemd can identify the main process of the daemon"
PIDFile=/var/run/myservice.pid
ExecStart=/usr/bin/myservice --daemon --pidfile /var/run/myservice.pid

[Install]
WantedBy=multi-user.target
^ The difference is in the way the dependencies are handled. If some other services depend on myservice.service, then, in the first example, systemd will be able to run them as soon as it starts myservice. In the second example, systemd will wait until myservice forks. The difference matters, because myservice creates its control socket after starting, but before forking. So, in the first example, there is some chance that systemd will start something that tries to connect to the socket before myservice creates it.


Automatic restart on failure:
[Unit]
Description=My Simple Service
After=syslog.target

[Service]
Type=forking
PIDFile=/var/run/myservice.pid
# Note the -f: don't fail if there is no PID file
ExecStartPre=/bin/rm -f /var/run/myservice.pid
ExecStart=/usr/bin/myservice \
 --daemon --pidfile /var/run/myservice.pid
Restart=on-failure

[Install]
WantedBy=multi-user.target


Using EnvironmentFile for parameters:
[Unit]
Description=My Simple Service
After=syslog.target

[Service]
Type=forking
EnvironmentFile=/etc/myservice/myservice
PIDFile=/var/run/myservice.pid
# Note the -f: don't fail if there is no PID file
ExecStartPre=/bin/rm -f /var/run/myservice.pid
ExecStart=/usr/bin/myservice \
 --daemon --pidfile /var/run/myservice.pid \
 $MYSERVICE_OPTS
Restart=on-failure

[Install]
WantedBy=multi-user.target

/etc/myservice/myservice:
# Options to pass to My Simple Service.
MYSERVICE_OPTS="--arg1 --arg2"


Interesting reading:
The Biggest Myths by Lennart Poettering.
sect.systemd in the Debian Handbook.