✦Template Printable Ideas Insights

How to Create a Scheduled Task to Restart a Service

By

Creating a scheduled task to restart a service is a common requirement in system administration to ensure optimum performance and prevent downtime. It's a straightforward process that helps automate routine tasks and save time in the long run. This guide will walk you through the process on both Windows and Unix-based systems, usingTask Scheduler for Windows and cron for Unix-like systems.

Before diving into the process, ensure you have the necessary permissions to create and manage scheduled tasks. For Windows, you'll need to have administrator privileges, and for Unix-based systems, you'll need to be the superuser or have sufficient permissions.

Scheduling a Service Restart on Windows

Windows uses the Task Scheduler to automate tasks. Here's how you can create a scheduled task to restart a service:

How to make a Windows Service restart automatically using Task Scheduler
How to make a Windows Service restart automatically using Task Scheduler
How to create scheduled tasks on Windows 10
How to create scheduled tasks on Windows 10
the 3 task rule ! . productivity system, daily planning, focus method, time management, routine
the 3 task rule ! . productivity system, daily planning, focus method, time management, routine

The following steps assume you're using the built-in Windows Task Scheduler. If you're using a third-party tool like Task Scheduler Pro or Advanced Task Killer, the process might vary slightly.

Method 1: Using Command Prompt

1. Open the Command Prompt as an administrator. You can do this by right-clicking the Start button and selecting "Command Prompt (Admin)".

Simple Systems For Managing Recurring Tasks Without Constant Context Switching
Simple Systems For Managing Recurring Tasks Without Constant Context Switching
a white board with instructions on how to complete backlogs fast and tips that actually work
a white board with instructions on how to complete backlogs fast and tips that actually work
How to Create a Remote Work Schedule that Protects Your Personal Time
How to Create a Remote Work Schedule that Protects Your Personal Time

2. To list all available services, type the following command and press Enter:

sc query

Replace "service_name" with the name of the service you want to restart. For instance, if you want to restart the "Windows Update" service, the command would be:

Step by Step Guide to Creating a Remote Work Schedule That Protects Your Personal Time
Step by Step Guide to Creating a Remote Work Schedule That Protects Your Personal Time
Simple productivity habits, mindset reset and daily routines to start 2026 focused, disciplined and intentional. 2026 Productivity, 2026 Self Improvement, New Year Resolution Text About Productivity, 2024 Priorities, 2025 Self Improvement, Self-improvement Plan 2022, Self Improvement 2025, Self Improvement Tips 2025, List Of Priorities In 2023 Me
Simple productivity habits, mindset reset and daily routines to start 2026 focused, disciplined and intentional. 2026 Productivity, 2026 Self Improvement, New Year Resolution Text About Productivity, 2024 Priorities, 2025 Self Improvement, Self-improvement Plan 2022, Self Improvement 2025, Self Improvement Tips 2025, List Of Priorities In 2023 Me
a poster with instructions on how to master daily production
a poster with instructions on how to master daily production
Step‑By‑Step Process to Create an Effective Remote Work Schedule
Step‑By‑Step Process to Create an Effective Remote Work Schedule
𝐐𝐮𝐢𝐜𝐤 𝐓𝐢𝐩: Feeling overwhelmed with your to-do list? Try the ‘one-task-at-a-time’ approach! Start with the most important task, give it your full focus, and check it off before moving on. It’s amazing how much a focused 20 minutes can accomplish! Task Prioritization, Two Tasks, Prioritize Important Tasks Tip, Task Done, Task Oriented People, Efficient Task Prioritization, Tips For Effective Task Prioritization, Rra Task Prioritization, Task Priority Board
𝐐𝐮𝐢𝐜𝐤 𝐓𝐢𝐩: Feeling overwhelmed with your to-do list? Try the ‘one-task-at-a-time’ approach! Start with the most important task, give it your full focus, and check it off before moving on. It’s amazing how much a focused 20 minutes can accomplish! Task Prioritization, Two Tasks, Prioritize Important Tasks Tip, Task Done, Task Oriented People, Efficient Task Prioritization, Tips For Effective Task Prioritization, Rra Task Prioritization, Task Priority Board
5 Tips For Successful Service Recovery
5 Tips For Successful Service Recovery

sc stop "Windows Update"

3. Once the service is stopped, you can start it again using the following command:

sc start "service_name"

Task Planner & To-Do List | Stay Organized and Boost Productivity
Task Planner & To-Do List | Stay Organized and Boost Productivity
Why You Never Stick to Your Plan (And How to Fix It)
Why You Never Stick to Your Plan (And How to Fix It)
Free Time Management Templates | Smartsheet
Free Time Management Templates | Smartsheet

4. To create a scheduled task, type the following command and press Enter:

schtasks /create /tn "TaskName" /tr "C:\Windows\System32\cmd.exe /c sc stop "service_name"" /sc weekly /d SUN /st 12:00

Replace "TaskName" with the name you want to give to your task, and adjust the schedule as needed. In this example, the task will run every Sunday at 12:00 PM.

Method 2: Using Task Scheduler GUI

1. Open the Task Scheduler by pressing the Windows key + R, typing taskschd.msc, and pressing Enter.

2. In the right-hand panel, click "Create Task".

3. On the General tab, give your task a name and check the box for "Run whether user is logged on or not". You can also choose to start the task at log on if you wish.

4. Go to the Triggers tab and click "New". Set up your trigger as desired (weekly, daily, etc.).

5. Move to the Actions tab and click "New". Select "Start a program" as the action, and in the "Program/script" field, enter the following:

"C:\Windows\System32\cmd.exe /c sc stop "service_name"

6. Click "OK" to save your task.

Scheduling a Service Restart on Unix-based Systems

Unix-based systems use the cron daemon to schedule tasks. Here's how you can create a cron job to restart a service:

The following steps assume you're using a Unix-based system with a typical cron setup. If you're using a system that uses a different cron implementation, the process might vary slightly.

Method 1: Using Shell Script

1. Create a shell script with the service restart command. For instance, to restart the "sshd" service on a Debian-based system, you would create a file with the following content:

#!/bin/bash service ssh restart

Save this file as a .sh file, for example, "sshd_restart.sh", and make it executable with the following command:

chmod +x sshd_restart.sh

2. Open the crontab file by typing the following command in the terminal:

crontab -e

3. Add a new line to schedule the task. For instance, to run the script every Sunday at 12:00 PM, you would add the following line:

0 12 * * 0 /path/to/sshd_restart.sh

The first five fields represent the minute, hour, day of the month, month, and day of the week, respectively. The last field is the command to run.

Method 2: Using System Kairos

Some Unix-based systems use systemd and its timedated daemon for scheduling tasks. Here's how you can create a systemd timer to restart a service:

1. Create a new unit file in the following location:

/etc/systemd/system/restart_sshd.service

With the following content:

2. Create a new timer file at the following location:

/etc/systemd/system/restart_sshd.timer

With the following content:

3. Reload the systemd daemon to apply the changes:

systemctl daemon-reload

4. Enable and start the new timer:

systemctl enable restart_sshd.timer systemctl start restart_sshd.timer

Congratulations! You've successfully created a scheduled task to restart a service on both Windows and Unix-based systems. This automation will help ensure your services remain healthy and performing optimally.

As a final note, remember to regularly monitor your scheduled tasks and services to ensure they're working as expected. Happy automating!